From 86febbf35190d680a61af4676704c5ece8a9de98 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 4 Sep 2012 15:19:10 -0500 Subject: [PATCH] Add connection to device lookup routines --- .../network-manager/network-manager.cpp | 35 +++++++++++++++++++ .../network-manager/network-manager.h | 1 + tdecore/tdenetworkconnections.cpp | 31 ++++++++++++++++ tdecore/tdenetworkconnections.h | 32 +++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/tdecore/networkbackends/network-manager/network-manager.cpp b/tdecore/networkbackends/network-manager/network-manager.cpp index 57ae8672d..ea962367b 100644 --- a/tdecore/networkbackends/network-manager/network-manager.cpp +++ b/tdecore/networkbackends/network-manager/network-manager.cpp @@ -3965,6 +3965,41 @@ TDENetworkConnectionStatus::TDENetworkConnectionStatus TDENetworkConnectionManag } } +TQStringList TDENetworkConnectionManager_BackendNM::connectionPhysicalDeviceUUIDs(TQString uuid) { + if (deviceType() == TDENetworkDeviceType::BackendOnly) { + return TQStringList(); + } + + TQT_DBusObjectPath existingConnection; + TQT_DBusError error; + if (d->m_networkManagerProxy) { + TQT_DBusObjectPathList activeConnections = d->m_networkManagerProxy->getActiveConnections(error); + TQT_DBusObjectPathList::iterator it; + TQStringList ret; + for (it = activeConnections.begin(); it != activeConnections.end(); ++it) { + DBus::ActiveConnectionProxy activeConnection(NM_DBUS_SERVICE, (*it)); + activeConnection.setConnection(TQT_DBusConnection::systemBus()); + if (activeConnection.getUuid(error) == uuid) { + TQValueList deviceList = activeConnection.getDevices(error); + TQT_DBusObjectPathList::iterator it2; + for (it2 = deviceList.begin(); it2 != deviceList.end(); ++it2) { + DBus::DeviceProxy underlyingNetworkDeviceProxy(NM_DBUS_SERVICE, *it2); + underlyingNetworkDeviceProxy.setConnection(TQT_DBusConnection::systemBus()); + TQString devUUID = underlyingNetworkDeviceProxy.getUdi(error); + if (devUUID != "") { + ret.append(devUUID); + } + } + } + } + return ret; + } + else { + PRINT_ERROR(TQString("invalid internal network-manager settings proxy object").arg(uuid)); + return TQStringList(); + } +} + TDENetworkConnectionStatus::TDENetworkConnectionStatus TDENetworkConnectionManager_BackendNM::deactivateConnection(TQString uuid) { TQT_DBusObjectPath existingConnection; TQT_DBusError error; diff --git a/tdecore/networkbackends/network-manager/network-manager.h b/tdecore/networkbackends/network-manager/network-manager.h index ef878bb00..d0b2df302 100644 --- a/tdecore/networkbackends/network-manager/network-manager.h +++ b/tdecore/networkbackends/network-manager/network-manager.h @@ -139,6 +139,7 @@ class TDECORE_EXPORT TDENetworkConnectionManager_BackendNM : public TDENetworkCo virtual TDENetworkConnectionStatus::TDENetworkConnectionStatus deactivateConnection(TQString uuid); virtual TDENetworkHWNeighborList* siteSurvey(); + virtual TQStringList connectionPhysicalDeviceUUIDs(TQString uuid); virtual bool networkingEnabled(); virtual bool wiFiHardwareEnabled(); diff --git a/tdecore/tdenetworkconnections.cpp b/tdecore/tdenetworkconnections.cpp index 71132825e..d9f4b5d97 100644 --- a/tdecore/tdenetworkconnections.cpp +++ b/tdecore/tdenetworkconnections.cpp @@ -635,6 +635,27 @@ TDENetworkConnection* TDENetworkConnectionManager::findConnectionByUUID(TQString return NULL; } +TDENetworkDevice* TDENetworkConnectionManager::findDeviceByUUID(TQString uuid) { + TDEHardwareDevices *hwdevices = KGlobal::hardwareDevices(); + if (!hwdevices) return NULL; + + TDEGenericHardwareList devices = hwdevices->listByDeviceClass(TDEGenericDeviceType::Network); + for (TDEGenericHardwareList::iterator it = devices.begin(); it != devices.end(); ++it) + { + TDENetworkDevice* dev = dynamic_cast(*it); + if (dev) { + TDENetworkConnectionManager* deviceConnectionManager = dev->connectionManager(); + if (deviceConnectionManager) { + if (deviceConnectionManager->deviceInformation().UUID == uuid) { + return dev; + } + } + } + } + + return NULL; +} + void TDENetworkConnectionManager::clearTDENetworkConnectionList() { TDENetworkConnection *connection; for (connection = m_connectionList->first(); connection; connection = m_connectionList->next()) { @@ -724,6 +745,11 @@ TDENetworkHWNeighborList* TDEGlobalNetworkManager::siteSurvey() { return m_internalConnectionManager->siteSurvey(); } +TQStringList TDEGlobalNetworkManager::connectionPhysicalDeviceUUIDs(TQString uuid) { + if (!m_internalConnectionManager) return TQStringList(); + return m_internalConnectionManager->connectionPhysicalDeviceUUIDs(uuid); +} + bool TDEGlobalNetworkManager::networkingEnabled() { if (!m_internalConnectionManager) return false; return m_internalConnectionManager->networkingEnabled(); @@ -759,6 +785,11 @@ TDENetworkConnection* TDEGlobalNetworkManager::findConnectionByUUID(TQString uui return m_internalConnectionManager->findConnectionByUUID(uuid); } +TDENetworkDevice* TDEGlobalNetworkManager::findDeviceByUUID(TQString uuid) { + if (!m_internalConnectionManager) return NULL; + return m_internalConnectionManager->findDeviceByUUID(uuid); +} + /*================================================================================================*/ /* End */ /*================================================================================================*/ diff --git a/tdecore/tdenetworkconnections.h b/tdecore/tdenetworkconnections.h index 92e5e5cb5..e41251b9d 100644 --- a/tdecore/tdenetworkconnections.h +++ b/tdecore/tdenetworkconnections.h @@ -56,6 +56,8 @@ return a; \ } +class TDENetworkDevice; + typedef TQValueList TDENetworkByteList; typedef TQValueList TDENetworkAddressList; typedef TQMap TDENetworkSettingsMap; @@ -989,6 +991,13 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject */ virtual TDENetworkHWNeighborList* siteSurvey() = 0; + /** + * @return a TQStringList containing the UUIDs of all physical devices used by this connection + * This function may return an empty list if the connection is inactive, this behaviour is + * dependend on the specific network backend in use. + */ + virtual TQStringList connectionPhysicalDeviceUUIDs(TQString uuid) = 0; + /** * @return true if networking is enabled, false if not. */ @@ -1055,6 +1064,14 @@ class TDECORE_EXPORT TDENetworkConnectionManager : public TQObject */ TDENetworkConnection* findConnectionByUUID(TQString uuid); + /** + * @return a pointer to a TDENetworkDevice object with the specified @param uuid, + * or a NULL pointer if no such connection exists. + * + * Note that the returned object is internally managed and must not be deleted! + */ + TDENetworkDevice* findDeviceByUUID(TQString uuid); + protected: void clearTDENetworkConnectionList(); void clearTDENetworkHWNeighborList(); @@ -1149,6 +1166,13 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject */ virtual TDENetworkHWNeighborList* siteSurvey(); + /** + * @return a TQStringList containing the UUIDs of all physical devices used by this connection + * This function may return an empty list if the connection is inactive, this behaviour is + * dependend on the specific network backend in use. + */ + virtual TQStringList connectionPhysicalDeviceUUIDs(TQString uuid); + /** * @return true if networking is enabled, false if not. */ @@ -1215,6 +1239,14 @@ class TDECORE_EXPORT TDEGlobalNetworkManager : public TQObject */ TDENetworkConnection* findConnectionByUUID(TQString uuid); + /** + * @return a pointer to a TDENetworkDevice object with the specified @param uuid, + * or a NULL pointer if no such connection exists. + * + * Note that the returned object is internally managed and must not be deleted! + */ + TDENetworkDevice* findDeviceByUUID(TQString uuid); + private: TDENetworkConnectionManager* m_internalConnectionManager; };