Ticket #46496: Use-a-property-cache-to-cut-down-on-blocking-calls.patch
File Use-a-property-cache-to-cut-down-on-blocking-calls.patch, 165.7 KB (added by RJVB (René Bertin), 10 years ago) |
---|
-
qtbase/src/plugins/bearer/connman/connman.pro
From 1df2cd6af5c40db588fc3ec40c7adfafc1b5eea3 Mon Sep 17 00:00:00 2001 From: Lorn Potter <lorn.potter@gmail.com> Date: Wed, 29 Oct 2014 19:40:43 +1000 Subject: [PATCH] Use a property cache to cut down on blocking calls Refactor old code Stop memory leaks Properly support mobile data (ofono) Change-Id: I7f23882ee0ee345a049a4a93ddd452b6d2e53710 --- src/plugins/bearer/connman/connman.pro | 4 +- src/plugins/bearer/connman/qconnmanengine.h | 2 +- src/plugins/bearer/connman/qofonoservice_linux.cpp | 303 --------- src/plugins/bearer/connman/qofonoservice_linux_p.h | 172 ----- .../bearer/linux_common/qofonoservice_linux.cpp | 370 +++++++++++ .../bearer/linux_common/qofonoservice_linux_p.h | 195 ++++++ .../bearer/networkmanager/networkmanager.pro | 6 +- .../networkmanager/qnetworkmanagerengine.cpp | 364 +++++------ .../bearer/networkmanager/qnetworkmanagerengine.h | 22 +- .../networkmanager/qnetworkmanagerservice.cpp | 693 +++++++++++++++------ .../bearer/networkmanager/qnetworkmanagerservice.h | 105 +++- .../bearer/networkmanager/qnmdbushelper.cpp | 140 ----- src/plugins/bearer/networkmanager/qnmdbushelper.h | 73 --- 13 files changed, 1318 insertions(+), 1131 deletions(-) delete mode 100644 src/plugins/bearer/connman/qofonoservice_linux.cpp delete mode 100644 src/plugins/bearer/connman/qofonoservice_linux_p.h create mode 100644 src/plugins/bearer/linux_common/qofonoservice_linux.cpp create mode 100644 src/plugins/bearer/linux_common/qofonoservice_linux_p.h delete mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.cpp delete mode 100644 src/plugins/bearer/networkmanager/qnmdbushelper.h
8 8 CONFIG += link_pkgconfig 9 9 10 10 HEADERS += qconnmanservice_linux_p.h \ 11 qofonoservice_linux_p.h \11 ../linux_common/qofonoservice_linux_p.h \ 12 12 qconnmanengine.h \ 13 13 ../qnetworksession_impl.h \ 14 14 ../qbearerengine_impl.h 15 15 16 16 SOURCES += main.cpp \ 17 17 qconnmanservice_linux.cpp \ 18 qofonoservice_linux.cpp \18 ../linux_common/qofonoservice_linux.cpp \ 19 19 qconnmanengine.cpp \ 20 20 ../qnetworksession_impl.cpp 21 21 -
qtbase/src/plugins/bearer/connman/qconnmanengine.h
56 56 #include "../qbearerengine_impl.h" 57 57 58 58 #include "qconnmanservice_linux_p.h" 59 #include " qofonoservice_linux_p.h"59 #include "../linux_common/qofonoservice_linux_p.h" 60 60 61 61 #include <QMap> 62 62 #include <QVariant> -
new file qtbase/src/plugins/bearer/linux_common/qofonoservice_linux.cpp
- + 1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 ** Contact: http://www.qt-project.org/legal 5 ** 6 ** This file is part of the plugins of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 ** use the contact form at http://qt.digia.com/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** In addition, as a special exception, Digia gives you certain additional 27 ** rights. These rights are described in the Digia Qt LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** $QT_END_LICENSE$ 31 ** 32 ****************************************************************************/ 33 34 #include <QObject> 35 #include <QList> 36 #include <QtDBus/QtDBus> 37 #include <QtDBus/QDBusConnection> 38 #include <QtDBus/QDBusError> 39 #include <QtDBus/QDBusInterface> 40 #include <QtDBus/QDBusMessage> 41 #include <QtDBus/QDBusReply> 42 #include <QtDBus/QDBusPendingCallWatcher> 43 #include <QtDBus/QDBusObjectPath> 44 #include <QtDBus/QDBusPendingCall> 45 46 #include "qofonoservice_linux_p.h" 47 48 #ifndef QT_NO_BEARERMANAGEMENT 49 #ifndef QT_NO_DBUS 50 51 QDBusArgument &operator<<(QDBusArgument &argument, const ObjectPathProperties &item) 52 { 53 argument.beginStructure(); 54 argument << item.path << item.properties; 55 argument.endStructure(); 56 return argument; 57 } 58 59 const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathProperties &item) 60 { 61 argument.beginStructure(); 62 argument >> item.path >> item.properties; 63 argument.endStructure(); 64 return argument; 65 } 66 67 QT_BEGIN_NAMESPACE 68 69 QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent) 70 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), 71 QStringLiteral(OFONO_MANAGER_PATH), 72 OFONO_MANAGER_INTERFACE, 73 QDBusConnection::systemBus(), parent) 74 { 75 qDBusRegisterMetaType<ObjectPathProperties>(); 76 qDBusRegisterMetaType<PathPropertiesList>(); 77 78 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), 79 QStringLiteral(OFONO_MANAGER_PATH), 80 QStringLiteral(OFONO_MANAGER_INTERFACE), 81 QStringLiteral("ModemAdded"), 82 this,SLOT(modemAdded(QDBusObjectPath, QVariantMap))); 83 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), 84 QStringLiteral(OFONO_MANAGER_PATH), 85 QStringLiteral(OFONO_MANAGER_INTERFACE), 86 QStringLiteral("ModemRemoved"), 87 this,SLOT(modemRemoved(QDBusObjectPath))); 88 } 89 90 QOfonoManagerInterface::~QOfonoManagerInterface() 91 { 92 } 93 94 QStringList QOfonoManagerInterface::getModems() 95 { 96 if (modemList.isEmpty()) { 97 QList<QVariant> argumentList; 98 QDBusPendingReply<PathPropertiesList> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetModems"), argumentList); 99 reply.waitForFinished(); 100 if (!reply.isError()) { 101 foreach (ObjectPathProperties modem, reply.value()) { 102 modemList << modem.path.path(); 103 } 104 } 105 } 106 107 return modemList; 108 } 109 110 QString QOfonoManagerInterface::currentModem() 111 { 112 QStringList modems = getModems(); 113 foreach (const QString &modem, modems) { 114 QOfonoModemInterface device(modem); 115 if (device.isPowered() && device.isOnline()) 116 return modem; 117 } 118 return QString(); 119 } 120 121 void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/) 122 { 123 if (!modemList.contains(path.path())) { 124 modemList << path.path(); 125 Q_EMIT modemChanged(); 126 } 127 } 128 129 void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path) 130 { 131 if (modemList.contains(path.path())) { 132 modemList.removeOne(path.path()); 133 Q_EMIT modemChanged(); 134 } 135 } 136 137 138 QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent) 139 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), 140 dbusPathName, 141 OFONO_MODEM_INTERFACE, 142 QDBusConnection::systemBus(), parent) 143 { 144 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), 145 path(), 146 OFONO_MODEM_INTERFACE, 147 QStringLiteral("PropertyChanged"), 148 this,SLOT(propertyChanged(QString,QDBusVariant))); 149 } 150 151 QOfonoModemInterface::~QOfonoModemInterface() 152 { 153 } 154 155 void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value) 156 { 157 propertiesMap[name] = value.variant(); 158 } 159 160 bool QOfonoModemInterface::isPowered() 161 { 162 QVariant var = getProperty(QStringLiteral("Powered")); 163 return qdbus_cast<bool>(var); 164 } 165 166 bool QOfonoModemInterface::isOnline() 167 { 168 QVariant var = getProperty(QStringLiteral("Online")); 169 return qdbus_cast<bool>(var); 170 } 171 172 QVariantMap QOfonoModemInterface::getProperties() 173 { 174 if (propertiesMap.isEmpty()) { 175 QList<QVariant> argumentList; 176 QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); 177 if (!reply.isError()) { 178 propertiesMap = reply.value(); 179 } 180 } 181 return propertiesMap; 182 } 183 184 QVariant QOfonoModemInterface::getProperty(const QString &property) 185 { 186 QVariant var; 187 QVariantMap map = getProperties(); 188 if (map.contains(property)) 189 var = map.value(property); 190 return var; 191 } 192 193 194 QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent) 195 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), 196 dbusPathName, 197 OFONO_NETWORK_REGISTRATION_INTERFACE, 198 QDBusConnection::systemBus(), parent) 199 { 200 } 201 202 QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface() 203 { 204 } 205 206 QString QOfonoNetworkRegistrationInterface::getTechnology() 207 { 208 QVariant var = getProperty(QStringLiteral("Technology")); 209 return qdbus_cast<QString>(var); 210 } 211 212 QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property) 213 { 214 QVariant var; 215 QVariantMap map = getProperties(); 216 if (map.contains(property)) 217 var = map.value(property); 218 return var; 219 } 220 221 QVariantMap QOfonoNetworkRegistrationInterface::getProperties() 222 { 223 if (propertiesMap.isEmpty()) { 224 QList<QVariant> argumentList; 225 QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); 226 reply.waitForFinished(); 227 if (!reply.isError()) { 228 propertiesMap = reply.value(); 229 } 230 } 231 return propertiesMap; 232 } 233 234 QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent) 235 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), 236 dbusPathName, 237 OFONO_DATA_CONNECTION_MANAGER_INTERFACE, 238 QDBusConnection::systemBus(), parent) 239 { 240 QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), 241 path(), 242 QLatin1String(OFONO_MODEM_INTERFACE), 243 QLatin1String("PropertyChanged"), 244 this,SLOT(propertyChanged(QString,QDBusVariant))); 245 } 246 247 QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface() 248 { 249 } 250 251 QStringList QOfonoDataConnectionManagerInterface::contexts() 252 { 253 if (contextList.isEmpty()) { 254 QDBusPendingReply<PathPropertiesList > reply = call(QLatin1String("GetContexts")); 255 reply.waitForFinished(); 256 if (!reply.isError()) { 257 foreach (ObjectPathProperties context, reply.value()) { 258 contextList << context.path.path(); 259 } 260 } 261 } 262 return contextList; 263 } 264 265 bool QOfonoDataConnectionManagerInterface::roamingAllowed() 266 { 267 QVariant var = getProperty(QStringLiteral("RoamingAllowed")); 268 return qdbus_cast<bool>(var); 269 } 270 271 QString QOfonoDataConnectionManagerInterface::bearer() 272 { 273 QVariant var = getProperty(QStringLiteral("Bearer")); 274 return qdbus_cast<QString>(var); 275 } 276 277 QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property) 278 { 279 QVariant var; 280 QVariantMap map = getProperties(); 281 if (map.contains(property)) 282 var = map.value(property); 283 return var; 284 } 285 286 QVariantMap QOfonoDataConnectionManagerInterface::getProperties() 287 { 288 if (propertiesMap.isEmpty()) { 289 QList<QVariant> argumentList; 290 QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); 291 if (!reply.isError()) { 292 propertiesMap = reply.value(); 293 } 294 } 295 return propertiesMap; 296 } 297 298 void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value) 299 { 300 propertiesMap[name] = value.variant(); 301 if (name == QLatin1String("RoamingAllowed")) 302 Q_EMIT roamingAllowedChanged(value.variant().toBool()); 303 } 304 305 306 QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent) 307 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), 308 dbusPathName, 309 OFONO_CONNECTION_CONTEXT_INTERFACE, 310 QDBusConnection::systemBus(), parent) 311 { 312 QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), 313 path(), 314 QLatin1String(OFONO_MODEM_INTERFACE), 315 QLatin1String("PropertyChanged"), 316 this,SLOT(propertyChanged(QString,QDBusVariant))); 317 } 318 319 QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface() 320 { 321 } 322 323 QVariantMap QOfonoConnectionContextInterface::getProperties() 324 { 325 if (propertiesMap.isEmpty()) { 326 QList<QVariant> argumentList; 327 QDBusPendingReply<QVariantMap> reply = callWithArgumentList(QDBus::Block, QLatin1String("GetProperties"), argumentList); 328 if (!reply.isError()) { 329 propertiesMap = reply.value(); 330 } 331 } 332 return propertiesMap; 333 } 334 335 void QOfonoConnectionContextInterface::propertyChanged(const QString &name, const QDBusVariant &value) 336 { 337 propertiesMap[name] = value.variant(); 338 } 339 340 QVariant QOfonoConnectionContextInterface::getProperty(const QString &property) 341 { 342 QVariant var; 343 QVariantMap map = getProperties(); 344 if (map.contains(property)) 345 var = map.value(property); 346 return var; 347 } 348 349 bool QOfonoConnectionContextInterface::active() 350 { 351 QVariant var = getProperty(QStringLiteral("Active")); 352 return qdbus_cast<bool>(var); 353 } 354 355 QString QOfonoConnectionContextInterface::accessPointName() 356 { 357 QVariant var = getProperty(QStringLiteral("AccessPointName")); 358 return qdbus_cast<QString>(var); 359 } 360 361 QString QOfonoConnectionContextInterface::name() 362 { 363 QVariant var = getProperty(QStringLiteral("Name")); 364 return qdbus_cast<QString>(var); 365 } 366 367 QT_END_NAMESPACE 368 369 #endif // QT_NO_DBUS 370 #endif // QT_NO_BEARERMANAGEMENT -
new file qtbase/src/plugins/bearer/linux_common/qofonoservice_linux_p.h
- + 1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 ** Contact: http://www.qt-project.org/legal 5 ** 6 ** This file is part of the plugins of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 ** use the contact form at http://qt.digia.com/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** In addition, as a special exception, Digia gives you certain additional 27 ** rights. These rights are described in the Digia Qt LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** $QT_END_LICENSE$ 31 ** 32 ****************************************************************************/ 33 34 #ifndef QOFONOSERVICE_H 35 #define QOFONOSERVICE_H 36 37 // 38 // W A R N I N G 39 // ------------- 40 // 41 // This file is not part of the Qt API. It exists purely as an 42 // implementation detail. This header file may change from version to 43 // version without notice, or even be removed. 44 // 45 // We mean it. 46 // 47 48 #include <QtDBus/QtDBus> 49 #include <QtDBus/QDBusConnection> 50 #include <QtDBus/QDBusError> 51 #include <QtDBus/QDBusInterface> 52 #include <QtDBus/QDBusMessage> 53 #include <QtDBus/QDBusReply> 54 55 #include <QtDBus/QDBusPendingCallWatcher> 56 #include <QtDBus/QDBusObjectPath> 57 #include <QtDBus/QDBusContext> 58 #include <QMap> 59 60 #ifndef QT_NO_BEARERMANAGEMENT 61 #ifndef QT_NO_DBUS 62 63 #define OFONO_SERVICE "org.ofono" 64 #define OFONO_MANAGER_INTERFACE "org.ofono.Manager" 65 #define OFONO_MANAGER_PATH "/" 66 67 #define OFONO_MODEM_INTERFACE "org.ofono.Modem" 68 #define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration" 69 #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager" 70 #define OFONO_CONNECTION_CONTEXT_INTERFACE "org.ofono.ConnectionContext" 71 72 QT_BEGIN_NAMESPACE 73 74 QT_END_NAMESPACE 75 76 struct ObjectPathProperties 77 { 78 QDBusObjectPath path; 79 QVariantMap properties; 80 }; 81 typedef QList<ObjectPathProperties> PathPropertiesList; 82 Q_DECLARE_METATYPE(ObjectPathProperties) 83 Q_DECLARE_METATYPE (PathPropertiesList) 84 85 QT_BEGIN_NAMESPACE 86 87 class QOfonoManagerInterface : public QDBusAbstractInterface 88 { 89 Q_OBJECT 90 91 public: 92 93 QOfonoManagerInterface( QObject *parent = 0); 94 ~QOfonoManagerInterface(); 95 96 QStringList getModems(); 97 QString currentModem(); 98 signals: 99 void modemChanged(); 100 private: 101 QStringList modemList; 102 private slots: 103 void modemAdded(const QDBusObjectPath &path, const QVariantMap &var); 104 void modemRemoved(const QDBusObjectPath &path); 105 }; 106 107 class QOfonoModemInterface : public QDBusAbstractInterface 108 { 109 Q_OBJECT 110 111 public: 112 113 explicit QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0); 114 ~QOfonoModemInterface(); 115 116 bool isPowered(); 117 bool isOnline(); 118 private: 119 QVariantMap getProperties(); 120 QVariantMap propertiesMap; 121 QVariant getProperty(const QString &); 122 void propertyChanged(const QString &, const QDBusVariant &value); 123 }; 124 125 126 class QOfonoNetworkRegistrationInterface : public QDBusAbstractInterface 127 { 128 Q_OBJECT 129 130 public: 131 132 explicit QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0); 133 ~QOfonoNetworkRegistrationInterface(); 134 135 QString getTechnology(); 136 137 private: 138 QVariantMap getProperties(); 139 QVariant getProperty(const QString &); 140 QVariantMap propertiesMap; 141 Q_SIGNALS: 142 void propertyChanged(const QString &, const QDBusVariant &value); 143 }; 144 145 class QOfonoDataConnectionManagerInterface : public QDBusAbstractInterface 146 { 147 Q_OBJECT 148 149 public: 150 151 explicit QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0); 152 ~QOfonoDataConnectionManagerInterface(); 153 154 QStringList contexts(); 155 bool roamingAllowed(); 156 QVariant getProperty(const QString &); 157 QString bearer(); 158 Q_SIGNALS: 159 void roamingAllowedChanged(bool); 160 private: 161 QVariantMap getProperties(); 162 QVariantMap propertiesMap; 163 QStringList contextList; 164 private slots: 165 void propertyChanged(const QString &, const QDBusVariant &value); 166 }; 167 168 class QOfonoConnectionContextInterface : public QDBusAbstractInterface 169 { 170 Q_OBJECT 171 172 public: 173 174 explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0); 175 ~QOfonoConnectionContextInterface(); 176 177 QVariant getProperty(const QString &); 178 bool active(); 179 QString accessPointName(); 180 QString name(); 181 182 Q_SIGNALS: 183 private: 184 QVariantMap getProperties(); 185 QVariantMap propertiesMap; 186 private slots: 187 void propertyChanged(const QString &, const QDBusVariant &value); 188 }; 189 190 QT_END_NAMESPACE 191 192 #endif // QT_NO_DBUS 193 #endif // QT_NO_BEARERMANAGEMENT 194 195 #endif //QOFONOSERVICE_H -
deleted file qtbase/src/plugins/bearer/connman/qofonoservice_linux.cpp
+ - 1 /****************************************************************************2 **3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).4 ** Contact: http://www.qt-project.org/legal5 **6 ** This file is part of the plugins of the Qt Toolkit.7 **8 ** $QT_BEGIN_LICENSE:LGPL$9 ** Commercial License Usage10 ** Licensees holding valid commercial Qt licenses may use this file in11 ** accordance with the commercial license agreement provided with the12 ** Software or, alternatively, in accordance with the terms contained in13 ** a written agreement between you and Digia. For licensing terms and14 ** conditions see http://qt.digia.com/licensing. For further information15 ** use the contact form at http://qt.digia.com/contact-us.16 **17 ** GNU Lesser General Public License Usage18 ** Alternatively, this file may be used under the terms of the GNU Lesser19 ** General Public License version 2.1 as published by the Free Software20 ** Foundation and appearing in the file LICENSE.LGPL included in the21 ** packaging of this file. Please review the following information to22 ** ensure the GNU Lesser General Public License version 2.1 requirements23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.24 **25 ** In addition, as a special exception, Digia gives you certain additional26 ** rights. These rights are described in the Digia Qt LGPL Exception27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.28 **29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 ** $QT_END_LICENSE$39 **40 ****************************************************************************/41 42 #include <QObject>43 #include <QList>44 #include <QtDBus/QtDBus>45 #include <QtDBus/QDBusConnection>46 #include <QtDBus/QDBusError>47 #include <QtDBus/QDBusInterface>48 #include <QtDBus/QDBusMessage>49 #include <QtDBus/QDBusReply>50 #include <QtDBus/QDBusPendingCallWatcher>51 #include <QtDBus/QDBusObjectPath>52 #include <QtDBus/QDBusPendingCall>53 54 #include "qofonoservice_linux_p.h"55 56 #ifndef QT_NO_BEARERMANAGEMENT57 #ifndef QT_NO_DBUS58 59 QDBusArgument &operator<<(QDBusArgument &argument, const ObjectPathProperties &item)60 {61 argument.beginStructure();62 argument << item.path << item.properties;63 argument.endStructure();64 return argument;65 }66 67 const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathProperties &item)68 {69 argument.beginStructure();70 argument >> item.path >> item.properties;71 argument.endStructure();72 return argument;73 }74 75 QT_BEGIN_NAMESPACE76 77 QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent)78 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),79 QStringLiteral(OFONO_MANAGER_PATH),80 OFONO_MANAGER_INTERFACE,81 QDBusConnection::systemBus(), parent)82 {83 qDBusRegisterMetaType<ObjectPathProperties>();84 qDBusRegisterMetaType<PathPropertiesList>();85 86 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),87 QStringLiteral(OFONO_MANAGER_PATH),88 QStringLiteral(OFONO_MANAGER_INTERFACE),89 QStringLiteral("ModemAdded"),90 this,SLOT(modemAdded(QDBusObjectPath, QVariantMap)));91 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),92 QStringLiteral(OFONO_MANAGER_PATH),93 QStringLiteral(OFONO_MANAGER_INTERFACE),94 QStringLiteral("ModemRemoved"),95 this,SLOT(modemRemoved(QDBusObjectPath)));96 }97 98 QOfonoManagerInterface::~QOfonoManagerInterface()99 {100 }101 102 QStringList QOfonoManagerInterface::getModems()103 {104 if (modemList.isEmpty()) {105 QList<QVariant> argumentList;106 QDBusPendingReply<PathPropertiesList> reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList);107 reply.waitForFinished();108 if (!reply.isError()) {109 foreach (ObjectPathProperties modem, reply.value()) {110 modemList << modem.path.path();111 }112 } else {113 qDebug() << reply.error().message();114 }115 }116 117 return modemList;118 }119 120 QString QOfonoManagerInterface::currentModem()121 {122 QStringList modems = getModems();123 foreach (const QString &modem, modems) {124 QOfonoModemInterface device(modem);125 if (device.isPowered() && device.isOnline())126 return modem;127 }128 return QString();129 }130 131 void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/)132 {133 if (!modemList.contains(path.path())) {134 modemList << path.path();135 Q_EMIT modemChanged();136 }137 }138 139 void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path)140 {141 if (modemList.contains(path.path())) {142 modemList.removeOne(path.path());143 Q_EMIT modemChanged();144 }145 }146 147 148 QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent)149 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),150 dbusPathName,151 OFONO_MODEM_INTERFACE,152 QDBusConnection::systemBus(), parent)153 {154 QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE),155 path(),156 OFONO_MODEM_INTERFACE,157 QStringLiteral("PropertyChanged"),158 this,SLOT(propertyChanged(QString,QDBusVariant)));159 }160 161 QOfonoModemInterface::~QOfonoModemInterface()162 {163 }164 165 void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value)166 {167 propertiesMap[name] = value.variant();168 }169 170 bool QOfonoModemInterface::isPowered()171 {172 QVariant var = getProperty(QStringLiteral("Powered"));173 return qdbus_cast<bool>(var);174 }175 176 bool QOfonoModemInterface::isOnline()177 {178 QVariant var = getProperty(QStringLiteral("Online"));179 return qdbus_cast<bool>(var);180 }181 182 QVariantMap QOfonoModemInterface::getProperties()183 {184 if (propertiesMap.isEmpty()) {185 QList<QVariant> argumentList;186 QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);187 if (!reply.isError()) {188 propertiesMap = reply.value();189 }190 }191 return propertiesMap;192 }193 194 QVariant QOfonoModemInterface::getProperty(const QString &property)195 {196 QVariant var;197 QVariantMap map = getProperties();198 var = map.value(property);199 return var;200 }201 202 203 QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent)204 : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE),205 dbusPathName,206 OFONO_NETWORK_REGISTRATION_INTERFACE,207 QDBusConnection::systemBus(), parent)208 {209 }210 211 QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface()212 {213 }214 215 QString QOfonoNetworkRegistrationInterface::getTechnology()216 {217 QVariant var = getProperty(QStringLiteral("Technology"));218 return qdbus_cast<QString>(var);219 }220 221 QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property)222 {223 QVariant var;224 QVariantMap map = getProperties();225 var = map.value(property);226 return var;227 }228 229 QVariantMap QOfonoNetworkRegistrationInterface::getProperties()230 {231 if (propertiesMap.isEmpty()) {232 QList<QVariant> argumentList;233 QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);234 reply.waitForFinished();235 if (!reply.isError()) {236 propertiesMap = reply.value();237 } else {238 qDebug() << reply.error().message();239 }240 }241 return propertiesMap;242 }243 244 QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent)245 : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE),246 dbusPathName,247 OFONO_DATA_CONNECTION_MANAGER_INTERFACE,248 QDBusConnection::systemBus(), parent)249 {250 QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE),251 path(),252 QLatin1String(OFONO_MODEM_INTERFACE),253 QLatin1String("PropertyChanged"),254 this,SLOT(propertyChanged(QString,QDBusVariant)));255 }256 257 QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface()258 {259 }260 261 QStringList QOfonoDataConnectionManagerInterface::contexts()262 {263 if (contextList.isEmpty()) {264 QDBusPendingReply<PathPropertiesList > reply = call(QLatin1String("GetContexts"));265 reply.waitForFinished();266 if (!reply.isError()) {267 foreach (ObjectPathProperties context, reply.value()) {268 contextList << context.path.path();269 }270 }271 }272 return contextList;273 }274 275 bool QOfonoDataConnectionManagerInterface::roamingAllowed()276 {277 QVariant var = getProperty(QStringLiteral("RoamingAllowed"));278 return qdbus_cast<bool>(var);279 }280 281 QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property)282 {283 QVariant var;284 QVariantMap map = getProperties();285 var = map.value(property);286 return var;287 }288 289 QVariantMap QOfonoDataConnectionManagerInterface::getProperties()290 {291 if (propertiesMap.isEmpty()) {292 QList<QVariant> argumentList;293 QDBusPendingReply<QVariantMap> reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList);294 if (!reply.isError()) {295 propertiesMap = reply.value();296 }297 }298 return propertiesMap;299 }300 301 void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value)302 {303 propertiesMap[name] = value.variant();304 if (name == QStringLiteral("RoamingAllowed"))305 Q_EMIT roamingAllowedChanged(value.variant().toBool());306 }307 308 QT_END_NAMESPACE309 310 #endif // QT_NO_DBUS311 #endif // QT_NO_BEARERMANAGEMENT -
deleted file qtbase/src/plugins/bearer/connman/qofonoservice_linux_p.h
+ - 1 /****************************************************************************2 **3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).4 ** Contact: http://www.qt-project.org/legal5 **6 ** This file is part of the plugins of the Qt Toolkit.7 **8 ** $QT_BEGIN_LICENSE:LGPL$9 ** Commercial License Usage10 ** Licensees holding valid commercial Qt licenses may use this file in11 ** accordance with the commercial license agreement provided with the12 ** Software or, alternatively, in accordance with the terms contained in13 ** a written agreement between you and Digia. For licensing terms and14 ** conditions see http://qt.digia.com/licensing. For further information15 ** use the contact form at http://qt.digia.com/contact-us.16 **17 ** GNU Lesser General Public License Usage18 ** Alternatively, this file may be used under the terms of the GNU Lesser19 ** General Public License version 2.1 as published by the Free Software20 ** Foundation and appearing in the file LICENSE.LGPL included in the21 ** packaging of this file. Please review the following information to22 ** ensure the GNU Lesser General Public License version 2.1 requirements23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.24 **25 ** In addition, as a special exception, Digia gives you certain additional26 ** rights. These rights are described in the Digia Qt LGPL Exception27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.28 **29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 ** $QT_END_LICENSE$39 **40 ****************************************************************************/41 42 #ifndef QOFONOSERVICE_H43 #define QOFONOSERVICE_H44 45 //46 // W A R N I N G47 // -------------48 //49 // This file is not part of the Qt API. It exists purely as an50 // implementation detail. This header file may change from version to51 // version without notice, or even be removed.52 //53 // We mean it.54 //55 56 #include <QtDBus/QtDBus>57 #include <QtDBus/QDBusConnection>58 #include <QtDBus/QDBusError>59 #include <QtDBus/QDBusInterface>60 #include <QtDBus/QDBusMessage>61 #include <QtDBus/QDBusReply>62 63 #include <QtDBus/QDBusPendingCallWatcher>64 #include <QtDBus/QDBusObjectPath>65 #include <QtDBus/QDBusContext>66 #include <QMap>67 68 #ifndef QT_NO_BEARERMANAGEMENT69 #ifndef QT_NO_DBUS70 71 #define OFONO_SERVICE "org.ofono"72 #define OFONO_MANAGER_INTERFACE "org.ofono.Manager"73 #define OFONO_MANAGER_PATH "/"74 75 #define OFONO_MODEM_INTERFACE "org.ofono.Modem"76 #define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration"77 #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager"78 79 QT_BEGIN_NAMESPACE80 81 QT_END_NAMESPACE82 83 struct ObjectPathProperties84 {85 QDBusObjectPath path;86 QVariantMap properties;87 };88 typedef QList<ObjectPathProperties> PathPropertiesList;89 Q_DECLARE_METATYPE(ObjectPathProperties)90 Q_DECLARE_METATYPE (PathPropertiesList)91 92 QT_BEGIN_NAMESPACE93 94 class QOfonoManagerInterface : public QDBusAbstractInterface95 {96 Q_OBJECT97 98 public:99 100 QOfonoManagerInterface( QObject *parent = 0);101 ~QOfonoManagerInterface();102 103 QStringList getModems();104 QString currentModem();105 signals:106 void modemChanged();107 private:108 QStringList modemList;109 private slots:110 void modemAdded(const QDBusObjectPath &path, const QVariantMap &var);111 void modemRemoved(const QDBusObjectPath &path);112 };113 114 class QOfonoModemInterface : public QDBusAbstractInterface115 {116 Q_OBJECT117 118 public:119 120 explicit QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0);121 ~QOfonoModemInterface();122 123 bool isPowered();124 bool isOnline();125 private:126 QVariantMap getProperties();127 QVariantMap propertiesMap;128 QVariant getProperty(const QString &);129 void propertyChanged(const QString &, const QDBusVariant &value);130 };131 132 133 class QOfonoNetworkRegistrationInterface : public QDBusAbstractInterface134 {135 Q_OBJECT136 137 public:138 139 explicit QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0);140 ~QOfonoNetworkRegistrationInterface();141 142 QString getTechnology();143 144 private:145 QVariantMap getProperties();146 QVariant getProperty(const QString &);147 QVariantMap propertiesMap;148 Q_SIGNALS:149 void propertyChanged(const QString &, const QDBusVariant &value);150 };151 152 class QOfonoDataConnectionManagerInterface : public QDBusAbstractInterface153 {154 Q_OBJECT155 156 public:157 158 explicit QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0);159 ~QOfonoDataConnectionManagerInterface();160 161 QStringList contexts();162 bool roamingAllowed();163 Q_SIGNALS:164 void roamingAllowedChanged(bool);165 private:166 QVariantMap getProperties();167 QVariantMap propertiesMap;168 QVariant getProperty(const QString &);169 QStringList contextList;170 private slots:171 void propertyChanged(const QString &, const QDBusVariant &value);172 };173 174 175 QT_END_NAMESPACE176 177 #endif // QT_NO_DBUS178 #endif // QT_NO_BEARERMANAGEMENT179 180 #endif //QOFONOSERVICE_H -
qtbase/src/plugins/bearer/networkmanager/main.cpp
1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 3Digia Plc and/or its subsidiary(-ies).3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 4 ** Contact: http://www.qt-project.org/legal 5 5 ** 6 6 ** This file is part of the plugins of the Qt Toolkit. 7 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL $8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 9 ** Commercial License Usage 10 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 11 ** accordance with the commercial license agreement provided with the 12 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. 14 ** conditions see http://qt.digia.com/licensing. 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 15 ** use the contact form at http://qt.digia.com/contact-us. 16 16 ** 17 17 ** GNU Lesser General Public License Usage 18 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 2.1 requirements 23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 25 ** 25 26 ** In addition, as a special exception, Digia gives you certain additional 26 ** rights. 27 ** rights. These rights are described in the Digia Qt LGPL Exception 27 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 29 ** 29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 30 ** $QT_END_LICENSE$ 39 31 ** 40 32 ****************************************************************************/ -
qtbase/src/plugins/bearer/networkmanager/networkmanager.pro
6 6 7 7 QT = core network-private dbus 8 8 9 HEADERS += qnmdbushelper.h \ 10 qnetworkmanagerservice.h \ 9 HEADERS += qnetworkmanagerservice.h \ 11 10 qnetworkmanagerengine.h \ 11 ../linux_common/qofonoservice_linux_p.h \ 12 12 ../qnetworksession_impl.h \ 13 13 ../qbearerengine_impl.h 14 14 15 15 SOURCES += main.cpp \ 16 qnmdbushelper.cpp \17 16 qnetworkmanagerservice.cpp \ 18 17 qnetworkmanagerengine.cpp \ 18 ../linux_common/qofonoservice_linux.cpp \ 19 19 ../qnetworksession_impl.cpp 20 20 21 21 OTHER_FILES += networkmanager.json -
qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp
1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 3Digia Plc and/or its subsidiary(-ies).3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 4 ** Contact: http://www.qt-project.org/legal 5 5 ** 6 6 ** This file is part of the plugins of the Qt Toolkit. 7 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL $8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 9 ** Commercial License Usage 10 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 11 ** accordance with the commercial license agreement provided with the 12 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. 14 ** conditions see http://qt.digia.com/licensing. 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 15 ** use the contact form at http://qt.digia.com/contact-us. 16 16 ** 17 17 ** GNU Lesser General Public License Usage 18 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 2.1 requirements 23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 25 ** 25 26 ** In addition, as a special exception, Digia gives you certain additional 26 ** rights. 27 ** rights. These rights are described in the Digia Qt LGPL Exception 27 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 29 ** 29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 30 ** $QT_END_LICENSE$ 39 31 ** 40 32 ****************************************************************************/ … … 55 47 #include <QDBusInterface> 56 48 #include <QDBusMessage> 57 49 #include <QDBusReply> 50 #include "../linux_common/qofonoservice_linux_p.h" 58 51 59 52 #ifndef QT_NO_BEARERMANAGEMENT 60 53 #ifndef QT_NO_DBUS … … 63 56 64 57 QNetworkManagerEngine::QNetworkManagerEngine(QObject *parent) 65 58 : QBearerEngineImpl(parent), 66 interface(new QNetworkManagerInterface(this)),67 systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE _SYSTEM_SETTINGS, this)),68 userSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE_USER_SETTINGS,this))59 managerInterface(new QNetworkManagerInterface(this)), 60 systemSettings(new QNetworkManagerSettings(NM_DBUS_SERVICE, this)), 61 ofonoManager(new QOfonoManagerInterface(this)) 69 62 { 70 if (!interface->isValid()) 63 64 if (!managerInterface->isValid()) 71 65 return; 72 66 73 interface->setConnections(); 74 connect(interface, SIGNAL(deviceAdded(QDBusObjectPath)), 67 qDBusRegisterMetaType<QNmSettingsMap>(); 68 69 connect(managerInterface, SIGNAL(deviceAdded(QDBusObjectPath)), 75 70 this, SLOT(deviceAdded(QDBusObjectPath))); 76 connect( interface, SIGNAL(deviceRemoved(QDBusObjectPath)),71 connect(managerInterface, SIGNAL(deviceRemoved(QDBusObjectPath)), 77 72 this, SLOT(deviceRemoved(QDBusObjectPath))); 78 #if 0 79 connect(interface, SIGNAL(stateChanged(QString,quint32)), 80 this, SIGNAL(configurationsChanged())); 81 #endif 82 connect(interface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), 73 connect(managerInterface, SIGNAL(activationFinished(QDBusPendingCallWatcher*)), 83 74 this, SLOT(activationFinished(QDBusPendingCallWatcher*))); 84 connect(interface, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), 85 this, SLOT(interfacePropertiesChanged(QString,QMap<QString,QVariant>))); 86 87 qDBusRegisterMetaType<QNmSettingsMap>(); 75 connect(managerInterface, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), 76 this, SLOT(interfacePropertiesChanged(QMap<QString,QVariant>))); 77 managerInterface->setConnections(); 88 78 89 systemSettings->setConnections();90 79 connect(systemSettings, SIGNAL(newConnection(QDBusObjectPath)), 91 80 this, SLOT(newConnection(QDBusObjectPath))); 92 93 userSettings->setConnections(); 94 connect(userSettings, SIGNAL(newConnection(QDBusObjectPath)), 95 this, SLOT(newConnection(QDBusObjectPath))); 81 systemSettings->setConnections(); 96 82 } 97 83 98 84 QNetworkManagerEngine::~QNetworkManagerEngine() 99 85 { 100 86 qDeleteAll(connections); 87 connections.clear(); 101 88 qDeleteAll(accessPoints); 89 accessPoints.clear(); 102 90 qDeleteAll(wirelessDevices); 103 qDeleteAll(activeConnections); 91 wirelessDevices.clear(); 92 qDeleteAll(activeConnectionsList); 93 activeConnectionsList.clear(); 94 qDeleteAll(interfaceDevices); 95 interfaceDevices.clear(); 96 97 connectionInterfaces.clear(); 98 99 qDeleteAll(ofonoContextManagers); 100 ofonoContextManagers.clear(); 101 102 qDeleteAll(wiredDevices); 103 wiredDevices.clear(); 104 104 } 105 105 106 106 void QNetworkManagerEngine::initialize() 107 107 { 108 108 QMutexLocker locker(&mutex); 109 109 110 // Get current list of access points. 111 foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { 110 if (ofonoManager->isValid()) { 111 Q_FOREACH (const QString &modem, ofonoManager->getModems()) { 112 QOfonoDataConnectionManagerInterface *ofonoContextManager 113 = new QOfonoDataConnectionManagerInterface(modem,this); 114 ofonoContextManagers.insert(modem, ofonoContextManager); 115 } 116 } 117 // Get active connections. 118 foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { 119 120 QNetworkManagerConnectionActive *activeConnection = 121 new QNetworkManagerConnectionActive(acPath.path(),this); 122 activeConnectionsList.insert(acPath.path(), activeConnection); 123 connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), 124 this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>))); 125 activeConnection->setConnections(); 126 127 QStringList devices = activeConnection->devices(); 128 if (!devices.isEmpty()) { 129 QNetworkManagerInterfaceDevice device(devices.at(0),this); 130 connectionInterfaces.insert(activeConnection->connection().path(),device.networkInterface()); 131 } 132 } 133 134 // Get current list of access points. 135 foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { 112 136 locker.unlock(); 113 deviceAdded(devicePath); 137 deviceAdded(devicePath); //add all accesspoints 114 138 locker.relock(); 115 139 } 116 140 117 141 // Get connections. 118 142 foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) { 119 143 locker.unlock(); 120 newConnection(settingsPath, systemSettings); 121 locker.relock(); 122 } 123 foreach (const QDBusObjectPath &settingsPath, userSettings->listConnections()) { 124 locker.unlock(); 125 newConnection(settingsPath, userSettings); 144 if (!hasIdentifier(settingsPath.path())) 145 newConnection(settingsPath, systemSettings); //add system connection configs 126 146 locker.relock(); 127 147 } 128 148 129 // Get active connections. 130 foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { 131 QNetworkManagerConnectionActive *activeConnection = 132 new QNetworkManagerConnectionActive(acPath.path()); 133 activeConnections.insert(acPath.path(), activeConnection); 134 135 activeConnection->setConnections(); 136 connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)), 137 this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>))); 138 } 149 Q_EMIT updateCompleted(); 139 150 } 140 151 141 152 bool QNetworkManagerEngine::networkManagerAvailable() const 142 153 { 143 QMutexLocker locker(&mutex); 144 145 return interface->isValid(); 154 return managerInterface->isValid(); 146 155 } 147 156 148 QString QNetworkManagerEngine::getInterfaceFromId(const QString & id)157 QString QNetworkManagerEngine::getInterfaceFromId(const QString &settingsPath) 149 158 { 150 QMutexLocker locker(&mutex); 151 152 foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { 153 QNetworkManagerConnectionActive activeConnection(acPath.path()); 154 155 const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + 156 activeConnection.connection().path())); 157 158 if (id == identifier) { 159 QList<QDBusObjectPath> devices = activeConnection.devices(); 160 161 if (devices.isEmpty()) 162 continue; 163 164 QNetworkManagerInterfaceDevice device(devices.at(0).path()); 165 return device.networkInterface(); 166 } 167 } 168 169 return QString(); 159 return connectionInterfaces.value(settingsPath); 170 160 } 171 161 172 162 bool QNetworkManagerEngine::hasIdentifier(const QString &id) 173 163 { 174 164 QMutexLocker locker(&mutex); 175 176 if (connectionFromId(id)) 177 return true; 178 179 for (int i = 0; i < accessPoints.count(); ++i) { 180 QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); 181 182 const QString identifier = 183 QString::number(qHash(accessPoint->connectionInterface()->path())); 184 185 if (id == identifier) 186 return true; 187 } 188 189 return false; 165 return accessPointConfigurations.contains(id); 190 166 } 191 167 192 168 void QNetworkManagerEngine::connectToId(const QString &id) … … 198 174 if (!connection) 199 175 return; 200 176 201 QNmSettingsMap map = connection->getSettings(); 202 const QString connectionType = map.value("connection").value("type").toString(); 177 NMDeviceType connectionType = connection->getType(); 203 178 204 179 QString dbusDevicePath; 205 foreach (const QDBusObjectPath &devicePath, interface->getDevices()) { 206 QNetworkManagerInterfaceDevice device(devicePath.path()); 207 if (device.deviceType() == DEVICE_TYPE_802_3_ETHERNET && 208 connectionType == QLatin1String("802-3-ethernet")) { 209 dbusDevicePath = devicePath.path(); 180 const QString settingsPath = connection->connectionInterface()->path(); 181 QString specificPath = configuredAccessPoints.key(settingsPath); 182 183 QHashIterator<QString, QNetworkManagerInterfaceDevice*> i(interfaceDevices); 184 while (i.hasNext()) { 185 i.next(); 186 if (i.value()->deviceType() == DEVICE_TYPE_ETHERNET && 187 connectionType == DEVICE_TYPE_ETHERNET) { 188 dbusDevicePath = i.key(); 210 189 break; 211 } else if ( device.deviceType() == DEVICE_TYPE_802_11_WIRELESS&&212 connectionType == QLatin1String("802-11-wireless")) {213 dbusDevicePath = devicePath.path();190 } else if (i.value()->deviceType() == DEVICE_TYPE_WIFI && 191 connectionType == DEVICE_TYPE_WIFI) { 192 dbusDevicePath = i.key(); 214 193 break; 215 } 216 else if (device.deviceType() == DEVICE_TYPE_GSM && 217 connectionType == QLatin1String("gsm")) { 218 dbusDevicePath = devicePath.path(); 194 } else if (i.value()->deviceType() == DEVICE_TYPE_MODEM && 195 connectionType == DEVICE_TYPE_MODEM) { 196 dbusDevicePath = i.key(); 219 197 break; 220 198 } 221 199 } 222 200 223 const QString service = connection->connectionInterface()->service();224 const QString settingsPath = connection->connectionInterface()->path();201 if (specificPath.isEmpty()) 202 specificPath = "/"; 225 203 226 interface->activateConnection(service,QDBusObjectPath(settingsPath),227 QDBusObjectPath(dbusDevicePath), QDBusObjectPath( "/"));204 managerInterface->activateConnection(QDBusObjectPath(settingsPath), 205 QDBusObjectPath(dbusDevicePath), QDBusObjectPath(specificPath)); 228 206 } 229 207 230 208 void QNetworkManagerEngine::disconnectFromId(const QString &id) 231 209 { 232 210 QMutexLocker locker(&mutex); 233 211 234 foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { 235 QNetworkManagerConnectionActive activeConnection(acPath.path()); 236 237 const QString identifier = QString::number(qHash(activeConnection.serviceName() + ' ' + 238 activeConnection.connection().path())); 212 QNetworkManagerSettingsConnection *connection = connectionFromId(id); 213 QNmSettingsMap map = connection->getSettings(); 214 bool connectionAutoconnect = map.value("connection").value("autoconnect",true).toBool(); //if not present is true !! 215 if (connectionAutoconnect) { //autoconnect connections will simply be reconnected by nm 216 emit connectionError(id, QBearerEngineImpl::OperationNotSupported); 217 return; 218 } 239 219 240 if (id == identifier && accessPointConfigurations.contains(id)) { 241 interface->deactivateConnection(acPath); 220 QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList); 221 while (i.hasNext()) { 222 i.next(); 223 if (id == i.value()->connection().path() && accessPointConfigurations.contains(id)) { 224 managerInterface->deactivateConnection(QDBusObjectPath(i.key())); 242 225 break; 243 226 } 244 227 } … … 246 229 247 230 void QNetworkManagerEngine::requestUpdate() 248 231 { 232 if (managerInterface->wirelessEnabled()) { 233 QHashIterator<QString, QNetworkManagerInterfaceDeviceWireless *> i(wirelessDevices); 234 while (i.hasNext()) { 235 i.next(); 236 i.value()->requestScan(); 237 } 238 } 249 239 QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection); 250 240 } 251 241 252 void QNetworkManagerEngine::interfacePropertiesChanged(const QString &path, 253 const QMap<QString, QVariant> &properties) 242 void QNetworkManagerEngine::scanFinished() 254 243 { 255 QMutexLocker locker(&mutex); 256 257 Q_UNUSED(path) 244 QMetaObject::invokeMethod(this, "updateCompleted", Qt::QueuedConnection); 245 } 258 246 247 void QNetworkManagerEngine::interfacePropertiesChanged(const QMap<QString, QVariant> &properties) 248 { 249 QMutexLocker locker(&mutex); 259 250 QMapIterator<QString, QVariant> i(properties); 260 251 while (i.hasNext()) { 261 252 i.next(); … … 267 258 qdbus_cast<QList<QDBusObjectPath> >(i.value().value<QDBusArgument>()); 268 259 269 260 QStringList identifiers = accessPointConfigurations.keys(); 270 foreach (const QString &id, identifiers) 271 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 272 273 QStringList priorActiveConnections = this->activeConnections.keys(); 261 QStringList priorActiveConnections = activeConnectionsList.keys(); 274 262 275 263 foreach (const QDBusObjectPath &acPath, activeConnections) { 276 264 priorActiveConnections.removeOne(acPath.path()); 277 265 QNetworkManagerConnectionActive *activeConnection = 278 this->activeConnections.value(acPath.path()); 266 activeConnectionsList.value(acPath.path()); 267 279 268 if (!activeConnection) { 280 activeConnection = new QNetworkManagerConnectionActive(acPath.path() );281 this->activeConnections.insert(acPath.path(), activeConnection);269 activeConnection = new QNetworkManagerConnectionActive(acPath.path(),this); 270 activeConnectionsList.insert(acPath.path(), activeConnection); 282 271 272 connect(activeConnection, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), 273 this, SLOT(activeConnectionPropertiesChanged(QMap<QString,QVariant>))); 283 274 activeConnection->setConnections(); 284 connect(activeConnection, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),285 this, SLOT(activeConnectionPropertiesChanged(QString,QMap<QString,QVariant>)));286 275 } 287 276 288 const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + 289 activeConnection->connection().path())); 277 const QString id = activeConnection->connection().path(); 290 278 291 279 identifiers.removeOne(id); 292 280 293 281 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 294 282 if (ptr) { 295 283 ptr->mutex.lock(); 296 if (activeConnection->state() == 2&&284 if (activeConnection->state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && 297 285 ptr->state != QNetworkConfiguration::Active) { 298 286 ptr->state = QNetworkConfiguration::Active; 287 288 if (activeConnectionsList.value(id) && activeConnectionsList.value(id)->defaultRoute() 289 && managerInterface->state() < QNetworkManagerInterface::NM_STATE_CONNECTED_GLOBAL) { 290 ptr->purpose = QNetworkConfiguration::PrivatePurpose; 291 } 299 292 ptr->mutex.unlock(); 300 293 301 294 locker.unlock(); … … 308 301 } 309 302 310 303 while (!priorActiveConnections.isEmpty()) 311 delete this->activeConnections.take(priorActiveConnections.takeFirst());304 delete activeConnectionsList.take(priorActiveConnections.takeFirst()); 312 305 313 306 while (!identifiers.isEmpty()) { 314 // These configurations are not active315 307 QNetworkConfigurationPrivatePointer ptr = 316 308 accessPointConfigurations.value(identifiers.takeFirst()); 317 309 318 310 ptr->mutex.lock(); 319 311 if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { 320 ptr->state = QNetworkConfiguration::Discovered; 312 QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; 313 ptr->state = (flag | QNetworkConfiguration::Discovered); 321 314 ptr->mutex.unlock(); 322 315 323 316 locker.unlock(); … … 331 324 } 332 325 } 333 326 334 void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QString &path, 335 const QMap<QString, QVariant> &properties) 327 void QNetworkManagerEngine::activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties) 336 328 { 337 329 QMutexLocker locker(&mutex); 338 330 339 331 Q_UNUSED(properties) 340 332 341 QNetworkManagerConnectionActive *activeConnection = activeConnections.value(path);333 QNetworkManagerConnectionActive *activeConnection = qobject_cast<QNetworkManagerConnectionActive *>(sender()); 342 334 343 335 if (!activeConnection) 344 336 return; 345 337 346 const QString id = QString::number(qHash(activeConnection->serviceName() + ' ' + 347 activeConnection->connection().path())); 338 const QString id = activeConnection->connection().path(); 348 339 349 340 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 350 341 if (ptr) { 351 342 ptr->mutex.lock(); 352 if (activeConnection->state() == 2 && 353 ptr->state != QNetworkConfiguration::Active) { 354 ptr->state = QNetworkConfiguration::Active; 343 if (properties.value("State").toUInt() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { 344 QStringList devices = activeConnection->devices(); 345 if (!devices.isEmpty()) { 346 QNetworkManagerInterfaceDevice device(devices.at(0),this); 347 connectionInterfaces.insert(id,device.networkInterface()); 348 } 349 350 ptr->state |= QNetworkConfiguration::Active; 355 351 ptr->mutex.unlock(); 356 352 357 353 locker.unlock(); 358 354 emit configurationChanged(ptr); 359 355 locker.relock(); 360 356 } else { 357 connectionInterfaces.remove(id); 361 358 ptr->mutex.unlock(); 362 359 } 363 360 } 364 361 } 365 362 366 void QNetworkManagerEngine::devicePropertiesChanged(const QString &path, 367 const QMap<QString, QVariant> &properties) 363 void QNetworkManagerEngine::deviceConnectionsChanged(const QStringList &connectionsList) 368 364 { 369 Q_UNUSED(path); 370 Q_UNUSED(properties); 365 QMutexLocker locker(&mutex); 366 for (int i = 0; i < connections.count(); ++i) { 367 if (connectionsList.contains(connections.at(i)->connectionInterface()->path())) 368 continue; 369 370 const QString settingsPath = connections.at(i)->connectionInterface()->path(); 371 372 QNetworkConfigurationPrivatePointer ptr = 373 accessPointConfigurations.value(settingsPath); 374 ptr->mutex.lock(); 375 QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; 376 ptr->state = (flag | QNetworkConfiguration::Discovered); 377 ptr->mutex.unlock(); 378 379 locker.unlock(); 380 emit configurationChanged(ptr); 381 locker.relock(); 382 Q_EMIT updateCompleted(); 383 } 371 384 } 372 385 373 386 void QNetworkManagerEngine::deviceAdded(const QDBusObjectPath &path) 374 387 { 375 QNetworkManagerInterfaceDevice device(path.path()); 376 if (device.deviceType() == DEVICE_TYPE_802_11_WIRELESS) { 388 QNetworkManagerInterfaceDevice *iDevice; 389 iDevice = new QNetworkManagerInterfaceDevice(path.path(),this); 390 connect(iDevice,SIGNAL(connectionsChanged(QStringList)), 391 this,SLOT(deviceConnectionsChanged(QStringList))); 392 393 iDevice->setConnections(); 394 interfaceDevices.insert(path.path(),iDevice); 395 if (iDevice->deviceType() == DEVICE_TYPE_WIFI) { 377 396 QNetworkManagerInterfaceDeviceWireless *wirelessDevice = 378 new QNetworkManagerInterfaceDeviceWireless( device.connectionInterface()->path());397 new QNetworkManagerInterfaceDeviceWireless(iDevice->connectionInterface()->path(),this); 379 398 399 connect(wirelessDevice, SIGNAL(accessPointAdded(QString)), 400 this, SLOT(newAccessPoint(QString))); 401 connect(wirelessDevice, SIGNAL(accessPointRemoved(QString)), 402 this, SLOT(removeAccessPoint(QString))); 403 connect(wirelessDevice,SIGNAL(scanDone()),this,SLOT(scanFinished())); 380 404 wirelessDevice->setConnections(); 381 connect(wirelessDevice, SIGNAL(accessPointAdded(QString,QDBusObjectPath)),382 this, SLOT(newAccessPoint(QString,QDBusObjectPath)));383 connect(wirelessDevice, SIGNAL(accessPointRemoved(QString,QDBusObjectPath)),384 this, SLOT(removeAccessPoint(QString,QDBusObjectPath)));385 connect(wirelessDevice, SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)),386 this, SLOT(devicePropertiesChanged(QString,QMap<QString,QVariant>)));387 405 388 406 foreach (const QDBusObjectPath &apPath, wirelessDevice->getAccessPoints()) 389 newAccessPoint( QString(), apPath);407 newAccessPoint(apPath.path()); 390 408 391 mutex.lock();392 409 wirelessDevices.insert(path.path(), wirelessDevice); 393 mutex.unlock(); 410 } 411 412 if (iDevice->deviceType() == DEVICE_TYPE_ETHERNET) { 413 QNetworkManagerInterfaceDeviceWired *wiredDevice = 414 new QNetworkManagerInterfaceDeviceWired(iDevice->connectionInterface()->path(),this); 415 connect(wiredDevice,SIGNAL(carrierChanged(bool)),this,SLOT(wiredCarrierChanged(bool))); 416 wiredDevices.insert(iDevice->connectionInterface()->path(), wiredDevice); 394 417 } 395 418 } 396 419 … … 398 421 { 399 422 QMutexLocker locker(&mutex); 400 423 401 delete wirelessDevices.take(path.path()); 424 if (interfaceDevices.contains(path.path())) { 425 locker.unlock(); 426 delete interfaceDevices.take(path.path()); 427 locker.relock(); 428 } 429 if (wirelessDevices.contains(path.path())) { 430 locker.unlock(); 431 delete wirelessDevices.take(path.path()); 432 locker.relock(); 433 } 434 if (wiredDevices.contains(path.path())) { 435 locker.unlock(); 436 delete wiredDevices.take(path.path()); 437 locker.relock(); 438 } 439 } 440 441 void QNetworkManagerEngine::wiredCarrierChanged(bool carrier) 442 { 443 QNetworkManagerInterfaceDeviceWired *deviceWired = qobject_cast<QNetworkManagerInterfaceDeviceWired *>(sender()); 444 if (!deviceWired) 445 return; 446 QMutexLocker locker(&mutex); 447 foreach (const QDBusObjectPath &settingsPath, systemSettings->listConnections()) { 448 for (int i = 0; i < connections.count(); ++i) { 449 QNetworkManagerSettingsConnection *connection = connections.at(i); 450 if (connection->getType() == DEVICE_TYPE_ETHERNET 451 && settingsPath.path() == connection->connectionInterface()->path()) { 452 QNetworkConfigurationPrivatePointer ptr = 453 accessPointConfigurations.value(settingsPath.path()); 454 455 if (ptr) { 456 ptr->mutex.lock(); 457 if (carrier) 458 ptr->state |= QNetworkConfiguration::Discovered; 459 else 460 ptr->state = QNetworkConfiguration::Defined; 461 ptr->mutex.unlock(); 462 locker.unlock(); 463 emit configurationChanged(ptr); 464 return; 465 } 466 } 467 } 468 } 402 469 } 403 470 404 471 void QNetworkManagerEngine::newConnection(const QDBusObjectPath &path, 405 472 QNetworkManagerSettings *settings) 406 473 { 407 474 QMutexLocker locker(&mutex); 408 409 475 if (!settings) 410 476 settings = qobject_cast<QNetworkManagerSettings *>(sender()); 411 477 412 if (!settings) 478 if (!settings) { 413 479 return; 480 } 414 481 415 482 QNetworkManagerSettingsConnection *connection = 416 483 new QNetworkManagerSettingsConnection(settings->connectionInterface()->service(), 417 path.path()); 484 path.path(),this); 485 const QString settingsPath = connection->connectionInterface()->path(); 486 if (accessPointConfigurations.contains(settingsPath)) { 487 return; 488 } 489 418 490 connections.append(connection); 419 491 420 connect(connection, SIGNAL(removed(QString)), this,SLOT(removeConnection(QString)));421 connect(connection, SIGNAL(updated(QNmSettingsMap)),422 this, SLOT(updateConnection(QNmSettingsMap)));492 connect(connection,SIGNAL(removed(QString)),this,SLOT(removeConnection(QString))); 493 connect(connection,SIGNAL(updated()),this,SLOT(updateConnection())); 494 connection->setConnections(); 423 495 424 const QString service = connection->connectionInterface()->service(); 425 const QString settingsPath = connection->connectionInterface()->path(); 496 NMDeviceType deviceType = connection->getType(); 497 498 if (deviceType == DEVICE_TYPE_WIFI) { 499 QString apPath; 500 for (int i = 0; i < accessPoints.count(); ++i) { 501 if (connection->getSsid() == accessPoints.at(i)->ssid()) { 502 // remove the corresponding accesspoint from configurations 503 apPath = accessPoints.at(i)->connectionInterface()->path(); 504 QNetworkConfigurationPrivatePointer ptr 505 = accessPointConfigurations.take(apPath); 506 if (ptr) { 507 locker.unlock(); 508 emit configurationRemoved(ptr); 509 locker.relock(); 510 } 511 } 512 } 513 if (!configuredAccessPoints.contains(settingsPath)) 514 configuredAccessPoints.insert(apPath,settingsPath); 515 } 426 516 427 517 QNetworkConfigurationPrivate *cpPriv = 428 parseConnection(se rvice, settingsPath, connection->getSettings());518 parseConnection(settingsPath, connection->getSettings()); 429 519 430 520 // Check if connection is active. 431 foreach (const QDBusObjectPath &acPath, interface->activeConnections()) { 432 QNetworkManagerConnectionActive activeConnection(acPath.path()); 433 434 if (activeConnection.serviceName() == service && 435 activeConnection.connection().path() == settingsPath && 436 activeConnection.state() == 2) { 521 QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList); 522 while (i.hasNext()) { 523 i.next(); 524 if (i.value()->connection().path() == settingsPath) { 437 525 cpPriv->state |= QNetworkConfiguration::Active; 438 526 break; 439 527 } 440 528 } 441 529 if (deviceType == DEVICE_TYPE_ETHERNET) { 530 QHashIterator<QString, QNetworkManagerInterfaceDevice*> i(interfaceDevices); 531 while (i.hasNext()) { 532 i.next(); 533 if (i.value()->deviceType() == deviceType) { 534 QNetworkManagerInterfaceDeviceWired *wiredDevice 535 = wiredDevices.value(i.value()->connectionInterface()->path()); 536 if (wiredDevice->carrier()) { 537 cpPriv->state |= QNetworkConfiguration::Discovered; 538 } 539 } 540 } 541 } 442 542 QNetworkConfigurationPrivatePointer ptr(cpPriv); 443 543 accessPointConfigurations.insert(ptr->id, ptr); 444 445 544 locker.unlock(); 446 545 emit configurationAdded(ptr); 447 546 } … … 450 549 { 451 550 QMutexLocker locker(&mutex); 452 551 453 Q_UNUSED(path)454 455 552 QNetworkManagerSettingsConnection *connection = 456 553 qobject_cast<QNetworkManagerSettingsConnection *>(sender()); 554 457 555 if (!connection) 458 556 return; 459 557 558 connection->deleteLater(); 460 559 connections.removeAll(connection); 461 560 462 const QString id = QString::number(qHash(connection->connectionInterface()->service() + ' ' + 463 connection->connectionInterface()->path())); 561 const QString id = path; 464 562 465 563 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); 466 564 467 connection->deleteLater(); 468 469 locker.unlock(); 470 emit configurationRemoved(ptr); 565 if (ptr) { 566 locker.unlock(); 567 emit configurationRemoved(ptr); 568 locker.relock(); 569 } 570 // add base AP back into configurations 571 QMapIterator<QString, QString> i(configuredAccessPoints); 572 while (i.hasNext()) { 573 i.next(); 574 if (i.value() == path) { 575 configuredAccessPoints.remove(i.key()); 576 newAccessPoint(i.key()); 577 } 578 } 471 579 } 472 580 473 void QNetworkManagerEngine::updateConnection( const QNmSettingsMap &settings)581 void QNetworkManagerEngine::updateConnection() 474 582 { 475 583 QMutexLocker locker(&mutex); 476 584 … … 478 586 qobject_cast<QNetworkManagerSettingsConnection *>(sender()); 479 587 if (!connection) 480 588 return; 481 482 const QString service = connection->connectionInterface()->service();483 589 const QString settingsPath = connection->connectionInterface()->path(); 484 590 485 QNetworkConfigurationPrivate *cpPriv = parseConnection(se rvice, settingsPath, settings);591 QNetworkConfigurationPrivate *cpPriv = parseConnection(settingsPath, connection->getSettings()); 486 592 487 593 // Check if connection is active. 488 foreach (const QDBusObjectPath &acPath, interface->activeConnections()) {594 foreach (const QDBusObjectPath &acPath, managerInterface->activeConnections()) { 489 595 QNetworkManagerConnectionActive activeConnection(acPath.path()); 490 596 491 if (activeConnection.serviceName() == service && 492 activeConnection.connection().path() == settingsPath && 597 if (activeConnection.connection().path() == settingsPath && 493 598 activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { 494 599 cpPriv->state |= QNetworkConfiguration::Active; 495 600 break; … … 509 614 510 615 locker.unlock(); 511 616 emit configurationChanged(ptr); 617 locker.relock(); 512 618 delete cpPriv; 513 619 } 514 620 515 621 void QNetworkManagerEngine::activationFinished(QDBusPendingCallWatcher *watcher) 516 622 { 517 623 QMutexLocker locker(&mutex); 518 519 624 QDBusPendingReply<QDBusObjectPath> reply(*watcher); 625 watcher->deleteLater(); 626 520 627 if (!reply.isError()) { 521 628 QDBusObjectPath result = reply.value(); 522 629 523 630 QNetworkManagerConnectionActive activeConnection(result.path()); 524 631 525 const QString id = QString::number(qHash(activeConnection.serviceName() + ' ' + 526 activeConnection.connection().path())); 632 const QString id = activeConnection.connection().path(); 527 633 528 634 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 529 635 if (ptr) { 530 636 ptr->mutex.lock(); 531 if (activeConnection.state() == 2&&637 if (activeConnection.state() == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && 532 638 ptr->state != QNetworkConfiguration::Active) { 533 ptr->state = QNetworkConfiguration::Active;639 ptr->state |= QNetworkConfiguration::Active; 534 640 ptr->mutex.unlock(); 535 641 536 642 locker.unlock(); … … 543 649 } 544 650 } 545 651 546 void QNetworkManagerEngine::newAccessPoint(const QString &path , const QDBusObjectPath &objectPath)652 void QNetworkManagerEngine::newAccessPoint(const QString &path) 547 653 { 548 654 QMutexLocker locker(&mutex); 549 655 550 Q_UNUSED(path)551 552 656 QNetworkManagerInterfaceAccessPoint *accessPoint = 553 new QNetworkManagerInterfaceAccessPoint(objectPath.path()); 554 accessPoints.append(accessPoint); 657 new QNetworkManagerInterfaceAccessPoint(path,this); 555 658 556 accessPoint->setConnections(); 557 connect(accessPoint, SIGNAL(propertiesChanged(QMap<QString,QVariant>)), 558 this, SLOT(updateAccessPoint(QMap<QString,QVariant>))); 559 560 // Check if configuration for this SSID already exists. 659 bool okToAdd = true; 561 660 for (int i = 0; i < accessPoints.count(); ++i) { 562 if (accessPoint != accessPoints.at(i) && 563 accessPoint->ssid() == accessPoints.at(i)->ssid()) { 564 return; 661 if (accessPoints.at(i)->connectionInterface()->path() == path) { 662 okToAdd = false; 565 663 } 566 664 } 567 665 if (okToAdd) { 666 accessPoints.append(accessPoint); 667 accessPoint->setConnections(); 668 } 568 669 // Check if configuration exists for connection. 569 670 if (!accessPoint->ssid().isEmpty()) { 671 570 672 for (int i = 0; i < connections.count(); ++i) { 571 673 QNetworkManagerSettingsConnection *connection = connections.at(i); 674 const QString settingsPath = connection->connectionInterface()->path(); 572 675 573 676 if (accessPoint->ssid() == connection->getSsid()) { 574 const QString service = connection->connectionInterface()->service();575 const QString settingsPath = connection->connectionInterface()->path();576 const QString connectionId = QString::number(qHash(service + ' ' + settingsPath));677 if (!configuredAccessPoints.contains(path)) { 678 configuredAccessPoints.insert(path,settingsPath); 679 } 577 680 578 681 QNetworkConfigurationPrivatePointer ptr = 579 accessPointConfigurations.value( connectionId);682 accessPointConfigurations.value(settingsPath); 580 683 ptr->mutex.lock(); 581 ptr->state = QNetworkConfiguration::Discovered; 684 QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; 685 ptr->state = (flag | QNetworkConfiguration::Discovered); 582 686 ptr->mutex.unlock(); 583 687 584 688 locker.unlock(); … … 593 697 594 698 ptr->name = accessPoint->ssid(); 595 699 ptr->isValid = true; 596 ptr->id = QString::number(qHash(objectPath.path()));700 ptr->id = path; 597 701 ptr->type = QNetworkConfiguration::InternetAccessPoint; 598 if(accessPoint->flags() == NM_802_11_AP_FLAGS_PRIVACY) { 599 ptr->purpose = QNetworkConfiguration::PrivatePurpose; 600 } else { 601 ptr->purpose = QNetworkConfiguration::PublicPurpose; 602 } 702 ptr->purpose = QNetworkConfiguration::PublicPurpose; 603 703 ptr->state = QNetworkConfiguration::Undefined; 604 704 ptr->bearerType = QNetworkConfiguration::BearerWLAN; 605 705 … … 609 709 emit configurationAdded(ptr); 610 710 } 611 711 612 void QNetworkManagerEngine::removeAccessPoint(const QString &path, 613 const QDBusObjectPath &objectPath) 712 void QNetworkManagerEngine::removeAccessPoint(const QString &path) 614 713 { 615 714 QMutexLocker locker(&mutex); 616 617 Q_UNUSED(path)618 619 715 for (int i = 0; i < accessPoints.count(); ++i) { 620 716 QNetworkManagerInterfaceAccessPoint *accessPoint = accessPoints.at(i); 621 622 if (accessPoint->connectionInterface()->path() == objectPath.path()) { 717 if (accessPoint->connectionInterface()->path() == path) { 623 718 accessPoints.removeOne(accessPoint); 624 719 625 if (configuredAccessPoints.contains(accessPoint )) {720 if (configuredAccessPoints.contains(accessPoint->connectionInterface()->path())) { 626 721 // find connection and change state to Defined 627 configuredAccessPoints.removeOne(accessPoint); 722 configuredAccessPoints.remove(accessPoint->connectionInterface()->path()); 723 628 724 for (int i = 0; i < connections.count(); ++i) { 629 725 QNetworkManagerSettingsConnection *connection = connections.at(i); 630 726 631 if (accessPoint->ssid() == connection->getSsid()) { 632 const QString service = connection->connectionInterface()->service(); 727 if (accessPoint->ssid() == connection->getSsid()) {//might not have bssid yet 633 728 const QString settingsPath = connection->connectionInterface()->path(); 634 const QString connectionId = 635 QString::number(qHash(service + ' ' + settingsPath)); 729 const QString connectionId = settingsPath; 636 730 637 731 QNetworkConfigurationPrivatePointer ptr = 638 732 accessPointConfigurations.value(connectionId); … … 648 742 } 649 743 } else { 650 744 QNetworkConfigurationPrivatePointer ptr = 651 accessPointConfigurations.take( QString::number(qHash(objectPath.path())));745 accessPointConfigurations.take(path); 652 746 653 747 if (ptr) { 654 748 locker.unlock(); … … 656 750 locker.relock(); 657 751 } 658 752 } 659 660 753 delete accessPoint; 661 662 754 break; 663 755 } 664 756 } 665 757 } 666 758 667 void QNetworkManagerEngine::updateAccessPoint(const QMap<QString, QVariant> &map) 668 { 669 QMutexLocker locker(&mutex); 670 671 Q_UNUSED(map) 672 673 QNetworkManagerInterfaceAccessPoint *accessPoint = 674 qobject_cast<QNetworkManagerInterfaceAccessPoint *>(sender()); 675 if (!accessPoint) 676 return; 677 678 for (int i = 0; i < connections.count(); ++i) { 679 QNetworkManagerSettingsConnection *connection = connections.at(i); 680 681 if (accessPoint->ssid() == connection->getSsid()) { 682 const QString service = connection->connectionInterface()->service(); 683 const QString settingsPath = connection->connectionInterface()->path(); 684 const QString connectionId = QString::number(qHash(service + ' ' + settingsPath)); 685 686 QNetworkConfigurationPrivatePointer ptr = 687 accessPointConfigurations.value(connectionId); 688 ptr->mutex.lock(); 689 ptr->state = QNetworkConfiguration::Discovered; 690 ptr->mutex.unlock(); 691 692 locker.unlock(); 693 emit configurationChanged(ptr); 694 return; 695 } 696 } 697 } 698 699 QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &service, 700 const QString &settingsPath, 759 QNetworkConfigurationPrivate *QNetworkManagerEngine::parseConnection(const QString &settingsPath, 701 760 const QNmSettingsMap &map) 702 761 { 762 QMutexLocker locker(&mutex); 703 763 QNetworkConfigurationPrivate *cpPriv = new QNetworkConfigurationPrivate; 704 764 cpPriv->name = map.value("connection").value("id").toString(); 765 705 766 cpPriv->isValid = true; 706 cpPriv->id = QString::number(qHash(service + ' ' + settingsPath));767 cpPriv->id = settingsPath; 707 768 cpPriv->type = QNetworkConfiguration::InternetAccessPoint; 708 769 709 770 cpPriv->purpose = QNetworkConfiguration::PublicPurpose; 710 771 711 772 cpPriv->state = QNetworkConfiguration::Defined; 712 713 773 const QString connectionType = map.value("connection").value("type").toString(); 714 774 715 775 if (connectionType == QLatin1String("802-3-ethernet")) { 716 776 cpPriv->bearerType = QNetworkConfiguration::BearerEthernet; 717 cpPriv->purpose = QNetworkConfiguration::PublicPurpose;718 777 719 foreach (const QDBusObjectPath &devicePath, interface->getDevices()) {720 QNetworkManagerInterfaceDevice device(devicePath.path() );721 if (device.deviceType() == DEVICE_TYPE_ 802_3_ETHERNET) {722 QNetworkManagerInterfaceDeviceWired wiredDevice(device.connectionInterface()->path());723 if (wiredDevice .carrier()) {778 foreach (const QDBusObjectPath &devicePath, managerInterface->getDevices()) { 779 QNetworkManagerInterfaceDevice device(devicePath.path(),this); 780 if (device.deviceType() == DEVICE_TYPE_ETHERNET) { 781 QNetworkManagerInterfaceDeviceWired *wiredDevice = wiredDevices.value(device.connectionInterface()->path()); 782 if (wiredDevice->carrier()) { 724 783 cpPriv->state |= QNetworkConfiguration::Discovered; 725 784 break; 726 785 } 727 728 786 } 729 787 } 730 788 } else if (connectionType == QLatin1String("802-11-wireless")) { 731 789 cpPriv->bearerType = QNetworkConfiguration::BearerWLAN; 732 790 733 791 const QString connectionSsid = map.value("802-11-wireless").value("ssid").toString(); 734 const QString connectionSecurity = map.value("802-11-wireless").value("security").toString();735 if(!connectionSecurity.isEmpty()) {736 cpPriv->purpose = QNetworkConfiguration::PrivatePurpose;737 } else {738 cpPriv->purpose = QNetworkConfiguration::PublicPurpose;739 }740 792 for (int i = 0; i < accessPoints.count(); ++i) { 741 if (connectionSsid == accessPoints.at(i)->ssid()) { 793 if (connectionSsid == accessPoints.at(i)->ssid() 794 && map.value("802-11-wireless").value("seen-bssids").toStringList().contains(accessPoints.at(i)->hwAddress())) { 742 795 cpPriv->state |= QNetworkConfiguration::Discovered; 743 if (!configuredAccessPoints.contains(accessPoints.at(i) )) {744 configuredAccessPoints. append(accessPoints.at(i));796 if (!configuredAccessPoints.contains(accessPoints.at(i)->connectionInterface()->path())) { 797 configuredAccessPoints.insert(accessPoints.at(i)->connectionInterface()->path(),settingsPath); 745 798 746 const QString accessPointId = 747 QString::number(qHash(accessPoints.at(i)->connectionInterface()->path())); 799 const QString accessPointId = accessPoints.at(i)->connectionInterface()->path(); 748 800 QNetworkConfigurationPrivatePointer ptr = 749 801 accessPointConfigurations.take(accessPointId); 750 802 751 803 if (ptr) { 752 mutex.unlock();804 locker.unlock(); 753 805 emit configurationRemoved(ptr); 754 mutex.lock();806 locker.relock(); 755 807 } 756 808 } 757 809 break; 758 810 } 759 811 } 760 } else if (connectionType == "gsm") { 761 cpPriv->bearerType = QNetworkConfiguration::Bearer2G; 762 } else if (connectionType == "cdma") { 763 cpPriv->bearerType = QNetworkConfiguration::BearerCDMA2000; 812 } else if (connectionType == QLatin1String("gsm")) { 813 814 const QString contextPath = map.value("connection").value("id").toString(); 815 cpPriv->name = contextName(contextPath); 816 cpPriv->bearerType = currentBearerType(contextPath); 817 818 if (map.value("connection").contains("timestamp")) { 819 cpPriv->state |= QNetworkConfiguration::Discovered; 820 } 764 821 } 765 822 766 823 return cpPriv; … … 770 827 { 771 828 for (int i = 0; i < connections.count(); ++i) { 772 829 QNetworkManagerSettingsConnection *connection = connections.at(i); 773 const QString service = connection->connectionInterface()->service(); 774 const QString settingsPath = connection->connectionInterface()->path(); 775 776 const QString identifier = QString::number(qHash(service + ' ' + settingsPath)); 777 778 if (id == identifier) 830 if (id == connection->connectionInterface()->path()) 779 831 return connection; 780 832 } 781 833 … … 785 837 QNetworkSession::State QNetworkManagerEngine::sessionStateForId(const QString &id) 786 838 { 787 839 QMutexLocker locker(&mutex); 788 789 840 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 790 841 791 842 if (!ptr) … … 794 845 if (!ptr->isValid) 795 846 return QNetworkSession::Invalid; 796 847 797 foreach (const QString &acPath, activeConnections .keys()) {798 QNetworkManagerConnectionActive *activeConnection = activeConnections .value(acPath);848 foreach (const QString &acPath, activeConnectionsList.keys()) { 849 QNetworkManagerConnectionActive *activeConnection = activeConnectionsList.value(acPath); 799 850 800 const QString identifier = QString::number(qHash(activeConnection->serviceName() + ' ' + 801 activeConnection->connection().path())); 851 const QString identifier = activeConnection->connection().path(); 802 852 803 853 if (id == identifier) { 804 854 switch (activeConnection->state()) { … … 828 878 829 879 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 830 880 if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { 831 const QString networkInterface = getInterfaceFromId(id);881 const QString networkInterface = connectionInterfaces.value(id); 832 882 if (!networkInterface.isEmpty()) { 833 883 const QString devFile = QLatin1String("/sys/class/net/") + 834 884 networkInterface + … … 856 906 857 907 QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); 858 908 if (ptr && (ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { 859 const QString networkInterface = getInterfaceFromId(id);909 const QString networkInterface = connectionInterfaces.value(id); 860 910 if (!networkInterface.isEmpty()) { 861 911 const QString devFile = QLatin1String("/sys/class/net/") + 862 912 networkInterface + … … 892 942 QNetworkConfigurationManager::Capabilities QNetworkManagerEngine::capabilities() const 893 943 { 894 944 return QNetworkConfigurationManager::ForcedRoaming | 895 QNetworkConfigurationManager::CanStartAndStopInterfaces; 945 QNetworkConfigurationManager::DataStatistics | 946 QNetworkConfigurationManager::CanStartAndStopInterfaces; 896 947 } 897 948 898 949 QNetworkSessionPrivate *QNetworkManagerEngine::createSessionBackend() … … 902 953 903 954 QNetworkConfigurationPrivatePointer QNetworkManagerEngine::defaultConfiguration() 904 955 { 956 QHashIterator<QString, QNetworkManagerConnectionActive*> i(activeConnectionsList); 957 while (i.hasNext()) { 958 i.next(); 959 QNetworkManagerConnectionActive *activeConnection = i.value(); 960 if ((activeConnection->defaultRoute() || activeConnection->default6Route())) { 961 return accessPointConfigurations.value(activeConnection->connection().path()); 962 } 963 } 964 905 965 return QNetworkConfigurationPrivatePointer(); 906 966 } 907 967 968 QNetworkConfiguration::BearerType QNetworkManagerEngine::currentBearerType(const QString &id) 969 { 970 if (ofonoManager->isValid()) { 971 QString contextPart = id.section('/', -1); 972 973 QHashIterator<QString, QOfonoDataConnectionManagerInterface*> i(ofonoContextManagers); 974 while (i.hasNext()) { 975 i.next(); 976 QString contextPath = i.key() +"/"+contextPart; 977 if (i.value()->contexts().contains(contextPath)) { 978 979 QString bearer = i.value()->bearer(); 980 if (bearer == QStringLiteral("gsm")) { 981 return QNetworkConfiguration::Bearer2G; 982 } else if (bearer == QStringLiteral("edge")) { 983 return QNetworkConfiguration::Bearer2G; 984 } else if (bearer == QStringLiteral("umts")) { 985 return QNetworkConfiguration::BearerWCDMA; 986 } else if (bearer == QStringLiteral("hspa") 987 || bearer == QStringLiteral("hsdpa") 988 || bearer == QStringLiteral("hsupa")) { 989 return QNetworkConfiguration::BearerHSPA; 990 } else if (bearer == QStringLiteral("lte")) { 991 return QNetworkConfiguration::BearerLTE; 992 } 993 } 994 } 995 } 996 return QNetworkConfiguration::BearerUnknown; 997 } 998 999 QString QNetworkManagerEngine::contextName(const QString &path) 1000 { 1001 if (ofonoManager->isValid()) { 1002 QString contextPart = path.section('/', -1); 1003 QHashIterator<QString, QOfonoDataConnectionManagerInterface*> i(ofonoContextManagers); 1004 while (i.hasNext()) { 1005 i.next(); 1006 Q_FOREACH (const QString &oContext, i.value()->contexts()) { 1007 if (oContext.contains(contextPart)) { 1008 QOfonoConnectionContextInterface contextInterface(oContext,this); 1009 return contextInterface.name(); 1010 } 1011 } 1012 } 1013 } 1014 return path; 1015 } 1016 908 1017 QT_END_NAMESPACE 909 1018 910 1019 #endif // QT_NO_DBUS -
qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerengine.h
1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 3Digia Plc and/or its subsidiary(-ies).3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 4 ** Contact: http://www.qt-project.org/legal 5 5 ** 6 6 ** This file is part of the plugins of the Qt Toolkit. 7 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL $8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 9 ** Commercial License Usage 10 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 11 ** accordance with the commercial license agreement provided with the 12 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. 14 ** conditions see http://qt.digia.com/licensing. 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 15 ** use the contact form at http://qt.digia.com/contact-us. 16 16 ** 17 17 ** GNU Lesser General Public License Usage 18 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 2.1 requirements 23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 25 ** 25 26 ** In addition, as a special exception, Digia gives you certain additional 26 ** rights. 27 ** rights. These rights are described in the Digia Qt LGPL Exception 27 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 29 ** 29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 30 ** $QT_END_LICENSE$ 39 31 ** 40 32 ****************************************************************************/ … … 57 49 58 50 #include "qnetworkmanagerservice.h" 59 51 52 #include "../linux_common/qofonoservice_linux_p.h" 53 60 54 #include <QMap> 61 55 #include <QVariant> 62 56 … … 97 91 QNetworkConfigurationPrivatePointer defaultConfiguration(); 98 92 99 93 private Q_SLOTS: 100 void interfacePropertiesChanged(const QString &path, 101 const QMap<QString, QVariant> &properties); 102 void activeConnectionPropertiesChanged(const QString &path, 103 const QMap<QString, QVariant> &properties); 104 void devicePropertiesChanged(const QString &path, 105 const QMap<QString, QVariant> &properties); 94 void interfacePropertiesChanged(const QMap<QString, QVariant> &properties); 95 void activeConnectionPropertiesChanged(const QMap<QString, QVariant> &properties); 106 96 107 97 void deviceAdded(const QDBusObjectPath &path); 108 98 void deviceRemoved(const QDBusObjectPath &path); 109 99 110 100 void newConnection(const QDBusObjectPath &path, QNetworkManagerSettings *settings = 0); 111 101 void removeConnection(const QString &path); 112 void updateConnection( const QNmSettingsMap &settings);102 void updateConnection(); 113 103 void activationFinished(QDBusPendingCallWatcher *watcher); 104 void deviceConnectionsChanged(const QStringList &activeConnectionsList); 114 105 115 void newAccessPoint(const QString &path, const QDBusObjectPath &objectPath); 116 void removeAccessPoint(const QString &path, const QDBusObjectPath &objectPath); 117 void updateAccessPoint(const QMap<QString, QVariant> &map); 106 void newAccessPoint(const QString &path); 107 void removeAccessPoint(const QString &path); 108 void scanFinished(); 109 110 void wiredCarrierChanged(bool); 118 111 119 112 private: 120 QNetworkConfigurationPrivate *parseConnection(const QString &service, 121 const QString &settingsPath, 113 QNetworkConfigurationPrivate *parseConnection(const QString &settingsPath, 122 114 const QNmSettingsMap &map); 123 115 QNetworkManagerSettingsConnection *connectionFromId(const QString &id) const; 124 116 125 private: 126 QNetworkManagerInterface *interface; 117 QNetworkManagerInterface *managerInterface; 127 118 QNetworkManagerSettings *systemSettings; 128 Q NetworkManagerSettings *userSettings;119 QHash<QString, QNetworkManagerInterfaceDeviceWired *> wiredDevices; 129 120 QHash<QString, QNetworkManagerInterfaceDeviceWireless *> wirelessDevices; 130 QHash<QString, QNetworkManagerConnectionActive *> activeConnections; 121 122 QHash<QString, QNetworkManagerConnectionActive *> activeConnectionsList; 131 123 QList<QNetworkManagerSettingsConnection *> connections; 132 124 QList<QNetworkManagerInterfaceAccessPoint *> accessPoints; 133 QList<QNetworkManagerInterfaceAccessPoint *> configuredAccessPoints; 125 QHash<QString, QNetworkManagerInterfaceDevice *> interfaceDevices; 126 127 QMap<QString,QString> configuredAccessPoints; //ap, settings path 128 QHash<QString,QString> connectionInterfaces; // ac, interface 129 130 QOfonoManagerInterface *ofonoManager; 131 QHash <QString, QOfonoDataConnectionManagerInterface *> ofonoContextManagers; 132 QNetworkConfiguration::BearerType currentBearerType(const QString &id); 133 QString contextName(const QString &path); 134 134 135 }; 135 136 136 137 QT_END_NAMESPACE -
qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp
1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 3Digia Plc and/or its subsidiary(-ies).3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 4 ** Contact: http://www.qt-project.org/legal 5 5 ** 6 6 ** This file is part of the plugins of the Qt Toolkit. 7 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL $8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 9 ** Commercial License Usage 10 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 11 ** accordance with the commercial license agreement provided with the 12 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. 14 ** conditions see http://qt.digia.com/licensing. 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 15 ** use the contact form at http://qt.digia.com/contact-us. 16 16 ** 17 17 ** GNU Lesser General Public License Usage 18 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 2.1 requirements 23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 25 ** 25 26 ** In addition, as a special exception, Digia gives you certain additional 26 ** rights. 27 ** rights. These rights are described in the Digia Qt LGPL Exception 27 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 29 ** 29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 30 ** $QT_END_LICENSE$ 39 31 ** 40 32 ****************************************************************************/ … … 52 44 #include <QtDBus/QDBusPendingCall> 53 45 54 46 #include "qnetworkmanagerservice.h" 55 #include "qnmdbushelper.h"56 47 57 48 #ifndef QT_NO_DBUS 58 49 … … 72 63 d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), 73 64 QLatin1String(NM_DBUS_PATH), 74 65 QLatin1String(NM_DBUS_INTERFACE), 75 QDBusConnection::systemBus() );66 QDBusConnection::systemBus(),parent); 76 67 if (!d->connectionInterface->isValid()) { 77 68 d->valid = false; 78 69 return; 79 70 } 80 71 d->valid = true; 81 nmDBusHelper = new QNmDBusHelper(this);82 connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)),83 this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>)));84 connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)),85 this, SIGNAL(stateChanged(QString,quint32)));86 72 73 QDBusInterface managerPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 74 QLatin1String(NM_DBUS_PATH), 75 QLatin1String("org.freedesktop.DBus.Properties"), 76 QDBusConnection::systemBus()); 77 QList<QVariant> argumentList; 78 argumentList << QLatin1String(NM_DBUS_INTERFACE); 79 QDBusPendingReply<QVariantMap> propsReply 80 = managerPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 81 argumentList); 82 if (!propsReply.isError()) { 83 propertyMap = propsReply.value(); 84 } 85 86 QDBusPendingReply<QList <QDBusObjectPath> > nmReply 87 = d->connectionInterface->call(QLatin1String("GetDevices")); 88 nmReply.waitForFinished(); 89 if (!nmReply.isError()) { 90 devicesPathList = nmReply.value(); 91 } 92 93 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 94 QLatin1String(NM_DBUS_PATH), 95 QLatin1String(NM_DBUS_INTERFACE), 96 QLatin1String("PropertiesChanged"), 97 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 87 98 } 88 99 89 100 QNetworkManagerInterface::~QNetworkManagerInterface() … … 99 110 100 111 bool QNetworkManagerInterface::setConnections() 101 112 { 102 if (!isValid())113 if (!isValid()) 103 114 return false; 104 115 105 QDBusConnection dbusConnection = QDBusConnection::systemBus(); 106 107 bool allOk = false; 108 if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 116 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 109 117 QLatin1String(NM_DBUS_PATH), 110 118 QLatin1String(NM_DBUS_INTERFACE), 111 119 QLatin1String("PropertiesChanged"), 112 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>)))) {113 allOk = true; 114 }115 if ( !dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),120 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 121 122 bool allOk = false; 123 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 116 124 QLatin1String(NM_DBUS_PATH), 117 125 QLatin1String(NM_DBUS_INTERFACE), 118 126 QLatin1String("DeviceAdded"), 119 127 this,SIGNAL(deviceAdded(QDBusObjectPath)))) { 120 128 allOk = true; 121 129 } 122 if ( !dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),130 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 123 131 QLatin1String(NM_DBUS_PATH), 124 132 QLatin1String(NM_DBUS_INTERFACE), 125 133 QLatin1String("DeviceRemoved"), … … 135 143 return d->connectionInterface; 136 144 } 137 145 138 QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const146 QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() 139 147 { 140 QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices")); 141 return reply.value(); 148 if (devicesPathList.isEmpty()) { 149 qWarning() << "using blocking call!"; 150 QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices")); 151 devicesPathList = reply.value(); 152 } 153 return devicesPathList; 142 154 } 143 155 144 void QNetworkManagerInterface::activateConnection( const QString &serviceName, 145 QDBusObjectPath connectionPath, 156 void QNetworkManagerInterface::activateConnection(QDBusObjectPath connectionPath, 146 157 QDBusObjectPath devicePath, 147 158 QDBusObjectPath specificObject) 148 159 { 149 160 QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"), 150 QVariant(serviceName),151 161 QVariant::fromValue(connectionPath), 152 162 QVariant::fromValue(devicePath), 153 163 QVariant::fromValue(specificObject)); 154 164 155 QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall , this);165 QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(pendingCall); 156 166 connect(callWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), 157 167 this, SIGNAL(activationFinished(QDBusPendingCallWatcher*))); 158 168 } 159 169 160 170 void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const 161 171 { 162 d->connectionInterface-> call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath));172 d->connectionInterface->asyncCall(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); 163 173 } 164 174 165 175 bool QNetworkManagerInterface::wirelessEnabled() const 166 176 { 167 return d->connectionInterface->property("WirelessEnabled").toBool(); 177 if (propertyMap.contains("WirelessEnabled")) 178 return propertyMap.value("WirelessEnabled").toBool(); 179 return false; 168 180 } 169 181 170 182 bool QNetworkManagerInterface::wirelessHardwareEnabled() const 171 183 { 172 return d->connectionInterface->property("WirelessHardwareEnabled").toBool(); 184 if (propertyMap.contains("WirelessHardwareEnabled")) 185 return propertyMap.value("WirelessHardwareEnabled").toBool(); 186 return false; 173 187 } 174 188 175 189 QList <QDBusObjectPath> QNetworkManagerInterface::activeConnections() const 176 190 { 177 QVariant prop = d->connectionInterface->property("ActiveConnections"); 178 return prop.value<QList<QDBusObjectPath> >(); 191 if (propertyMap.contains("ActiveConnections")) { 192 193 const QDBusArgument &dbusArgs = propertyMap.value("ActiveConnections").value<QDBusArgument>(); 194 QDBusObjectPath path; 195 QList <QDBusObjectPath> list; 196 197 dbusArgs.beginArray(); 198 while (!dbusArgs.atEnd()) { 199 dbusArgs >> path; 200 list.append(path); 201 } 202 dbusArgs.endArray(); 203 204 return list; 205 } 206 207 QList <QDBusObjectPath> list; 208 list << QDBusObjectPath(); 209 return list; 179 210 } 180 211 181 quint32QNetworkManagerInterface::state()212 QNetworkManagerInterface::NMState QNetworkManagerInterface::state() 182 213 { 183 return d->connectionInterface->property("State").toUInt(); 214 if (propertyMap.contains("State")) 215 return static_cast<QNetworkManagerInterface::NMState>(propertyMap.value("State").toUInt()); 216 return QNetworkManagerInterface::NM_STATE_UNKNOWN; 217 } 218 219 QString QNetworkManagerInterface::version() const 220 { 221 if (propertyMap.contains("Version")) 222 return propertyMap.value("Version").toString(); 223 return QString(); 224 } 225 226 void QNetworkManagerInterface::propertiesSwap(QMap<QString,QVariant> map) 227 { 228 QMapIterator<QString, QVariant> i(map); 229 while (i.hasNext()) { 230 i.next(); 231 propertyMap.insert(i.key(),i.value()); 232 233 if (i.key() == QStringLiteral("State")) { 234 quint32 state = i.value().toUInt(); 235 if (state == NM_DEVICE_STATE_ACTIVATED 236 || state == NM_DEVICE_STATE_DISCONNECTED 237 || state == NM_DEVICE_STATE_UNAVAILABLE 238 || state == NM_DEVICE_STATE_FAILED) { 239 Q_EMIT propertiesChanged(map); 240 Q_EMIT stateChanged(state); 241 } 242 } else if (i.key() == QStringLiteral("ActiveConnections")) { 243 Q_EMIT propertiesChanged(map); 244 } 245 } 184 246 } 185 247 186 248 class QNetworkManagerInterfaceAccessPointPrivate … … 192 254 }; 193 255 194 256 QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent) 195 : QObject(parent) , nmDBusHelper(0)257 : QObject(parent) 196 258 { 197 259 d = new QNetworkManagerInterfaceAccessPointPrivate(); 198 260 d->path = dbusPathName; 199 261 d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), 200 262 d->path, 201 263 QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), 202 QDBusConnection::systemBus() );264 QDBusConnection::systemBus(),parent); 203 265 if (!d->connectionInterface->isValid()) { 204 266 d->valid = false; 205 267 return; 206 268 } 269 QDBusInterface accessPointPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 270 d->path, 271 QLatin1String("org.freedesktop.DBus.Properties"), 272 QDBusConnection::systemBus()); 273 274 QList<QVariant> argumentList; 275 argumentList << QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT); 276 QDBusPendingReply<QVariantMap> propsReply 277 = accessPointPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 278 argumentList); 279 if (!propsReply.isError()) { 280 propertyMap = propsReply.value(); 281 } 282 283 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 284 d->path, 285 QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), 286 QLatin1String("PropertiesChanged"), 287 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 288 207 289 d->valid = true; 208 290 209 291 } … … 221 303 222 304 bool QNetworkManagerInterfaceAccessPoint::setConnections() 223 305 { 224 if (!isValid())306 if (!isValid()) 225 307 return false; 226 308 227 bool allOk = false; 228 delete nmDBusHelper; 229 nmDBusHelper = new QNmDBusHelper(this); 230 connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), 231 this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); 232 233 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 234 d->path, 235 QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), 236 QLatin1String("PropertiesChanged"), 237 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) ) { 238 allOk = true; 239 240 } 241 return allOk; 309 return true; 242 310 } 243 311 244 312 QDBusInterface *QNetworkManagerInterfaceAccessPoint::connectionInterface() const … … 248 316 249 317 quint32 QNetworkManagerInterfaceAccessPoint::flags() const 250 318 { 251 return d->connectionInterface->property("Flags").toUInt(); 319 if (propertyMap.contains("Flags")) 320 return propertyMap.value("Flags").toUInt(); 321 return 0; 252 322 } 253 323 254 324 quint32 QNetworkManagerInterfaceAccessPoint::wpaFlags() const 255 325 { 256 return d->connectionInterface->property("WpaFlags").toUInt(); 326 if (propertyMap.contains("WpaFlags")) 327 return propertyMap.value("WpaFlags").toUInt(); 328 return 0; 257 329 } 258 330 259 331 quint32 QNetworkManagerInterfaceAccessPoint::rsnFlags() const 260 332 { 261 return d->connectionInterface->property("RsnFlags").toUInt(); 333 if (propertyMap.contains("RsnFlags")) 334 return propertyMap.value("RsnFlags").toUInt(); 335 return 0; 262 336 } 263 337 264 338 QString QNetworkManagerInterfaceAccessPoint::ssid() const 265 339 { 266 return d->connectionInterface->property("Ssid").toString(); 340 if (propertyMap.contains("Ssid")) 341 return propertyMap.value("Ssid").toString(); 342 return QString(); 267 343 } 268 344 269 345 quint32 QNetworkManagerInterfaceAccessPoint::frequency() const 270 346 { 271 return d->connectionInterface->property("Frequency").toUInt(); 347 if (propertyMap.contains("Frequency")) 348 return propertyMap.value("Frequency").toUInt(); 349 return 0; 272 350 } 273 351 274 352 QString QNetworkManagerInterfaceAccessPoint::hwAddress() const 275 353 { 276 return d->connectionInterface->property("HwAddress").toString(); 354 if (propertyMap.contains("HwAddress")) 355 return propertyMap.value("HwAddress").toString(); 356 return QString(); 277 357 } 278 358 279 359 quint32 QNetworkManagerInterfaceAccessPoint::mode() const 280 360 { 281 return d->connectionInterface->property("Mode").toUInt(); 361 if (propertyMap.contains("Mode")) 362 return propertyMap.value("Mode").toUInt(); 363 return 0; 282 364 } 283 365 284 366 quint32 QNetworkManagerInterfaceAccessPoint::maxBitrate() const 285 367 { 286 return d->connectionInterface->property("MaxBitrate").toUInt(); 368 if (propertyMap.contains("MaxBitrate")) 369 return propertyMap.value("MaxBitrate").toUInt(); 370 return 0; 287 371 } 288 372 289 373 quint32 QNetworkManagerInterfaceAccessPoint::strength() const 290 374 { 291 return d->connectionInterface->property("Strength").toUInt(); 375 if (propertyMap.contains("Strength")) 376 return propertyMap.value("Strength").toUInt(); 377 return 0; 378 } 379 380 void QNetworkManagerInterfaceAccessPoint::propertiesSwap(QMap<QString,QVariant> map) 381 { 382 QMapIterator<QString, QVariant> i(map); 383 while (i.hasNext()) { 384 i.next(); 385 propertyMap.insert(i.key(),i.value()); 386 } 292 387 } 293 388 294 389 class QNetworkManagerInterfaceDevicePrivate … … 300 395 }; 301 396 302 397 QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent) 303 : QObject(parent) , nmDBusHelper(0)398 : QObject(parent) 304 399 { 400 305 401 d = new QNetworkManagerInterfaceDevicePrivate(); 306 402 d->path = deviceObjectPath; 307 403 d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), 308 404 d->path, 309 405 QLatin1String(NM_DBUS_INTERFACE_DEVICE), 310 QDBusConnection::systemBus() );406 QDBusConnection::systemBus(),parent); 311 407 if (!d->connectionInterface->isValid()) { 312 408 d->valid = false; 313 409 return; 314 410 } 411 QDBusInterface devicePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 412 d->path, 413 QLatin1String("org.freedesktop.DBus.Properties"), 414 QDBusConnection::systemBus(),parent); 415 416 QList<QVariant> argumentList; 417 argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE); 418 QDBusPendingReply<QVariantMap> propsReply 419 = devicePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 420 argumentList); 421 422 if (!propsReply.isError()) { 423 propertyMap = propsReply.value(); 424 } 425 426 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 427 d->path, 428 QLatin1String(NM_DBUS_INTERFACE_DEVICE), 429 QLatin1String("PropertiesChanged"), 430 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 315 431 d->valid = true; 316 432 } 317 433 … … 328 444 329 445 bool QNetworkManagerInterfaceDevice::setConnections() 330 446 { 331 if (!isValid())447 if (!isValid()) 332 448 return false; 333 449 334 bool allOk = false; 335 delete nmDBusHelper; 336 nmDBusHelper = new QNmDBusHelper(this); 337 connect(nmDBusHelper,SIGNAL(pathForStateChanged(QString,quint32)), 338 this, SIGNAL(stateChanged(QString,quint32))); 339 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 340 d->path, 341 QLatin1String(NM_DBUS_INTERFACE_DEVICE), 342 QLatin1String("StateChanged"), 343 nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { 344 allOk = true; 345 } 346 return allOk; 450 return true; 347 451 } 348 452 349 453 QDBusInterface *QNetworkManagerInterfaceDevice::connectionInterface() const … … 353 457 354 458 QString QNetworkManagerInterfaceDevice::udi() const 355 459 { 356 return d->connectionInterface->property("Udi").toString(); 460 if (propertyMap.contains("Udi")) 461 return propertyMap.value("Udi").toString(); 462 return QString(); 357 463 } 358 464 359 465 QString QNetworkManagerInterfaceDevice::networkInterface() const 360 466 { 361 return d->connectionInterface->property("Interface").toString(); 467 if (propertyMap.contains("Interface")) 468 return propertyMap.value("Interface").toString(); 469 return QString(); 362 470 } 363 471 364 472 quint32 QNetworkManagerInterfaceDevice::ip4Address() const 365 473 { 366 return d->connectionInterface->property("Ip4Address").toUInt(); 474 if (propertyMap.contains("Ip4Address")) 475 return propertyMap.value("Ip4Address").toUInt(); 476 return 0; 367 477 } 368 478 369 479 quint32 QNetworkManagerInterfaceDevice::state() const 370 480 { 371 return d->connectionInterface->property("State").toUInt(); 481 if (propertyMap.contains("State")) 482 return propertyMap.value("State").toUInt(); 483 return 0; 372 484 } 373 485 374 486 quint32 QNetworkManagerInterfaceDevice::deviceType() const 375 487 { 376 return d->connectionInterface->property("DeviceType").toUInt(); 488 if (propertyMap.contains("DeviceType")) 489 return propertyMap.value("DeviceType").toUInt(); 490 return 0; 377 491 } 378 492 379 493 QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const 380 494 { 381 QVariant prop = d->connectionInterface->property("Ip4Config"); 382 return prop.value<QDBusObjectPath>(); 495 if (propertyMap.contains("Ip4Config")) 496 return propertyMap.value("Ip4Config").value<QDBusObjectPath>(); 497 return QDBusObjectPath(); 498 } 499 500 void QNetworkManagerInterfaceDevice::propertiesSwap(QMap<QString,QVariant> map) 501 { 502 QMapIterator<QString, QVariant> i(map); 503 while (i.hasNext()) { 504 i.next(); 505 if (i.key() == QStringLiteral("AvailableConnections")) { //Device 506 const QDBusArgument &dbusArgs = i.value().value<QDBusArgument>(); 507 QDBusObjectPath path; 508 QStringList paths; 509 dbusArgs.beginArray(); 510 while (!dbusArgs.atEnd()) { 511 dbusArgs >> path; 512 paths << path.path(); 513 } 514 dbusArgs.endArray(); 515 Q_EMIT connectionsChanged(paths); 516 } 517 propertyMap.insert(i.key(),i.value()); 518 } 519 Q_EMIT propertiesChanged(map); 383 520 } 384 521 385 522 class QNetworkManagerInterfaceDeviceWiredPrivate … … 391 528 }; 392 529 393 530 QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath, QObject *parent) 394 : QObject(parent) , nmDBusHelper(0)531 : QObject(parent) 395 532 { 396 533 d = new QNetworkManagerInterfaceDeviceWiredPrivate(); 397 534 d->path = ifaceDevicePath; … … 403 540 d->valid = false; 404 541 return; 405 542 } 543 QDBusInterface deviceWiredPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 544 d->path, 545 QLatin1String("org.freedesktop.DBus.Properties"), 546 QDBusConnection::systemBus(),parent); 547 548 QList<QVariant> argumentList; 549 argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED); 550 QDBusPendingReply<QVariantMap> propsReply 551 = deviceWiredPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 552 argumentList); 553 554 if (!propsReply.isError()) { 555 propertyMap = propsReply.value(); 556 } 557 558 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 559 d->path, 560 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), 561 QLatin1String("PropertiesChanged"), 562 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 563 406 564 d->valid = true; 407 565 } 408 566 … … 420 578 421 579 bool QNetworkManagerInterfaceDeviceWired::setConnections() 422 580 { 423 if (!isValid())581 if (!isValid()) 424 582 return false; 425 426 bool allOk = false; 427 428 delete nmDBusHelper; 429 nmDBusHelper = new QNmDBusHelper(this); 430 connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), 431 this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); 432 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 433 d->path, 434 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), 435 QLatin1String("PropertiesChanged"), 436 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) ) { 437 allOk = true; 438 } 439 return allOk; 583 return true; 440 584 } 441 585 442 586 QDBusInterface *QNetworkManagerInterfaceDeviceWired::connectionInterface() const … … 446 590 447 591 QString QNetworkManagerInterfaceDeviceWired::hwAddress() const 448 592 { 449 return d->connectionInterface->property("HwAddress").toString(); 593 if (propertyMap.contains("HwAddress")) 594 return propertyMap.value("HwAddress").toString(); 595 return QString(); 450 596 } 451 597 452 598 quint32 QNetworkManagerInterfaceDeviceWired::speed() const 453 599 { 454 return d->connectionInterface->property("Speed").toUInt(); 600 if (propertyMap.contains("Speed")) 601 return propertyMap.value("Speed").toUInt(); 602 return 0; 455 603 } 456 604 457 605 bool QNetworkManagerInterfaceDeviceWired::carrier() const 458 606 { 459 return d->connectionInterface->property("Carrier").toBool(); 607 if (propertyMap.contains("Carrier")) 608 return propertyMap.value("Carrier").toBool(); 609 return false; 610 } 611 612 QStringList QNetworkManagerInterfaceDeviceWired::availableConnections() 613 { 614 QStringList list; 615 if (propertyMap.contains("AvailableConnections")) { 616 const QDBusArgument &dbusArgs = propertyMap.value("Carrier").value<QDBusArgument>(); 617 QDBusObjectPath path; 618 dbusArgs.beginArray(); 619 while (!dbusArgs.atEnd()) { 620 dbusArgs >> path; 621 list << path.path(); 622 } 623 dbusArgs.endArray(); 624 } 625 626 return list; 627 } 628 629 void QNetworkManagerInterfaceDeviceWired::propertiesSwap(QMap<QString,QVariant> map) 630 { 631 QMapIterator<QString, QVariant> i(map); 632 while (i.hasNext()) { 633 i.next(); 634 propertyMap.insert(i.key(),i.value()); 635 if (i.key() == QStringLiteral("Carrier")) { 636 Q_EMIT carrierChanged(i.value().toBool()); 637 } 638 } 639 Q_EMIT propertiesChanged(map); 460 640 } 461 641 462 642 class QNetworkManagerInterfaceDeviceWirelessPrivate … … 468 648 }; 469 649 470 650 QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath, QObject *parent) 471 : QObject(parent) , nmDBusHelper(0)651 : QObject(parent) 472 652 { 473 653 d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); 474 654 d->path = ifaceDevicePath; … … 480 660 d->valid = false; 481 661 return; 482 662 } 663 664 665 QDBusPendingReply<QList <QDBusObjectPath> > nmReply 666 = d->connectionInterface->call(QLatin1String("GetAccessPoints")); 667 668 if (!nmReply.isError()) { 669 accessPointsList = nmReply.value(); 670 } 671 672 QDBusInterface deviceWirelessPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 673 d->path, 674 QLatin1String("org.freedesktop.DBus.Properties"), 675 QDBusConnection::systemBus(),parent); 676 677 QList<QVariant> argumentList; 678 argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS); 679 QDBusPendingReply<QVariantMap> propsReply 680 = deviceWirelessPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 681 argumentList); 682 if (!propsReply.isError()) { 683 propertyMap = propsReply.value(); 684 } 685 686 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 687 d->path, 688 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), 689 QLatin1String("PropertiesChanged"), 690 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 483 691 d->valid = true; 484 692 } 485 693 … … 494 702 return d->valid; 495 703 } 496 704 705 void QNetworkManagerInterfaceDeviceWireless::slotAccessPointAdded(QDBusObjectPath path) 706 { 707 if (path.path().length() > 2) 708 Q_EMIT accessPointAdded(path.path()); 709 } 710 711 void QNetworkManagerInterfaceDeviceWireless::slotAccessPointRemoved(QDBusObjectPath path) 712 { 713 if (path.path().length() > 2) 714 Q_EMIT accessPointRemoved(path.path()); 715 } 716 497 717 bool QNetworkManagerInterfaceDeviceWireless::setConnections() 498 718 { 499 if (!isValid())719 if (!isValid()) 500 720 return false; 501 721 502 722 QDBusConnection dbusConnection = QDBusConnection::systemBus(); 503 bool allOk = false; 504 delete nmDBusHelper; 505 nmDBusHelper = new QNmDBusHelper(this); 506 connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), 507 this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); 723 bool allOk = true; 508 724 509 connect(nmDBusHelper, SIGNAL(pathForAccessPointAdded(QString,QDBusObjectPath)), 510 this,SIGNAL(accessPointAdded(QString,QDBusObjectPath))); 511 512 connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(QString,QDBusObjectPath)), 513 this,SIGNAL(accessPointRemoved(QString,QDBusObjectPath))); 514 515 if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 516 d->path, 725 if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 726 d->path, 517 727 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), 518 728 QLatin1String("AccessPointAdded"), 519 nmDBusHelper, SLOT(slotAccessPointAdded(QDBusObjectPath)))) {520 allOk = true;729 this, SLOT(slotAccessPointAdded(QDBusObjectPath)))) { 730 allOk = false; 521 731 } 522 732 523 733 524 if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE),734 if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 525 735 d->path, 526 736 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), 527 737 QLatin1String("AccessPointRemoved"), 528 nmDBusHelper, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) {529 allOk = true;738 this, SLOT(slotAccessPointRemoved(QDBusObjectPath)))) { 739 allOk = false; 530 740 } 531 741 532 533 if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 534 d->path, 535 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), 536 QLatin1String("PropertiesChanged"), 537 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>)))) { 538 allOk = true; 742 if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), 743 d->path, 744 QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), 745 QLatin1String("ScanDone"), 746 this, SLOT(scanIsDone()))) { 747 allOk = false; 539 748 } 540 541 749 return allOk; 542 750 } 543 751 … … 548 756 549 757 QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints() 550 758 { 551 QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints")); 552 return reply.value(); 759 if (accessPointsList.isEmpty()) { 760 qWarning() << "Using blocking call!"; 761 QDBusReply<QList<QDBusObjectPath> > reply 762 = d->connectionInterface->call(QLatin1String("GetAccessPoints")); 763 accessPointsList = reply.value(); 764 } 765 return accessPointsList; 553 766 } 554 767 555 768 QString QNetworkManagerInterfaceDeviceWireless::hwAddress() const 556 769 { 557 return d->connectionInterface->property("HwAddress").toString(); 770 if (propertyMap.contains("HwAddress")) 771 return propertyMap.value("HwAddress").toString(); 772 return QString(); 558 773 } 559 774 560 775 quint32 QNetworkManagerInterfaceDeviceWireless::mode() const 561 776 { 562 return d->connectionInterface->property("Mode").toUInt(); 777 if (propertyMap.contains("Mode")) 778 return propertyMap.value("Mode").toUInt(); 779 return 0; 563 780 } 564 781 565 782 quint32 QNetworkManagerInterfaceDeviceWireless::bitrate() const 566 783 { 567 return d->connectionInterface->property("Bitrate").toUInt(); 784 if (propertyMap.contains("Bitrate")) 785 return propertyMap.value("Bitrate").toUInt(); 786 return 0; 568 787 } 569 788 570 789 QDBusObjectPath QNetworkManagerInterfaceDeviceWireless::activeAccessPoint() const 571 790 { 572 return d->connectionInterface->property("ActiveAccessPoint").value<QDBusObjectPath>(); 791 if (propertyMap.contains("ActiveAccessPoint")) 792 return propertyMap.value("ActiveAccessPoint").value<QDBusObjectPath>(); 793 return QDBusObjectPath(); 573 794 } 574 795 575 796 quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const 576 797 { 577 return d->connectionInterface->property("WirelelessCapabilities").toUInt(); 798 if (propertyMap.contains("WirelelessCapabilities")) 799 return propertyMap.value("WirelelessCapabilities").toUInt(); 800 return 0; 801 } 802 803 void QNetworkManagerInterfaceDeviceWireless::scanIsDone() 804 { 805 Q_EMIT scanDone(); 806 } 807 808 void QNetworkManagerInterfaceDeviceWireless::requestScan() 809 { 810 d->connectionInterface->asyncCall(QLatin1String("RequestScan")); 811 } 812 813 void QNetworkManagerInterfaceDeviceWireless::propertiesSwap(QMap<QString,QVariant> map) 814 { 815 QMapIterator<QString, QVariant> i(map); 816 while (i.hasNext()) { 817 i.next(); 818 propertyMap.insert(i.key(),i.value()); 819 if (i.key() == QStringLiteral("ActiveAccessPoint")) { //DeviceWireless 820 Q_EMIT propertiesChanged(map); 821 } 822 } 823 } 824 825 class QNetworkManagerInterfaceDeviceModemPrivate 826 { 827 public: 828 QDBusInterface *connectionInterface; 829 QString path; 830 bool valid; 831 }; 832 833 QNetworkManagerInterfaceDeviceModem::QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, QObject *parent) 834 : QObject(parent) 835 { 836 d = new QNetworkManagerInterfaceDeviceModemPrivate(); 837 d->path = ifaceDevicePath; 838 d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), 839 d->path, 840 QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), 841 QDBusConnection::systemBus(), parent); 842 if (!d->connectionInterface->isValid()) { 843 d->valid = false; 844 return; 845 } 846 QDBusInterface deviceModemPropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 847 d->path, 848 QLatin1String("org.freedesktop.DBus.Properties"), 849 QDBusConnection::systemBus(),parent); 850 851 QList<QVariant> argumentList; 852 argumentList << QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM); 853 QDBusPendingReply<QVariantMap> propsReply 854 = deviceModemPropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 855 argumentList); 856 if (!propsReply.isError()) { 857 propertyMap = propsReply.value(); 858 } 859 860 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 861 d->path, 862 QLatin1String(NM_DBUS_INTERFACE_DEVICE_MODEM), 863 QLatin1String("PropertiesChanged"), 864 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 865 d->valid = true; 866 } 867 868 QNetworkManagerInterfaceDeviceModem::~QNetworkManagerInterfaceDeviceModem() 869 { 870 delete d->connectionInterface; 871 delete d; 872 } 873 874 bool QNetworkManagerInterfaceDeviceModem::isValid() 875 { 876 877 return d->valid; 878 } 879 880 bool QNetworkManagerInterfaceDeviceModem::setConnections() 881 { 882 if (!isValid() ) 883 return false; 884 885 return true; 886 } 887 888 QDBusInterface *QNetworkManagerInterfaceDeviceModem::connectionInterface() const 889 { 890 return d->connectionInterface; 891 } 892 893 QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::modemCapabilities() const 894 { 895 if (propertyMap.contains("ModemCapabilities")) 896 return static_cast<QNetworkManagerInterfaceDeviceModem::ModemCapabilities>(propertyMap.value("ModemCapabilities").toUInt()); 897 return QNetworkManagerInterfaceDeviceModem::None; 898 } 899 900 QNetworkManagerInterfaceDeviceModem::ModemCapabilities QNetworkManagerInterfaceDeviceModem::currentCapabilities() const 901 { 902 if (propertyMap.contains("CurrentCapabilities")) 903 return static_cast<QNetworkManagerInterfaceDeviceModem::ModemCapabilities>(propertyMap.value("CurrentCapabilities").toUInt()); 904 return QNetworkManagerInterfaceDeviceModem::None; 905 } 906 907 void QNetworkManagerInterfaceDeviceModem::propertiesSwap(QMap<QString,QVariant> map) 908 { 909 QMapIterator<QString, QVariant> i(map); 910 while (i.hasNext()) { 911 i.next(); 912 propertyMap.insert(i.key(),i.value()); 913 } 914 Q_EMIT propertiesChanged(map); 578 915 } 579 916 580 917 class QNetworkManagerSettingsPrivate … … 598 935 d->valid = false; 599 936 return; 600 937 } 938 939 QDBusPendingReply<QList <QDBusObjectPath> > nmReply 940 = d->connectionInterface->call(QLatin1String("ListConnections")); 941 942 if (!nmReply.isError()) { 943 connectionsList = nmReply.value(); 944 } 945 601 946 d->valid = true; 602 947 } 603 948 … … 614 959 615 960 bool QNetworkManagerSettings::setConnections() 616 961 { 617 bool allOk = false;962 bool allOk = true; 618 963 619 if (!QDBusConnection::systemBus().connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS), 620 QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"), 621 this, SIGNAL(newConnection(QDBusObjectPath)))) { 622 allOk = true; 964 if (!QDBusConnection::systemBus().connect(d->path, 965 QLatin1String(NM_DBUS_PATH_SETTINGS), 966 QLatin1String(NM_DBUS_IFACE_SETTINGS), 967 QLatin1String("NewConnection"), 968 this, SIGNAL(newConnection(QDBusObjectPath)))) { 969 allOk = false; 623 970 } 624 971 625 972 return allOk; … … 627 974 628 975 QList <QDBusObjectPath> QNetworkManagerSettings::listConnections() 629 976 { 630 QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("ListConnections")); 631 return reply.value(); 977 if (connectionsList.isEmpty()) { 978 qWarning() << "Using blocking call!"; 979 QDBusReply<QList<QDBusObjectPath> > reply 980 = d->connectionInterface->call(QLatin1String("ListConnections")); 981 connectionsList = reply.value(); 982 } 983 return connectionsList; 984 } 985 986 987 QString QNetworkManagerSettings::getConnectionByUuid(const QString &uuid) 988 { 989 QList<QVariant> argumentList; 990 argumentList << QVariant::fromValue(uuid); 991 QDBusReply<QDBusObjectPath > reply = d->connectionInterface->callWithArgumentList(QDBus::Block,QLatin1String("GetConnectionByUuid"), argumentList); 992 return reply.value().path(); 632 993 } 633 994 634 995 QDBusInterface *QNetworkManagerSettings::connectionInterface() const … … 648 1009 }; 649 1010 650 1011 QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent) 651 : QObject(parent) , nmDBusHelper(0)1012 : QObject(parent) 652 1013 { 653 1014 qDBusRegisterMetaType<QNmSettingsMap>(); 654 1015 d = new QNetworkManagerSettingsConnectionPrivate(); … … 663 1024 return; 664 1025 } 665 1026 d->valid = true; 666 QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); 667 d->settingsMap = rep.value(); 1027 1028 QDBusPendingReply<QNmSettingsMap> nmReply 1029 = d->connectionInterface->call(QLatin1String("GetSettings")); 1030 if (!nmReply.isError()) { 1031 d->settingsMap = nmReply.value(); 1032 } 668 1033 } 669 1034 670 1035 QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() … … 680 1045 681 1046 bool QNetworkManagerSettingsConnection::setConnections() 682 1047 { 683 if (!isValid())1048 if (!isValid()) 684 1049 return false; 685 1050 686 1051 QDBusConnection dbusConnection = QDBusConnection::systemBus(); 687 bool allOk = false;688 if (!dbusConnection.connect(d->service, d->path,689 QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"),690 this, SIGNAL(updated(QNmSettingsMap)))) {691 allOk = true;692 } else{693 QDBusError error = dbusConnection.lastError();1052 bool allOk = true; 1053 if (!dbusConnection.connect(d->service, 1054 d->path, 1055 QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), 1056 QLatin1String("Updated"), 1057 this, SIGNAL(updated()))) { 1058 allOk = false; 694 1059 } 695 1060 696 delete nmDBusHelper; 697 nmDBusHelper = new QNmDBusHelper(this); 698 connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(QString)), 699 this,SIGNAL(removed(QString))); 700 701 if (!dbusConnection.connect(d->service, d->path, 702 QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"), 703 nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { 704 allOk = true; 1061 if (!dbusConnection.connect(d->service, 1062 d->path, 1063 QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), 1064 QLatin1String("Removed"), 1065 this, SIGNAL(slotSettingsRemoved()))) { 1066 allOk = false; 705 1067 } 706 707 1068 return allOk; 708 1069 } 709 1070 1071 void QNetworkManagerSettingsConnection::slotSettingsRemoved() 1072 { 1073 Q_EMIT removed(d->path); 1074 } 1075 710 1076 QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const 711 1077 { 712 1078 return d->connectionInterface; … … 714 1080 715 1081 QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() 716 1082 { 717 QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); 718 d->settingsMap = rep.value(); 1083 if (d->settingsMap.isEmpty()) { 1084 qWarning() << "Using blocking call!"; 1085 QDBusReply<QNmSettingsMap> reply = d->connectionInterface->call(QLatin1String("GetSettings")); 1086 d->settingsMap = reply.value(); 1087 } 719 1088 return d->settingsMap; 720 1089 } 721 1090 … … 725 1094 d->settingsMap.value(QLatin1String("connection")).value(QLatin1String("type")).toString(); 726 1095 727 1096 if (devType == QLatin1String("802-3-ethernet")) 728 return DEVICE_TYPE_ 802_3_ETHERNET;1097 return DEVICE_TYPE_ETHERNET; 729 1098 else if (devType == QLatin1String("802-11-wireless")) 730 return DEVICE_TYPE_802_11_WIRELESS; 1099 return DEVICE_TYPE_WIFI; 1100 else if (devType == QLatin1String("gsm")) 1101 return DEVICE_TYPE_MODEM; 731 1102 else 732 1103 return DEVICE_TYPE_UNKNOWN; 733 1104 } … … 774 1145 { 775 1146 NMDeviceType type = getType(); 776 1147 777 if (type == DEVICE_TYPE_ 802_3_ETHERNET) {1148 if (type == DEVICE_TYPE_ETHERNET) { 778 1149 return d->settingsMap.value(QLatin1String("802-3-ethernet")) 779 1150 .value(QLatin1String("mac-address")).toString(); 780 } else if (type == DEVICE_TYPE_ 802_11_WIRELESS) {1151 } else if (type == DEVICE_TYPE_WIFI) { 781 1152 return d->settingsMap.value(QLatin1String("802-11-wireless")) 782 1153 .value(QLatin1String("mac-address")).toString(); 783 1154 } else { … … 787 1158 788 1159 QStringList QNetworkManagerSettingsConnection::getSeenBssids() 789 1160 { 790 if (getType() == DEVICE_TYPE_ 802_11_WIRELESS) {1161 if (getType() == DEVICE_TYPE_WIFI) { 791 1162 return d->settingsMap.value(QLatin1String("802-11-wireless")) 792 1163 .value(QLatin1String("seen-bssids")).toStringList(); 793 1164 } else { … … 803 1174 bool valid; 804 1175 }; 805 1176 806 QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( 807 : QObject(parent) , nmDBusHelper(0)1177 QNetworkManagerConnectionActive::QNetworkManagerConnectionActive(const QString &activeConnectionObjectPath, QObject *parent) 1178 : QObject(parent) 808 1179 { 809 1180 d = new QNetworkManagerConnectionActivePrivate(); 810 1181 d->path = activeConnectionObjectPath; … … 816 1187 d->valid = false; 817 1188 return; 818 1189 } 1190 QDBusInterface connectionActivePropertiesInterface(QLatin1String(NM_DBUS_SERVICE), 1191 d->path, 1192 QLatin1String("org.freedesktop.DBus.Properties"), 1193 QDBusConnection::systemBus()); 1194 1195 1196 QList<QVariant> argumentList; 1197 argumentList << QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION); 1198 QDBusPendingReply<QVariantMap> propsReply 1199 = connectionActivePropertiesInterface.callWithArgumentList(QDBus::Block,QLatin1String("GetAll"), 1200 argumentList); 1201 1202 if (!propsReply.isError()) { 1203 propertyMap = propsReply.value(); 1204 } else { 1205 qWarning() << propsReply.error().message(); 1206 } 1207 1208 QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 1209 d->path, 1210 QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), 1211 QLatin1String("PropertiesChanged"), 1212 this,SLOT(propertiesSwap(QMap<QString,QVariant>))); 819 1213 d->valid = true; 820 1214 } 821 1215 … … 832 1226 833 1227 bool QNetworkManagerConnectionActive::setConnections() 834 1228 { 835 if (!isValid())1229 if (!isValid()) 836 1230 return false; 837 1231 838 bool allOk = false; 839 delete nmDBusHelper; 840 nmDBusHelper = new QNmDBusHelper(this); 841 connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(QString,QMap<QString,QVariant>)), 842 this,SIGNAL(propertiesChanged(QString,QMap<QString,QVariant>))); 843 if (QDBusConnection::systemBus().connect(QLatin1String(NM_DBUS_SERVICE), 844 d->path, 845 QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), 846 QLatin1String("PropertiesChanged"), 847 nmDBusHelper,SLOT(slotPropertiesChanged(QMap<QString,QVariant>))) ) { 848 allOk = true; 849 } 850 851 return allOk; 1232 return true; 852 1233 } 853 1234 854 1235 QDBusInterface *QNetworkManagerConnectionActive::connectionInterface() const … … 856 1237 return d->connectionInterface; 857 1238 } 858 1239 859 QString QNetworkManagerConnectionActive::serviceName() const860 {861 return d->connectionInterface->property("ServiceName").toString();862 }863 864 1240 QDBusObjectPath QNetworkManagerConnectionActive::connection() const 865 1241 { 866 QVariant prop = d->connectionInterface->property("Connection"); 867 return prop.value<QDBusObjectPath>(); 1242 if (propertyMap.contains("Connection")) 1243 return propertyMap.value("Connection").value<QDBusObjectPath>(); 1244 return QDBusObjectPath(); 868 1245 } 869 1246 870 1247 QDBusObjectPath QNetworkManagerConnectionActive::specificObject() const 871 1248 { 872 QVariant prop = d->connectionInterface->property("SpecificObject"); 873 return prop.value<QDBusObjectPath>(); 874 } 875 876 QList<QDBusObjectPath> QNetworkManagerConnectionActive::devices() const 877 { 878 QVariant prop = d->connectionInterface->property("Devices"); 879 return prop.value<QList<QDBusObjectPath> >(); 1249 if (propertyMap.contains("SpecificObject")) 1250 return propertyMap.value("SpecificObject").value<QDBusObjectPath>(); 1251 return QDBusObjectPath(); 1252 } 1253 1254 QStringList QNetworkManagerConnectionActive::devices() const 1255 { 1256 QStringList list; 1257 if (propertyMap.contains("Devices")) { 1258 const QDBusArgument &dbusArgs = propertyMap.value("Devices").value<QDBusArgument>(); 1259 QDBusObjectPath path; 1260 1261 dbusArgs.beginArray(); 1262 while (!dbusArgs.atEnd()) { 1263 dbusArgs >> path; 1264 list.append(path.path()); 1265 } 1266 dbusArgs.endArray(); 1267 } 1268 return list; 880 1269 } 881 1270 882 1271 quint32 QNetworkManagerConnectionActive::state() const 883 1272 { 884 return d->connectionInterface->property("State").toUInt(); 1273 if (propertyMap.contains("State")) 1274 return propertyMap.value("State").toUInt(); 1275 return 0; 885 1276 } 886 1277 887 1278 bool QNetworkManagerConnectionActive::defaultRoute() const 888 1279 { 889 return d->connectionInterface->property("Default").toBool(); 1280 if (propertyMap.contains("Default")) 1281 return propertyMap.value("Default").toBool(); 1282 return false; 1283 } 1284 1285 bool QNetworkManagerConnectionActive::default6Route() const 1286 { 1287 if (propertyMap.contains("Default6")) 1288 return propertyMap.value("Default6").toBool(); 1289 return false; 1290 } 1291 1292 void QNetworkManagerConnectionActive::propertiesSwap(QMap<QString,QVariant> map) 1293 { 1294 QMapIterator<QString, QVariant> i(map); 1295 while (i.hasNext()) { 1296 i.next(); 1297 propertyMap.insert(i.key(),i.value()); 1298 if (i.key() == QStringLiteral("State")) { 1299 quint32 state = i.value().toUInt(); 1300 if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED 1301 || state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { 1302 Q_EMIT propertiesChanged(map); 1303 } 1304 } 1305 } 890 1306 } 891 1307 892 1308 class QNetworkManagerIp4ConfigPrivate -
qtbase/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h
1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 3Digia Plc and/or its subsidiary(-ies).3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 4 4 ** Contact: http://www.qt-project.org/legal 5 5 ** 6 6 ** This file is part of the plugins of the Qt Toolkit. 7 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL $8 ** $QT_BEGIN_LICENSE:LGPL21$ 9 9 ** Commercial License Usage 10 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 11 ** accordance with the commercial license agreement provided with the 12 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and Digia. 14 ** conditions see http://qt.digia.com/licensing. 13 ** a written agreement between you and Digia. For licensing terms and 14 ** conditions see http://qt.digia.com/licensing. For further information 15 15 ** use the contact form at http://qt.digia.com/contact-us. 16 16 ** 17 17 ** GNU Lesser General Public License Usage 18 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 2.1 requirements 23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 25 ** 25 26 ** In addition, as a special exception, Digia gives you certain additional 26 ** rights. 27 ** rights. These rights are described in the Digia Qt LGPL Exception 27 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 28 29 ** 29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 30 ** $QT_END_LICENSE$ 39 31 ** 40 32 ****************************************************************************/ … … 64 56 #include <QtDBus/QDBusObjectPath> 65 57 #include <QtDBus/QDBusContext> 66 58 #include <QMap> 67 #include "qnmdbushelper.h"68 59 69 60 #ifndef QT_NO_DBUS 70 61 … … 72 63 typedef enum NMDeviceType 73 64 { 74 65 DEVICE_TYPE_UNKNOWN = 0, 75 DEVICE_TYPE_802_3_ETHERNET, 76 DEVICE_TYPE_802_11_WIRELESS, 77 DEVICE_TYPE_GSM, 78 DEVICE_TYPE_CDMA 66 DEVICE_TYPE_ETHERNET, 67 DEVICE_TYPE_WIFI, 68 DEVICE_TYPE_MODEM = 8 79 69 } NMDeviceType; 80 70 81 71 typedef enum 82 72 { 83 73 NM_DEVICE_STATE_UNKNOWN = 0, 84 NM_DEVICE_STATE_UNMANAGED, 85 NM_DEVICE_STATE_UNAVAILABLE, 86 NM_DEVICE_STATE_DISCONNECTED, 87 NM_DEVICE_STATE_PREPARE, 88 NM_DEVICE_STATE_CONFIG, 89 NM_DEVICE_STATE_NEED_AUTH, 90 NM_DEVICE_STATE_IP_CONFIG, 91 NM_DEVICE_STATE_ACTIVATED, 92 NM_DEVICE_STATE_FAILED 74 NM_DEVICE_STATE_UNMANAGED = 10, 75 NM_DEVICE_STATE_UNAVAILABLE = 20, 76 NM_DEVICE_STATE_DISCONNECTED = 30, 77 NM_DEVICE_STATE_PREPARE = 40, 78 NM_DEVICE_STATE_CONFIG = 50, 79 NM_DEVICE_STATE_NEED_AUTH = 60, 80 NM_DEVICE_STATE_IP_CONFIG = 70, 81 NM_DEVICE_STATE_ACTIVATED = 100, 82 NM_DEVICE_STATE_DEACTIVATING = 110, 83 NM_DEVICE_STATE_FAILED = 120 93 84 } NMDeviceState; 94 85 95 86 typedef enum 96 87 { 97 88 NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0, 98 89 NM_ACTIVE_CONNECTION_STATE_ACTIVATING, 99 NM_ACTIVE_CONNECTION_STATE_ACTIVATED 90 NM_ACTIVE_CONNECTION_STATE_ACTIVATED, 91 NM_ACTIVE_CONNECTION_STATE_DEACTIVATED = 4 100 92 } NMActiveConnectionState; 101 93 102 94 #define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" … … 106 98 #define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device" 107 99 #define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired" 108 100 #define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless" 101 #define NM_DBUS_INTERFACE_DEVICE_MODEM NM_DBUS_INTERFACE_DEVICE ".Modem" 109 102 #define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint" 110 103 #define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint" 111 104 112 #define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager Settings"105 #define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManager/Settings" 113 106 114 #define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManager Settings.Connection"115 #define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager Settings"107 #define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManager.Settings.Connection" 108 #define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManager.Settings" 116 109 #define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active" 117 110 #define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config" 118 111 … … 141 134 Q_OBJECT 142 135 143 136 public: 137 typedef enum 138 { 139 NM_STATE_UNKNOWN = 0, 140 NM_STATE_ASLEEP = 10, 141 NM_STATE_DISCONNECTED = 20, 142 NM_STATE_DISCONNECTING = 30, 143 NM_STATE_CONNECTING = 40, 144 NM_STATE_CONNECTED_LOCAL = 50, 145 NM_STATE_CONNECTED_SITE = 60, 146 NM_STATE_CONNECTED_GLOBAL = 70 147 } NMState; 144 148 145 149 QNetworkManagerInterface(QObject *parent = 0); 146 150 ~QNetworkManagerInterface(); 147 151 148 QList <QDBusObjectPath> getDevices() const;149 void activateConnection( const QString &serviceName, QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject);152 QList <QDBusObjectPath> getDevices(); 153 void activateConnection(QDBusObjectPath connection,QDBusObjectPath device, QDBusObjectPath specificObject); 150 154 void deactivateConnection(QDBusObjectPath connectionPath) const; 151 155 152 156 QDBusObjectPath path() const; … … 155 159 bool wirelessEnabled() const; 156 160 bool wirelessHardwareEnabled() const; 157 161 QList <QDBusObjectPath> activeConnections() const; 158 quint32 state(); 162 NMState state(); 163 QString version() const; 159 164 bool setConnections(); 160 165 bool isValid(); 161 166 162 167 Q_SIGNALS: 163 168 void deviceAdded(QDBusObjectPath); 164 169 void deviceRemoved(QDBusObjectPath); 165 void propertiesChanged( const QString &,QMap<QString,QVariant>);166 void stateChanged( const QString&,quint32);170 void propertiesChanged(QMap<QString,QVariant>); 171 void stateChanged(quint32); 167 172 void activationFinished(QDBusPendingCallWatcher*); 173 void propertiesReady(); 174 void devicesListReady(); 168 175 169 176 private Q_SLOTS: 177 void propertiesSwap(QMap<QString,QVariant>); 178 170 179 private: 171 180 QNetworkManagerInterfacePrivate *d; 172 QNmDBusHelper *nmDBusHelper; 181 QVariantMap propertyMap; 182 QList<QDBusObjectPath> devicesPathList; 183 173 184 }; 174 185 175 186 class QNetworkManagerInterfaceAccessPointPrivate; … … 234 245 235 246 Q_SIGNALS: 236 247 void propertiesChanged(QMap <QString,QVariant>); 237 void propertiesChanged( const QString &, QMap<QString,QVariant>); 248 void propertiesReady(); 249 250 private Q_SLOTS: 251 void propertiesSwap(QMap<QString,QVariant>); 252 238 253 private: 239 254 QNetworkManagerInterfaceAccessPointPrivate *d; 240 QNmDBusHelper *nmDBusHelper; 241 255 QVariantMap propertyMap; 242 256 }; 243 257 244 258 class QNetworkManagerInterfaceDevicePrivate; … … 264 278 265 279 Q_SIGNALS: 266 280 void stateChanged(const QString &, quint32); 267 281 void propertiesChanged(QMap<QString,QVariant>); 282 void connectionsChanged(QStringList); 283 void propertiesReady(); 284 private Q_SLOTS: 285 void propertiesSwap(QMap<QString,QVariant>); 268 286 private: 269 287 QNetworkManagerInterfaceDevicePrivate *d; 270 Q NmDBusHelper *nmDBusHelper;288 QVariantMap propertyMap; 271 289 }; 272 290 273 291 class QNetworkManagerInterfaceDeviceWiredPrivate; … … 287 305 bool carrier() const; 288 306 bool setConnections(); 289 307 bool isValid(); 308 QStringList availableConnections(); 290 309 291 310 Q_SIGNALS: 292 void propertiesChanged( const QString &, QMap<QString,QVariant>); 311 void propertiesChanged(QMap<QString,QVariant>); 312 void propertiesReady(); 313 void carrierChanged(bool); 314 315 private Q_SLOTS: 316 void propertiesSwap(QMap<QString,QVariant>); 317 293 318 private: 294 319 QNetworkManagerInterfaceDeviceWiredPrivate *d; 295 Q NmDBusHelper *nmDBusHelper;320 QVariantMap propertyMap; 296 321 }; 297 322 298 323 class QNetworkManagerInterfaceDeviceWirelessPrivate; … … 328 353 bool setConnections(); 329 354 bool isValid(); 330 355 356 void requestScan(); 331 357 Q_SIGNALS: 332 void propertiesChanged( const QString &, QMap<QString,QVariant>); 333 void accessPointAdded(const QString &,QDBusObjectPath); 334 void accessPointRemoved(const QString &,QDBusObjectPath); 358 void propertiesChanged(QMap<QString,QVariant>); 359 void accessPointAdded(const QString &); 360 void accessPointRemoved(const QString &); 361 void scanDone(); 362 void propertiesReady(); 363 void accessPointsReady(); 364 365 private Q_SLOTS: 366 void scanIsDone(); 367 void propertiesSwap(QMap<QString,QVariant>); 368 369 void slotAccessPointAdded(QDBusObjectPath); 370 void slotAccessPointRemoved(QDBusObjectPath); 371 335 372 private: 336 373 QNetworkManagerInterfaceDeviceWirelessPrivate *d; 337 QNmDBusHelper *nmDBusHelper; 374 QVariantMap propertyMap; 375 QList <QDBusObjectPath> accessPointsList; 376 }; 377 378 class QNetworkManagerInterfaceDeviceModemPrivate; 379 class QNetworkManagerInterfaceDeviceModem : public QObject 380 { 381 Q_OBJECT 382 383 public: 384 385 enum ModemCapability { 386 None = 0x0, 387 Pots = 0x1, 388 Cmda_Edvo = 0x2, 389 Gsm_Umts = 0x4, 390 Lte = 0x08 391 }; 392 Q_DECLARE_FLAGS(ModemCapabilities, ModemCapability) 393 394 explicit QNetworkManagerInterfaceDeviceModem(const QString &ifaceDevicePath, 395 QObject *parent = 0); 396 ~QNetworkManagerInterfaceDeviceModem(); 397 398 QDBusObjectPath path() const; 399 QDBusInterface *connectionInterface() const; 400 401 bool setConnections(); 402 bool isValid(); 403 404 ModemCapabilities modemCapabilities() const; 405 ModemCapabilities currentCapabilities() const; 406 407 Q_SIGNALS: 408 void propertiesChanged(QMap<QString,QVariant>); 409 void propertiesReady(); 410 411 private Q_SLOTS: 412 void propertiesSwap(QMap<QString,QVariant>); 413 414 private: 415 QNetworkManagerInterfaceDeviceModemPrivate *d; 416 QVariantMap propertyMap; 338 417 }; 339 418 419 Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkManagerInterfaceDeviceModem::ModemCapabilities) 420 340 421 class QNetworkManagerSettingsPrivate; 341 422 class QNetworkManagerSettings : public QObject 342 423 { … … 349 430 350 431 QDBusInterface *connectionInterface() const; 351 432 QList <QDBusObjectPath> listConnections(); 433 QString getConnectionByUuid(const QString &uuid); 352 434 bool setConnections(); 353 435 bool isValid(); 354 436 355 437 Q_SIGNALS: 356 438 void newConnection(QDBusObjectPath); 439 void connectionsListReady(); 357 440 private: 358 441 QNetworkManagerSettingsPrivate *d; 442 QList <QDBusObjectPath> connectionsList; 359 443 }; 360 444 361 445 class QNetworkManagerSettingsConnectionPrivate; … … 382 466 bool isValid(); 383 467 384 468 Q_SIGNALS: 385 386 void updated(const QNmSettingsMap &settings); 469 void updated(); 387 470 void removed(const QString &path); 471 void settingsReady(); 472 473 private Q_SLOTS: 474 void slotSettingsRemoved(); 388 475 389 476 private: 390 QNmDBusHelper *nmDBusHelper;391 477 QNetworkManagerSettingsConnectionPrivate *d; 392 478 }; 393 479 … … 408 494 ~ QNetworkManagerConnectionActive(); 409 495 410 496 QDBusInterface *connectionInterface() const; 411 QString serviceName() const;412 497 QDBusObjectPath connection() const; 413 498 QDBusObjectPath specificObject() const; 414 Q List<QDBusObjectPath>devices() const;499 QStringList devices() const; 415 500 quint32 state() const; 416 501 bool defaultRoute() const; 502 bool default6Route() const; 417 503 bool setConnections(); 418 504 bool isValid(); 419 505 420 506 421 507 Q_SIGNALS: 422 void propertiesChanged(QList<QDBusObjectPath>); 423 void propertiesChanged( const QString &, QMap<QString,QVariant>); 508 void propertiesChanged(QMap<QString,QVariant>); 509 void propertiesReady(); 510 511 private Q_SLOTS: 512 void propertiesSwap(QMap<QString,QVariant>); 513 424 514 private: 425 515 QNetworkManagerConnectionActivePrivate *d; 426 Q NmDBusHelper *nmDBusHelper;516 QVariantMap propertyMap; 427 517 }; 428 518 429 519 class QNetworkManagerIp4ConfigPrivate; -
deleted file qtbase/src/plugins/bearer/networkmanager/qnmdbushelper.cpp
+ - 1 /****************************************************************************2 **3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).4 ** Contact: http://www.qt-project.org/legal5 **6 ** This file is part of the plugins of the Qt Toolkit.7 **8 ** $QT_BEGIN_LICENSE:LGPL$9 ** Commercial License Usage10 ** Licensees holding valid commercial Qt licenses may use this file in11 ** accordance with the commercial license agreement provided with the12 ** Software or, alternatively, in accordance with the terms contained in13 ** a written agreement between you and Digia. For licensing terms and14 ** conditions see http://qt.digia.com/licensing. For further information15 ** use the contact form at http://qt.digia.com/contact-us.16 **17 ** GNU Lesser General Public License Usage18 ** Alternatively, this file may be used under the terms of the GNU Lesser19 ** General Public License version 2.1 as published by the Free Software20 ** Foundation and appearing in the file LICENSE.LGPL included in the21 ** packaging of this file. Please review the following information to22 ** ensure the GNU Lesser General Public License version 2.1 requirements23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.24 **25 ** In addition, as a special exception, Digia gives you certain additional26 ** rights. These rights are described in the Digia Qt LGPL Exception27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.28 **29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 ** $QT_END_LICENSE$39 **40 ****************************************************************************/41 42 // this class is for helping qdbus get stuff43 44 #include "qnmdbushelper.h"45 46 #include "qnetworkmanagerservice.h"47 48 #include <QDBusError>49 #include <QDBusInterface>50 #include <QDBusMessage>51 #include <QDBusReply>52 53 #include <QDebug>54 55 #ifndef QT_NO_DBUS56 57 QT_BEGIN_NAMESPACE58 59 QNmDBusHelper::QNmDBusHelper(QObject * parent)60 : QObject(parent)61 {62 }63 64 QNmDBusHelper::~QNmDBusHelper()65 {66 }67 68 void QNmDBusHelper::deviceStateChanged(quint32 state)69 {70 QDBusMessage msg = this->message();71 if(state == NM_DEVICE_STATE_ACTIVATED72 || state == NM_DEVICE_STATE_DISCONNECTED73 || state == NM_DEVICE_STATE_UNAVAILABLE74 || state == NM_DEVICE_STATE_FAILED) {75 emit pathForStateChanged(msg.path(), state);76 }77 }78 79 void QNmDBusHelper::slotAccessPointAdded(QDBusObjectPath path)80 {81 if(path.path().length() > 2) {82 QDBusMessage msg = this->message();83 emit pathForAccessPointAdded(msg.path(), path);84 }85 }86 87 void QNmDBusHelper::slotAccessPointRemoved(QDBusObjectPath path)88 {89 if(path.path().length() > 2) {90 QDBusMessage msg = this->message();91 emit pathForAccessPointRemoved(msg.path(), path);92 }93 }94 95 void QNmDBusHelper::slotPropertiesChanged(QMap<QString,QVariant> map)96 {97 QDBusMessage msg = this->message();98 QMapIterator<QString, QVariant> i(map);99 while (i.hasNext()) {100 i.next();101 if( i.key() == "State") { //state only applies to device interfaces102 quint32 state = i.value().toUInt();103 if( state == NM_DEVICE_STATE_ACTIVATED104 || state == NM_DEVICE_STATE_DISCONNECTED105 || state == NM_DEVICE_STATE_UNAVAILABLE106 || state == NM_DEVICE_STATE_FAILED) {107 emit pathForPropertiesChanged( msg.path(), map);108 }109 } else if( i.key() == "ActiveAccessPoint") {110 emit pathForPropertiesChanged(msg.path(), map);111 // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().value<QDBusObjectPath>().path();112 // } else if( i.key() == "Strength")113 // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value().toUInt();114 // else115 // qWarning() << __PRETTY_FUNCTION__ << i.key() << ": " << i.value();116 } else if (i.key() == "ActiveConnections") {117 emit pathForPropertiesChanged(msg.path(), map);118 }119 }120 }121 122 void QNmDBusHelper::slotSettingsRemoved()123 {124 QDBusMessage msg = this->message();125 emit pathForSettingsRemoved(msg.path());126 }127 128 QT_END_NAMESPACE129 130 #endif // QT_NO_DBUS -
deleted file qtbase/src/plugins/bearer/networkmanager/qnmdbushelper.h
+ - 1 /****************************************************************************2 **3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).4 ** Contact: http://www.qt-project.org/legal5 **6 ** This file is part of the plugins of the Qt Toolkit.7 **8 ** $QT_BEGIN_LICENSE:LGPL$9 ** Commercial License Usage10 ** Licensees holding valid commercial Qt licenses may use this file in11 ** accordance with the commercial license agreement provided with the12 ** Software or, alternatively, in accordance with the terms contained in13 ** a written agreement between you and Digia. For licensing terms and14 ** conditions see http://qt.digia.com/licensing. For further information15 ** use the contact form at http://qt.digia.com/contact-us.16 **17 ** GNU Lesser General Public License Usage18 ** Alternatively, this file may be used under the terms of the GNU Lesser19 ** General Public License version 2.1 as published by the Free Software20 ** Foundation and appearing in the file LICENSE.LGPL included in the21 ** packaging of this file. Please review the following information to22 ** ensure the GNU Lesser General Public License version 2.1 requirements23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.24 **25 ** In addition, as a special exception, Digia gives you certain additional26 ** rights. These rights are described in the Digia Qt LGPL Exception27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.28 **29 ** GNU General Public License Usage30 ** Alternatively, this file may be used under the terms of the GNU31 ** General Public License version 3.0 as published by the Free Software32 ** Foundation and appearing in the file LICENSE.GPL included in the33 ** packaging of this file. Please review the following information to34 ** ensure the GNU General Public License version 3.0 requirements will be35 ** met: http://www.gnu.org/copyleft/gpl.html.36 **37 **38 ** $QT_END_LICENSE$39 **40 ****************************************************************************/41 42 #ifndef QNMDBUSHELPERPRIVATE_H43 #define QNMDBUSHELPERPRIVATE_H44 45 #include <QDBusObjectPath>46 #include <QDBusContext>47 #include <QMap>48 49 #ifndef QT_NO_DBUS50 51 QT_BEGIN_NAMESPACE52 53 class QNmDBusHelper: public QObject, protected QDBusContext54 {55 Q_OBJECT56 public:57 QNmDBusHelper(QObject *parent = 0);58 ~QNmDBusHelper();59 60 public slots:61 void deviceStateChanged(quint32);62 void slotAccessPointAdded( QDBusObjectPath );63 void slotAccessPointRemoved( QDBusObjectPath );64 void slotPropertiesChanged( QMap<QString,QVariant>);65 void slotSettingsRemoved();66 67 Q_SIGNALS:68 void pathForStateChanged(const QString &, quint32);69 void pathForAccessPointAdded(const QString &, QDBusObjectPath );70 void pathForAccessPointRemoved(const QString &, QDBusObjectPath );71 void pathForPropertiesChanged(const QString &, QMap<QString,QVariant>);72 void pathForSettingsRemoved(const QString &);73 };74 75 QT_END_NAMESPACE76 77 #endif // QT_NO_DBUS78 79 #endif// QNMDBUSHELPERPRIVATE_H