网络模式配置代码增加dbus判空

This commit is contained in:
zhangyuanyuan1 2023-01-31 16:33:33 +08:00
parent 53bb8d6ba4
commit 0b4d460914
1 changed files with 12 additions and 6 deletions

View File

@ -37,6 +37,9 @@ NetworkModeConfig::NetworkModeConfig(QObject *parent) : QObject(parent)
"/firewall", "/firewall",
"com.ksc.defender.firewall", "com.ksc.defender.firewall",
QDBusConnection::systemBus()); QDBusConnection::systemBus());
if(!m_dbusInterface->isValid()) {
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
}
} }
int NetworkModeConfig::getNetworkModeConfig(QString uuid) int NetworkModeConfig::getNetworkModeConfig(QString uuid)
@ -46,8 +49,9 @@ int NetworkModeConfig::getNetworkModeConfig(QString uuid)
return -1; return -1;
} }
if(!m_dbusInterface->isValid()) { if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init com.ksc.defender dbus error"; qWarning () << "com.ksc.defender dbus is invalid";
return -1;
} }
QDBusReply<int> reply = m_dbusInterface->call("get_networkModeConfig", uuid); QDBusReply<int> reply = m_dbusInterface->call("get_networkModeConfig", uuid);
@ -61,8 +65,9 @@ int NetworkModeConfig::getNetworkModeConfig(QString uuid)
void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode) void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QString ssid, int mode)
{ {
if(!m_dbusInterface->isValid()) { if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init com.ksc.defender dbus error"; qWarning () << "com.ksc.defender dbus is invalid";
return;
} }
QDBusReply<int> reply = m_dbusInterface->call("set_networkModeConfig", uuid, cardName, ssid, mode); QDBusReply<int> reply = m_dbusInterface->call("set_networkModeConfig", uuid, cardName, ssid, mode);
@ -75,8 +80,9 @@ void NetworkModeConfig::setNetworkModeConfig(QString uuid, QString cardName, QSt
int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QString ssid) int NetworkModeConfig::breakNetworkConnect(QString uuid, QString cardName, QString ssid)
{ {
if(!m_dbusInterface->isValid()) { if(m_dbusInterface == nullptr || !m_dbusInterface->isValid()) {
qWarning ()<< "init com.ksc.defender dbus error"; qWarning () << "com.ksc.defender dbus is invalid";
return -1;
} }
QDBusReply<int> reply = m_dbusInterface->call("break_networkConnect", uuid, cardName, ssid); QDBusReply<int> reply = m_dbusInterface->call("break_networkConnect", uuid, cardName, ssid);