fix types and network device notifications
This commit is contained in:
parent
24276d393c
commit
28f6263ec0
@ -334,6 +334,7 @@ void JsonTypes::init()
|
||||
s_wirelessAccessPoint.insert("macAddress", basicTypeToString(QVariant::String));
|
||||
s_wirelessAccessPoint.insert("frequency", basicTypeToString(QVariant::Double));
|
||||
s_wirelessAccessPoint.insert("signalStrength", basicTypeToString(QVariant::Int));
|
||||
s_wirelessAccessPoint.insert("protected", basicTypeToString(QVariant::Bool));
|
||||
|
||||
// WiredNetworkDevice
|
||||
s_wiredNetworkDevice.insert("interface", basicTypeToString(QVariant::String));
|
||||
@ -396,6 +397,7 @@ QVariantMap JsonTypes::allTypes()
|
||||
allTypes.insert("ConfigurationError", configurationError());
|
||||
allTypes.insert("NetworkManagerError", networkManagerError());
|
||||
allTypes.insert("NetworkManagerState", networkManagerState());
|
||||
allTypes.insert("NetworkDeviceState", networkDeviceState());
|
||||
|
||||
allTypes.insert("StateType", stateTypeDescription());
|
||||
allTypes.insert("StateDescriptor", stateDescriptorDescription());
|
||||
@ -979,7 +981,7 @@ QVariantMap JsonTypes::packWirelessAccessPoint(WirelessAccessPoint *wirelessAcce
|
||||
wirelessAccessPointVariant.insert("macAddress", wirelessAccessPoint->macAddress());
|
||||
wirelessAccessPointVariant.insert("frequency", wirelessAccessPoint->frequency());
|
||||
wirelessAccessPointVariant.insert("signalStrength", wirelessAccessPoint->signalStrength());
|
||||
|
||||
wirelessAccessPointVariant.insert("protected", wirelessAccessPoint->isProtected());
|
||||
return wirelessAccessPointVariant;
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
#include "cloud/cloudconnection.h"
|
||||
|
||||
#include "networkmanager/networkmanager.h"
|
||||
#include "networkmanager/networkdevice.h"
|
||||
#include "networkmanager/wirednetworkdevice.h"
|
||||
#include "networkmanager/wirelessnetworkdevice.h"
|
||||
#include "networkmanager/wirelessaccesspoint.h"
|
||||
|
||||
@ -57,7 +57,7 @@ NetworkDevice::NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent)
|
||||
m_autoconnect = m_networkDeviceInterface->property("Autoconnect").toBool();
|
||||
|
||||
m_deviceState = NetworkDeviceState(m_networkDeviceInterface->property("State").toUInt());
|
||||
m_deviceType = DeviceType(m_networkDeviceInterface->property("DeviceType").toUInt());
|
||||
m_deviceType = NetworkDeviceType(m_networkDeviceInterface->property("NetworkDeviceType").toUInt());
|
||||
|
||||
m_activeConnection = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("ActiveConnection"));
|
||||
m_ip4Config = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("Ip4Config"));
|
||||
@ -136,7 +136,7 @@ NetworkDevice::NetworkDeviceStateReason NetworkDevice::deviceStateReason() const
|
||||
return m_deviceStateReason;
|
||||
}
|
||||
|
||||
NetworkDevice::DeviceType NetworkDevice::deviceType() const
|
||||
NetworkDevice::NetworkDeviceType NetworkDevice::deviceType() const
|
||||
{
|
||||
return m_deviceType;
|
||||
}
|
||||
@ -164,12 +164,12 @@ void NetworkDevice::disconnectDevice()
|
||||
|
||||
}
|
||||
|
||||
QString NetworkDevice::deviceTypeToString(const NetworkDevice::DeviceType &deviceType)
|
||||
QString NetworkDevice::deviceTypeToString(const NetworkDevice::NetworkDeviceType &deviceType)
|
||||
{
|
||||
QMetaObject metaObject = NetworkDevice::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("DeviceType").toLatin1().data());
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkDeviceType").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(deviceType)).remove("DeviceType");
|
||||
return QString(metaEnum.valueToKey(deviceType)).remove("NetworkDeviceType");
|
||||
}
|
||||
|
||||
QString NetworkDevice::deviceStateToString(const NetworkDevice::NetworkDeviceState &deviceState)
|
||||
@ -192,8 +192,10 @@ void NetworkDevice::onStateChanged(uint newState, uint oldState, uint reason)
|
||||
{
|
||||
Q_UNUSED(oldState);
|
||||
qCDebug(dcNetworkManager()) << m_interface << "--> State changed:" << deviceStateToString(NetworkDeviceState(newState)) << ":" << deviceStateReasonToString(NetworkDeviceStateReason(reason));
|
||||
m_deviceState = NetworkDeviceState(newState);
|
||||
emit deviceChanged();
|
||||
if (m_deviceState != NetworkDeviceState(newState)) {
|
||||
m_deviceState = NetworkDeviceState(newState);
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkDevice *device)
|
||||
|
||||
@ -35,7 +35,7 @@ namespace guhserver {
|
||||
class NetworkDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(DeviceType)
|
||||
Q_ENUMS(NetworkDeviceType)
|
||||
Q_ENUMS(NetworkDeviceState)
|
||||
Q_ENUMS(NetworkDeviceStateReason)
|
||||
|
||||
@ -122,26 +122,26 @@ public:
|
||||
NetworkDeviceStateReasonParentManagedChanged = 62
|
||||
};
|
||||
|
||||
enum DeviceType {
|
||||
DeviceTypeUnknown = 0,
|
||||
DeviceTypeEthernet = 1,
|
||||
DeviceTypeWifi = 2,
|
||||
DeviceTypeBluetooth = 5,
|
||||
DeviceTypeOlpcMesh = 6,
|
||||
DeviceTypeWiMax = 7,
|
||||
DeviceTypeModem = 8,
|
||||
DeviceTypeInfiniBand = 9,
|
||||
DeviceTypeBond = 10,
|
||||
DeviceTypeVLan = 11,
|
||||
DeviceTypeAdsl = 12,
|
||||
DeviceTypeBridge = 13,
|
||||
DeviceTypeGeneric = 14,
|
||||
DeviceTypeTeam = 15,
|
||||
DeviceTypeTun = 16,
|
||||
DeviceTypeIpTunnel = 17,
|
||||
DeviceTypeMacVLan = 18,
|
||||
DeviceTypeVXLan = 19,
|
||||
DeviceTypeVEth = 20,
|
||||
enum NetworkDeviceType {
|
||||
NetworkDeviceTypeUnknown = 0,
|
||||
NetworkDeviceTypeEthernet = 1,
|
||||
NetworkDeviceTypeWifi = 2,
|
||||
NetworkDeviceTypeBluetooth = 5,
|
||||
NetworkDeviceTypeOlpcMesh = 6,
|
||||
NetworkDeviceTypeWiMax = 7,
|
||||
NetworkDeviceTypeModem = 8,
|
||||
NetworkDeviceTypeInfiniBand = 9,
|
||||
NetworkDeviceTypeBond = 10,
|
||||
NetworkDeviceTypeVLan = 11,
|
||||
NetworkDeviceTypeAdsl = 12,
|
||||
NetworkDeviceTypeBridge = 13,
|
||||
NetworkDeviceTypeGeneric = 14,
|
||||
NetworkDeviceTypeTeam = 15,
|
||||
NetworkDeviceTypeTun = 16,
|
||||
NetworkDeviceTypeIpTunnel = 17,
|
||||
NetworkDeviceTypeMacVLan = 18,
|
||||
NetworkDeviceTypeVXLan = 19,
|
||||
NetworkDeviceTypeVEth = 20,
|
||||
};
|
||||
|
||||
explicit NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = 0);
|
||||
@ -163,7 +163,7 @@ public:
|
||||
QString deviceStateString() const;
|
||||
|
||||
NetworkDeviceStateReason deviceStateReason() const;
|
||||
DeviceType deviceType() const;
|
||||
NetworkDeviceType deviceType() const;
|
||||
|
||||
QDBusObjectPath activeConnection() const;
|
||||
QDBusObjectPath ip4Config() const;
|
||||
@ -172,7 +172,7 @@ public:
|
||||
// Method
|
||||
void disconnectDevice();
|
||||
|
||||
static QString deviceTypeToString(const DeviceType &deviceType);
|
||||
static QString deviceTypeToString(const NetworkDeviceType &deviceType);
|
||||
static QString deviceStateToString(const NetworkDeviceState &deviceState);
|
||||
static QString deviceStateReasonToString(const NetworkDeviceStateReason &deviceStateReason);
|
||||
|
||||
@ -193,7 +193,7 @@ private:
|
||||
bool m_autoconnect;
|
||||
NetworkDeviceState m_deviceState;
|
||||
NetworkDeviceStateReason m_deviceStateReason;
|
||||
DeviceType m_deviceType;
|
||||
NetworkDeviceType m_deviceType;
|
||||
|
||||
QDBusObjectPath m_activeConnection;
|
||||
QDBusObjectPath m_ip4Config;
|
||||
@ -213,4 +213,9 @@ QDebug operator<<(QDebug debug, NetworkDevice *device);
|
||||
|
||||
}
|
||||
|
||||
using namespace guhserver;
|
||||
Q_DECLARE_METATYPE(NetworkDevice::NetworkDeviceType)
|
||||
Q_DECLARE_METATYPE(NetworkDevice::NetworkDeviceState)
|
||||
Q_DECLARE_METATYPE(NetworkDevice::NetworkDeviceStateReason)
|
||||
|
||||
#endif // NETWORKDEVICE_H
|
||||
|
||||
@ -155,8 +155,8 @@ NetworkManager::NetworkManagerError NetworkManager::connectWifi(const QString &i
|
||||
|
||||
QVariantMap wirelessSettings;
|
||||
wirelessSettings.insert("ssid", ssid.toUtf8());
|
||||
wirelessSettings.insert("security", "802-11-wireless-security");
|
||||
wirelessSettings.insert("mode", "infrastructure");
|
||||
wirelessSettings.insert("security", "802-11-wireless-security");
|
||||
|
||||
QVariantMap wirelessSecuritySettings;
|
||||
wirelessSecuritySettings.insert("auth-alg", "open");
|
||||
@ -173,11 +173,16 @@ NetworkManager::NetworkManagerError NetworkManager::connectWifi(const QString &i
|
||||
ConnectionSettings settings;
|
||||
settings.insert("connection", connectionSettings);
|
||||
settings.insert("802-11-wireless", wirelessSettings);
|
||||
settings.insert("802-11-wireless-security", wirelessSecuritySettings);
|
||||
settings.insert("ipv4", ipv4Settings);
|
||||
settings.insert("ipv6", ipv6Settings);
|
||||
settings.insert("802-11-wireless-security", wirelessSecuritySettings);
|
||||
|
||||
// TODO: check if connection exists
|
||||
// Remove old configuration (if there is any)
|
||||
foreach (NetworkConnection *connection, m_networkSettings->connections()) {
|
||||
if (connection->id() == connectionSettings.value("id")) {
|
||||
connection->deleteConnection();
|
||||
}
|
||||
}
|
||||
|
||||
// Add connection
|
||||
QDBusObjectPath connectionObjectPath = m_networkSettings->addConnection(settings);
|
||||
@ -312,9 +317,9 @@ void NetworkManager::onDeviceAdded(const QDBusObjectPath &deviceObjectPath)
|
||||
}
|
||||
|
||||
// Create object
|
||||
NetworkDevice::DeviceType deviceType = NetworkDevice::DeviceType(networkDeviceInterface.property("DeviceType").toUInt());
|
||||
NetworkDevice::NetworkDeviceType deviceType = NetworkDevice::NetworkDeviceType(networkDeviceInterface.property("NetworkDeviceType").toUInt());
|
||||
switch (deviceType) {
|
||||
case NetworkDevice::DeviceTypeWifi: {
|
||||
case NetworkDevice::NetworkDeviceTypeWifi: {
|
||||
WirelessNetworkDevice *wirelessNetworkDevice = new WirelessNetworkDevice(deviceObjectPath, this);
|
||||
qCDebug(dcNetworkManager()) << "[+]" << wirelessNetworkDevice;
|
||||
m_wifiAvailable = true;
|
||||
@ -324,7 +329,7 @@ void NetworkManager::onDeviceAdded(const QDBusObjectPath &deviceObjectPath)
|
||||
emit wirelessDeviceAdded(wirelessNetworkDevice);
|
||||
break;
|
||||
}
|
||||
case NetworkDevice::DeviceTypeEthernet: {
|
||||
case NetworkDevice::NetworkDeviceTypeEthernet: {
|
||||
WiredNetworkDevice *wiredNetworkDevice = new WiredNetworkDevice(deviceObjectPath, this);
|
||||
qCDebug(dcNetworkManager()) << "[+]" << wiredNetworkDevice;
|
||||
m_networkDevices.insert(deviceObjectPath, wiredNetworkDevice);
|
||||
|
||||
@ -53,6 +53,11 @@ QDBusObjectPath NetworkSettings::addConnection(const ConnectionSettings &setting
|
||||
return query.arguments().at(0).value<QDBusObjectPath>();
|
||||
}
|
||||
|
||||
QList<NetworkConnection *> NetworkSettings::connections() const
|
||||
{
|
||||
return m_connections.values();
|
||||
}
|
||||
|
||||
void NetworkSettings::loadConnections()
|
||||
{
|
||||
QDBusMessage query = m_settingsInterface->call("ListConnections");
|
||||
@ -79,13 +84,14 @@ void NetworkSettings::connectionAdded(const QDBusObjectPath &objectPath)
|
||||
NetworkConnection *connection = new NetworkConnection(objectPath, this);
|
||||
m_connections.insert(objectPath, connection);
|
||||
|
||||
//qCDebug(dcNetworkManager()) << "Settings: [+]" << connection;
|
||||
qCDebug(dcNetworkManager()) << "Settings: [+]" << connection;
|
||||
}
|
||||
|
||||
void NetworkSettings::connectionRemoved(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
Q_UNUSED(objectPath);
|
||||
//qCDebug(dcNetworkManager()) << "Settings: [-]" << objectPath.path();
|
||||
NetworkConnection *connection = m_connections.take(objectPath);
|
||||
qCDebug(dcNetworkManager()) << "Settings: [-]" << connection;
|
||||
connection->deleteLater();
|
||||
}
|
||||
|
||||
void NetworkSettings::propertiesChanged(const QVariantMap &properties)
|
||||
|
||||
@ -40,6 +40,7 @@ public:
|
||||
explicit NetworkSettings(QObject *parent = 0);
|
||||
|
||||
QDBusObjectPath addConnection(const ConnectionSettings &settings);
|
||||
QList<NetworkConnection *> connections() const;
|
||||
|
||||
private:
|
||||
QDBusInterface *m_settingsInterface;
|
||||
|
||||
@ -26,7 +26,8 @@ namespace guhserver {
|
||||
|
||||
WirelessAccessPoint::WirelessAccessPoint(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_objectPath(objectPath)
|
||||
m_objectPath(objectPath),
|
||||
m_securityFlags(0)
|
||||
{
|
||||
QDBusInterface accessPointInterface(serviceString, m_objectPath.path(), accessPointInterfaceString, QDBusConnection::systemBus());
|
||||
if(!accessPointInterface.isValid()) {
|
||||
@ -40,6 +41,7 @@ WirelessAccessPoint::WirelessAccessPoint(const QDBusObjectPath &objectPath, QObj
|
||||
setFrequency(accessPointInterface.property("Frequency").toDouble() / 1000);
|
||||
setSignalStrength(accessPointInterface.property("Strength").toUInt());
|
||||
setSecurityFlags(WirelessAccessPoint::ApSecurityModes(accessPointInterface.property("WpaFlags").toUInt()));
|
||||
setIsProtected((bool)accessPointInterface.property("Flags").toUInt());
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, objectPath.path(), accessPointInterfaceString, "PropertiesChanged", this, SLOT(onPropertiesChanged(QVariantMap)));
|
||||
}
|
||||
@ -90,6 +92,16 @@ void WirelessAccessPoint::setSignalStrength(const int &signalStrength)
|
||||
emit signalStrengthChanged();
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setIsProtected(const bool &isProtected)
|
||||
{
|
||||
m_isProtected = isProtected;
|
||||
}
|
||||
|
||||
bool WirelessAccessPoint::isProtected() const
|
||||
{
|
||||
return m_isProtected;
|
||||
}
|
||||
|
||||
WirelessAccessPoint::ApSecurityModes WirelessAccessPoint::securityFlags() const
|
||||
{
|
||||
return m_securityFlags;
|
||||
@ -109,7 +121,7 @@ void WirelessAccessPoint::onPropertiesChanged(const QVariantMap &properties)
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessAccessPoint *accessPoint)
|
||||
{
|
||||
return debug.nospace() << "AccessPoint(" << accessPoint->signalStrength() << "%, " << accessPoint->frequency()<< " GHz, " << accessPoint->ssid() << ")";
|
||||
return debug.nospace() << "AccessPoint(" << accessPoint->signalStrength() << "%, " << accessPoint->frequency()<< " GHz, " << accessPoint->ssid() << ", " << (accessPoint->isProtected() ? "protected" : "open" ) << ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -58,16 +58,10 @@ public:
|
||||
QDBusObjectPath objectPath() const;
|
||||
|
||||
QString ssid() const;
|
||||
void setSsid(const QString &ssid);
|
||||
|
||||
QString macAddress() const;
|
||||
void setMacAddress(const QString &macAddress);
|
||||
|
||||
double frequency() const;
|
||||
void setFrequency(const double &frequency);
|
||||
|
||||
int signalStrength() const;
|
||||
void setSignalStrength(const int &signalStrength);
|
||||
bool isProtected() const;
|
||||
|
||||
WirelessAccessPoint::ApSecurityModes securityFlags() const;
|
||||
void setSecurityFlags(const WirelessAccessPoint::ApSecurityModes &securityFlags);
|
||||
@ -78,8 +72,15 @@ private:
|
||||
QString m_macAddress;
|
||||
double m_frequency;
|
||||
int m_signalStrength;
|
||||
bool m_isProtected;
|
||||
WirelessAccessPoint::ApSecurityModes m_securityFlags;
|
||||
|
||||
void setSsid(const QString &ssid);
|
||||
void setMacAddress(const QString &macAddress);
|
||||
void setFrequency(const double &frequency);
|
||||
void setSignalStrength(const int &signalStrength);
|
||||
void setIsProtected(const bool &isProtected);
|
||||
|
||||
signals:
|
||||
void signalStrengthChanged();
|
||||
|
||||
|
||||
@ -126,15 +126,28 @@ void WirelessNetworkDevice::setMacAddress(const QString &macAddress)
|
||||
|
||||
void WirelessNetworkDevice::setBitrate(const int &bitRate)
|
||||
{
|
||||
m_bitRate = bitRate / 1000;
|
||||
if (m_bitRate != bitRate / 1000) {
|
||||
m_bitRate = bitRate / 1000;
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::setActiveAccessPoint(const QDBusObjectPath &activeAccessPointObjectPath)
|
||||
{
|
||||
if (m_accessPointsTable.contains(activeAccessPointObjectPath)) {
|
||||
m_activeAccessPoint = m_accessPointsTable.value(activeAccessPointObjectPath);
|
||||
} else {
|
||||
m_activeAccessPoint = Q_NULLPTR;
|
||||
if (m_activeAccessPointObjectPath != activeAccessPointObjectPath) {
|
||||
m_activeAccessPointObjectPath = activeAccessPointObjectPath;
|
||||
if (m_accessPointsTable.contains(m_activeAccessPointObjectPath)) {
|
||||
if (m_activeAccessPoint)
|
||||
disconnect(m_activeAccessPoint, &WirelessAccessPoint::signalStrengthChanged, this, &WirelessNetworkDevice::deviceChanged);
|
||||
|
||||
// Set new access point object
|
||||
m_activeAccessPoint = m_accessPointsTable.value(activeAccessPointObjectPath);
|
||||
// Update the device when the signalstrength changed
|
||||
connect(m_activeAccessPoint, &WirelessAccessPoint::signalStrengthChanged, this, &WirelessNetworkDevice::deviceChanged);
|
||||
} else {
|
||||
m_activeAccessPoint = Q_NULLPTR;
|
||||
}
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,8 +191,6 @@ void WirelessNetworkDevice::propertiesChanged(const QVariantMap &properties)
|
||||
|
||||
if (properties.contains("ActiveAccessPoint"))
|
||||
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(properties.value("ActiveAccessPoint")));
|
||||
|
||||
emit deviceChanged();
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessNetworkDevice *manager)
|
||||
|
||||
@ -60,6 +60,7 @@ private:
|
||||
QString m_macAddress;
|
||||
int m_bitRate;
|
||||
WirelessAccessPoint *m_activeAccessPoint;
|
||||
QDBusObjectPath m_activeAccessPointObjectPath;
|
||||
|
||||
QHash<QDBusObjectPath, WirelessAccessPoint *> m_accessPointsTable;
|
||||
|
||||
|
||||
@ -1108,6 +1108,21 @@
|
||||
"LoggingSourceStates",
|
||||
"LoggingSourceRules"
|
||||
],
|
||||
"NetworkDeviceState": [
|
||||
"NetworkDeviceStateUnknown",
|
||||
"NetworkDeviceStateUnmanaged",
|
||||
"NetworkDeviceStateUnavailable",
|
||||
"NetworkDeviceStateDisconnected",
|
||||
"NetworkDeviceStatePrepare",
|
||||
"NetworkDeviceStateConfig",
|
||||
"NetworkDeviceStateNeedAuth",
|
||||
"NetworkDeviceStateIpConfig",
|
||||
"NetworkDeviceStateIpCheck",
|
||||
"NetworkDeviceStateSecondaries",
|
||||
"NetworkDeviceStateActivated",
|
||||
"NetworkDeviceStateDeactivating",
|
||||
"NetworkDeviceStateFailed"
|
||||
],
|
||||
"NetworkManagerError": [
|
||||
"NetworkManagerErrorNoError",
|
||||
"NetworkManagerErrorUnknownError",
|
||||
@ -1372,6 +1387,7 @@
|
||||
"WirelessAccessPoint": {
|
||||
"frequency": "Double",
|
||||
"macAddress": "String",
|
||||
"protected": "Bool",
|
||||
"signalStrength": "Int",
|
||||
"ssid": "String"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user