From cc14f85730813b9f0bb752627bab3c44803091a6 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Thu, 23 Jan 2014 18:47:31 +1000 Subject: Refactor and remove dead code, add property caching. This helps with a flood of dbus messages due to properties. Change-Id: I7aa9d36a077d84a88dab561d007d597b0780e096 Reviewed-by: Aaron McCarthy --- src/plugins/bearer/connman/connman.pro | 2 + src/plugins/bearer/connman/qconnmanengine.cpp | 401 +++++---- src/plugins/bearer/connman/qconnmanengine.h | 24 +- .../bearer/connman/qconnmanservice_linux.cpp | 866 +++++--------------- .../bearer/connman/qconnmanservice_linux_p.h | 207 ++--- src/plugins/bearer/connman/qofonoservice_linux.cpp | 899 +++------------------ src/plugins/bearer/connman/qofonoservice_linux_p.h | 220 +---- 7 files changed, 606 insertions(+), 2013 deletions(-) (limited to 'src') diff --git a/src/plugins/bearer/connman/connman.pro b/src/plugins/bearer/connman/connman.pro index cccdff0fdb..0da2dfacf6 100644 --- a/src/plugins/bearer/connman/connman.pro +++ b/src/plugins/bearer/connman/connman.pro @@ -5,6 +5,8 @@ PLUGIN_CLASS_NAME = QConnmanEnginePlugin load(qt_plugin) QT = core network-private dbus +CONFIG += link_pkgconfig +packagesExist(connectionagent) { DEFINES += QT_HAS_CONNECTIONAGENT } HEADERS += qconnmanservice_linux_p.h \ qofonoservice_linux_p.h \ diff --git a/src/plugins/bearer/connman/qconnmanengine.cpp b/src/plugins/bearer/connman/qconnmanengine.cpp index eac0d2b813..aee56eb034 100644 --- a/src/plugins/bearer/connman/qconnmanengine.cpp +++ b/src/plugins/bearer/connman/qconnmanengine.cpp @@ -41,7 +41,6 @@ #include "qconnmanengine.h" #include "qconnmanservice_linux_p.h" -#include "qofonoservice_linux_p.h" #include "../qnetworksession_impl.h" #include @@ -55,7 +54,11 @@ #include #include #include - +#ifdef QT_HAS_CONNECTIONAGENT +#include +#include +#include +#endif #ifndef QT_NO_BEARERMANAGEMENT #ifndef QT_NO_DBUS @@ -63,7 +66,10 @@ QT_BEGIN_NAMESPACE QConnmanEngine::QConnmanEngine(QObject *parent) : QBearerEngineImpl(parent), - connmanManager(new QConnmanManagerInterface(this)) + connmanManager(new QConnmanManagerInterface(this)), + ofonoManager(new QOfonoManagerInterface(this)), + ofonoNetwork(0), + ofonoContextManager(0) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -72,6 +78,9 @@ QConnmanEngine::QConnmanEngine(QObject *parent) QConnmanEngine::~QConnmanEngine() { +#ifdef QT_HAS_CONNECTIONAGENT + qt_safe_close(inotifyFileDescriptor); +#endif } bool QConnmanEngine::connmanAvailable() const @@ -82,26 +91,56 @@ bool QConnmanEngine::connmanAvailable() const void QConnmanEngine::initialize() { - connect(connmanManager,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(propertyChangedContext(QString,QString,QDBusVariant))); + QMutexLocker locker(&mutex); + connect(ofonoManager,SIGNAL(modemChanged()),this,SLOT(changedModem())); + + ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); + ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); + connect(ofonoContextManager,SIGNAL(roamingAllowedChanged(bool)),this,SLOT(reEvaluateCellular())); connect(connmanManager,SIGNAL(servicesChanged(ConnmanMapList, QList)), this, SLOT(updateServices(ConnmanMapList, QList))); - foreach (const QString &techPath, connmanManager->getTechnologies()) { - QConnmanTechnologyInterface *tech; - tech = new QConnmanTechnologyInterface(techPath, this); + connect(connmanManager,SIGNAL(servicesReady(QStringList)),this,SLOT(servicesReady(QStringList))); + connect(connmanManager,SIGNAL(scanFinished()),this,SLOT(finishedScan())); - connect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); + foreach (const QString &servPath, connmanManager->getServices()) { + addServiceConfiguration(servPath); + } + Q_EMIT updateCompleted(); +#ifdef QT_HAS_CONNECTIONAGENT + QSettings confFile(QStringLiteral("nemomobile"),QStringLiteral("connectionagent")); + + inotifyFileDescriptor = ::inotify_init(); + inotifyWatcher = ::inotify_add_watch(inotifyFileDescriptor, QFile::encodeName(confFile.fileName()), IN_MODIFY); + if (inotifyWatcher > 0) { + QSocketNotifier *notifier = new QSocketNotifier(inotifyFileDescriptor, QSocketNotifier::Read, this); + connect(notifier, SIGNAL(activated(int)), this, SLOT(inotifyActivated())); } +#endif +} - foreach (const QString &servPath, connmanManager->getServices()) { +void QConnmanEngine::changedModem() +{ + QMutexLocker locker(&mutex); + if (ofonoNetwork) + delete ofonoNetwork; + + ofonoNetwork = new QOfonoNetworkRegistrationInterface(ofonoManager->currentModem(),this); + + if (ofonoContextManager) + delete ofonoContextManager; + ofonoContextManager = new QOfonoDataConnectionManagerInterface(ofonoManager->currentModem(),this); +} + +void QConnmanEngine::servicesReady(const QStringList &list) +{ + QMutexLocker locker(&mutex); + foreach (const QString &servPath, list) { addServiceConfiguration(servPath); } - // Get current list of access points. - getConfigurations(); + Q_EMIT updateCompleted(); } QList QConnmanEngine::getConfigurations() @@ -129,13 +168,6 @@ QList QConnmanEngine::getConfigurations() return fetchedConfigurations; } -void QConnmanEngine::doRequestUpdate() -{ - connmanManager->requestScan(""); - getConfigurations(); - emit updateCompleted(); -} - QString QConnmanEngine::getInterfaceFromId(const QString &id) { QMutexLocker locker(&mutex); @@ -151,24 +183,25 @@ bool QConnmanEngine::hasIdentifier(const QString &id) void QConnmanEngine::connectToId(const QString &id) { QMutexLocker locker(&mutex); - QString servicePath = serviceFromId(id); - QConnmanServiceInterface serv(servicePath); - if(!serv.isValid()) { + + QConnmanServiceInterface *serv = connmanServiceInterfaces.value(id); + + if (!serv->isValid()) { emit connectionError(id, QBearerEngineImpl::InterfaceLookupError); } else { - serv.connect(); + serv->connect(); } } void QConnmanEngine::disconnectFromId(const QString &id) { QMutexLocker locker(&mutex); - QString servicePath = serviceFromId(id); - QConnmanServiceInterface serv(servicePath); - if(!serv.isValid()) { + QConnmanServiceInterface *serv = connmanServiceInterfaces.value(id); + + if (!serv->isValid()) { emit connectionError(id, DisconnectionError); } else { - serv.disconnect(); + serv->disconnect(); } } @@ -178,31 +211,32 @@ void QConnmanEngine::requestUpdate() QTimer::singleShot(0, this, SLOT(doRequestUpdate())); } +void QConnmanEngine::doRequestUpdate() +{ + connmanManager->requestScan("wifi"); +} + +void QConnmanEngine::finishedScan() +{ +} + void QConnmanEngine::updateServices(const ConnmanMapList &changed, const QList &removed) { + QMutexLocker locker(&mutex); + foreach (const QDBusObjectPath &objectPath, removed) { - removeConfiguration(QString::number(qHash(objectPath.path()))); + removeConfiguration(objectPath.path()); } foreach (const ConnmanMap &connmanMap, changed) { - const QString id = QString::number(qHash(connmanMap.objectPath.path())); + const QString id = connmanMap.objectPath.path(); if (accessPointConfigurations.contains(id)) { - configurationChange(id); + configurationChange(connmanServiceInterfaces.value(id)); } else { addServiceConfiguration(connmanMap.objectPath.path()); } } -} - -QString QConnmanEngine::serviceFromId(const QString &id) -{ - QMutexLocker locker(&mutex); - foreach (const QString &service, serviceNetworks) { - if (id == QString::number(qHash(service))) - return service; - } - - return QString(); + Q_EMIT updateCompleted(); } QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) @@ -211,25 +245,24 @@ QNetworkSession::State QConnmanEngine::sessionStateForId(const QString &id) QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - if (!ptr) + if (!ptr || !ptr->isValid) return QNetworkSession::Invalid; - if (!ptr->isValid) { - return QNetworkSession::Invalid; + QString service = id; + QConnmanServiceInterface *serv = connmanServiceInterfaces.value(service); - } - QString service = serviceFromId(id); - QConnmanServiceInterface serv(service); - QString servState = serv.getState(); + QString servState = serv->state(); - if(serv.isFavorite() && (servState == "idle" || servState == "failure")) { + if (serv->favorite() && (servState == QLatin1String("idle") || servState == QLatin1String("failure"))) { return QNetworkSession::Disconnected; } - if(servState == "association" || servState == "configuration" || servState == "login") { + if (servState == QLatin1String("association") || servState == QLatin1String("configuration") + || servState == QLatin1String("ready")) { return QNetworkSession::Connecting; } - if(servState == "ready" || servState == "online") { + + if (servState == QLatin1String("online")) { return QNetworkSession::Connected; } @@ -300,88 +333,36 @@ QNetworkSessionPrivate *QConnmanEngine::createSessionBackend() QNetworkConfigurationPrivatePointer QConnmanEngine::defaultConfiguration() { - return QNetworkConfigurationPrivatePointer(); -} - -void QConnmanEngine::propertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) -{ - Q_UNUSED(path); - - QMutexLocker locker(&mutex); - if(item == "Services") { - QDBusArgument arg = qvariant_cast(value.variant()); - QStringList list = qdbus_cast(arg); - - if(list.count() > accessPointConfigurations.count()) { - foreach (const QString &service, list) { - addServiceConfiguration(service); - } - } - } - - if(item == "Technologies") { - QDBusArgument arg = qvariant_cast(value.variant()); - QStringList newlist = qdbus_cast(arg); - if(newlist.count() > 0) { - QMap oldtech = technologies; - - foreach (const QString &listPath, newlist) { - if(!oldtech.contains(listPath)) { - QConnmanTechnologyInterface *tech; - tech = new QConnmanTechnologyInterface(listPath,this); - connect(tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); - technologies.insert(listPath, tech); - } - } - } - } - if(item == "State") { -// qDebug() << value.variant(); - } -} - -void QConnmanEngine::servicePropertyChangedContext(const QString &path,const QString &item, const QDBusVariant &value) -{ - QMutexLocker locker(&mutex); - if(item == "State") { - configurationChange(QString::number(qHash(path))); - - if(value.variant().toString() == "failure") { - QConnmanServiceInterface serv(path); - emit connectionError(QString::number(qHash(path)), ConnectError); + const QMutexLocker locker(&mutex); + Q_FOREACH (const QString &servPath, connmanManager->getServices()) { + if (connmanServiceInterfaces.contains(servPath)) { + if (accessPointConfigurations.contains(servPath)) + return accessPointConfigurations.value(servPath); } } + return QNetworkConfigurationPrivatePointer(); } -void QConnmanEngine::technologyPropertyChangedContext(const QString & path, const QString &item, const QDBusVariant &value) +void QConnmanEngine::serviceStateChanged(const QString &state) { - if(item == "State") { - if(value.variant().toString() == "offline") { - QConnmanTechnologyInterface tech(path); - disconnect(&tech,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(technologyPropertyChangedContext(QString,QString,QDBusVariant))); + QConnmanServiceInterface *service = qobject_cast(sender()); + configurationChange(service); - technologies.remove(path); - } + if (state == QStringLiteral("failure")) { + emit connectionError(service->path(), ConnectError); } } -void QConnmanEngine::configurationChange(const QString &id) +void QConnmanEngine::configurationChange(QConnmanServiceInterface *serv) { QMutexLocker locker(&mutex); + QString id = serv->path(); if (accessPointConfigurations.contains(id)) { bool changed = false; QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); - - QString servicePath = serviceFromId(id); - QConnmanServiceInterface *serv; - serv = new QConnmanServiceInterface(servicePath); - QString networkName = serv->getName(); - - QNetworkConfiguration::StateFlags curState = getStateForService(servicePath); - + QString networkName = serv->name(); + QNetworkConfiguration::StateFlags curState = getStateForService(serv->path()); ptr->mutex.lock(); if (!ptr->isValid) { @@ -414,26 +395,31 @@ void QConnmanEngine::configurationChange(const QString &id) QNetworkConfiguration::StateFlags QConnmanEngine::getStateForService(const QString &service) { QMutexLocker locker(&mutex); - QConnmanServiceInterface serv(service); + QConnmanServiceInterface *serv = connmanServiceInterfaces.value(service); + QString state = serv->state(); + QNetworkConfiguration::StateFlags flag = QNetworkConfiguration::Defined; - if (serv.getType() == "cellular") { - if (serv.isSetupRequired() || !serv.isAutoConnect() || (serv.isRoaming() && isAlwaysAskRoaming())) { - flag = ( flag | QNetworkConfiguration::Defined); + + if (serv->type() == QLatin1String("cellular")) { + + if (!serv->autoConnect() + || (serv->roaming() + && (isAlwaysAskRoaming() || !isRoamingAllowed(serv->path())))) { + flag = (flag | QNetworkConfiguration::Defined); } else { - flag = ( flag | QNetworkConfiguration::Discovered); + flag = (flag | QNetworkConfiguration::Discovered); } } else { - if (serv.isFavorite()) { - if (serv.isAutoConnect()) { - flag = ( flag | QNetworkConfiguration::Discovered); + if (serv->favorite()) { + if (serv->autoConnect()) { + flag = (flag | QNetworkConfiguration::Discovered); } } else { flag = QNetworkConfiguration::Undefined; } } - - if (serv.getState() == "ready" || serv.getState() == "online") { - flag = ( flag | QNetworkConfiguration::Active); + if (state == QLatin1String("online")) { + flag = (flag | QNetworkConfiguration::Active); } return flag; @@ -441,51 +427,35 @@ QNetworkConfiguration::StateFlags QConnmanEngine::getStateForService(const QStri QNetworkConfiguration::BearerType QConnmanEngine::typeToBearer(const QString &type) { - if (type == "wifi") + if (type == QLatin1String("wifi")) return QNetworkConfiguration::BearerWLAN; - if (type == "ethernet") + if (type == QLatin1String("ethernet")) return QNetworkConfiguration::BearerEthernet; - if (type == "bluetooth") + if (type == QLatin1String("bluetooth")) return QNetworkConfiguration::BearerBluetooth; - if (type == "cellular") { + if (type == QLatin1String("cellular")) { return ofonoTechToBearerType(type); } - if (type == "wimax") + if (type == QLatin1String("wimax")) return QNetworkConfiguration::BearerWiMAX; -// if(type == "gps") -// if(type == "vpn") - return QNetworkConfiguration::BearerUnknown; } QNetworkConfiguration::BearerType QConnmanEngine::ofonoTechToBearerType(const QString &/*type*/) { - QOfonoManagerInterface ofonoManager(this); - QOfonoNetworkRegistrationInterface ofonoNetwork(ofonoManager.currentModem().path(),this); - - if(ofonoNetwork.isValid()) { - foreach (const QDBusObjectPath &op,ofonoNetwork.getOperators() ) { - QOfonoNetworkOperatorInterface opIface(op.path(),this); - - foreach (const QString &opTech, opIface.getTechnologies()) { - - if(opTech == "gsm") { - return QNetworkConfiguration::Bearer2G; - } - if(opTech == "edge"){ - return QNetworkConfiguration::BearerCDMA2000; //wrong, I know - } - if(opTech == "umts"){ - return QNetworkConfiguration::BearerWCDMA; - } - if(opTech == "hspa"){ - return QNetworkConfiguration::BearerHSPA; - } - if(opTech == "lte"){ - return QNetworkConfiguration::BearerWiMAX; //not exact - } - } + if (ofonoNetwork) { + QString currentTechnology = ofonoNetwork->getTechnology(); + if (currentTechnology == QLatin1String("gsm")) { + return QNetworkConfiguration::Bearer2G; + } else if (currentTechnology == QLatin1String("edge")) { + return QNetworkConfiguration::BearerCDMA2000; //wrong, I know + } else if (currentTechnology == QLatin1String("umts")) { + return QNetworkConfiguration::BearerWCDMA; + } else if (currentTechnology == QLatin1String("hspa")) { + return QNetworkConfiguration::BearerHSPA; + } else if (currentTechnology == QLatin1String("lte")) { + return QNetworkConfiguration::BearerWiMAX; //not exact } } return QNetworkConfiguration::BearerUnknown; @@ -493,12 +463,9 @@ QNetworkConfiguration::BearerType QConnmanEngine::ofonoTechToBearerType(const QS bool QConnmanEngine::isRoamingAllowed(const QString &context) { - QOfonoManagerInterface ofonoManager(this); - QString modemPath = ofonoManager.currentModem().path(); - QOfonoDataConnectionManagerInterface dc(modemPath,this); - foreach (const QDBusObjectPath &dcPath,dc.getPrimaryContexts()) { - if(dcPath.path().contains(context.section("_",-1))) { - return dc.isRoamingAllowed(); + foreach (const QString &dcPath, ofonoContextManager->contexts()) { + if (dcPath.contains(context.section("_",-1))) { + return ofonoContextManager->roamingAllowed(); } } return false; @@ -510,14 +477,11 @@ void QConnmanEngine::removeConfiguration(const QString &id) if (accessPointConfigurations.contains(id)) { - QString service = serviceFromId(id); - QConnmanServiceInterface serv(service); - - disconnect(&serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(servicePropertyChangedContext(QString,QString,QDBusVariant))); - - serviceNetworks.removeOne(service); - + disconnect(connmanServiceInterfaces.value(id),SIGNAL(stateChanged(QString)), + this,SLOT(serviceStateChanged(QString))); + serviceNetworks.removeOne(id); + QConnmanServiceInterface *service = connmanServiceInterfaces.take(id); + delete service; QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(id); foundConfigurations.removeOne(ptr.data()); locker.unlock(); @@ -529,35 +493,32 @@ void QConnmanEngine::removeConfiguration(const QString &id) void QConnmanEngine::addServiceConfiguration(const QString &servicePath) { QMutexLocker locker(&mutex); - QConnmanServiceInterface *serv; - serv = new QConnmanServiceInterface(servicePath); + if (!connmanServiceInterfaces.contains(servicePath)) { + QConnmanServiceInterface *serv = new QConnmanServiceInterface(servicePath); + connmanServiceInterfaces.insert(serv->path(),serv); + } - const QString id = QString::number(qHash(servicePath)); + if (!accessPointConfigurations.contains(servicePath)) { - if (!accessPointConfigurations.contains(id)) { serviceNetworks.append(servicePath); - connect(serv,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SLOT(servicePropertyChangedContext(QString,QString,QDBusVariant))); + connect(connmanServiceInterfaces.value(servicePath),SIGNAL(stateChanged(QString)), + this,SLOT(serviceStateChanged(QString))); + QNetworkConfigurationPrivate* cpPriv = new QNetworkConfigurationPrivate(); + QConnmanServiceInterface *service = connmanServiceInterfaces.value(servicePath); - QString networkName = serv->getName(); + QString networkName = service->name(); - const QString connectionType = serv->getType(); - if (connectionType == "ethernet") { + const QString connectionType = service->type(); + if (connectionType == QLatin1String("ethernet")) { cpPriv->bearerType = QNetworkConfiguration::BearerEthernet; - } else if (connectionType == "wifi") { + } else if (connectionType == QLatin1String("wifi")) { cpPriv->bearerType = QNetworkConfiguration::BearerWLAN; - } else if (connectionType == "cellular") { - cpPriv->bearerType = ofonoTechToBearerType("cellular"); - if(servicePath.isEmpty()) { - networkName = serv->getAPN(); - if(networkName.isEmpty()) { - networkName = serv->getName(); - } - } - cpPriv->roamingSupported = isRoamingAllowed(servicePath); - } else if (connectionType == "wimax") { + } else if (connectionType == QLatin1String("cellular")) { + cpPriv->bearerType = ofonoTechToBearerType(QLatin1String("cellular")); + cpPriv->roamingSupported = service->roaming() && isRoamingAllowed(servicePath); + } else if (connectionType == QLatin1String("wimax")) { cpPriv->bearerType = QNetworkConfiguration::BearerWiMAX; } else { cpPriv->bearerType = QNetworkConfiguration::BearerUnknown; @@ -565,10 +526,10 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) cpPriv->name = networkName; cpPriv->isValid = true; - cpPriv->id = id; + cpPriv->id = servicePath; cpPriv->type = QNetworkConfiguration::InternetAccessPoint; - if(serv->getSecurity() == "none") { + if (service->security() == QStringLiteral("none")) { cpPriv->purpose = QNetworkConfiguration::PublicPurpose; } else { cpPriv->purpose = QNetworkConfiguration::PrivatePurpose; @@ -578,13 +539,16 @@ void QConnmanEngine::addServiceConfiguration(const QString &servicePath) QNetworkConfigurationPrivatePointer ptr(cpPriv); accessPointConfigurations.insert(ptr->id, ptr); - foundConfigurations.append(cpPriv); - configInterfaces[cpPriv->id] = serv->getInterface(); + if (connectionType == QLatin1String("cellular")) { + foundConfigurations.append(cpPriv); + } else { + foundConfigurations.prepend(cpPriv); + } + configInterfaces[cpPriv->id] = service->serviceInterface(); locker.unlock(); - emit configurationAdded(ptr); + Q_EMIT configurationAdded(ptr); locker.relock(); - emit updateCompleted(); } } @@ -595,10 +559,39 @@ bool QConnmanEngine::requiresPolling() const bool QConnmanEngine::isAlwaysAskRoaming() { - QSettings confFile(QStringLiteral("nemomobile"), QStringLiteral("connectionagent")); +#ifdef QT_HAS_CONNECTIONAGENT + QSettings confFile(QStringLiteral("nemomobile"),QStringLiteral("connectionagent")); confFile.beginGroup(QStringLiteral("Connectionagent")); return confFile.value(QStringLiteral("askForRoaming")).toBool(); +#else + return false; +#endif } + +void QConnmanEngine::reEvaluateCellular() +{ + Q_FOREACH (const QString &servicePath, connmanManager->getServices()) { + if (servicePath.contains("cellular") && accessPointConfigurations.contains(servicePath)) { + configurationChange(connmanServiceInterfaces.value(servicePath)); + } + } +} + +void QConnmanEngine::inotifyActivated() +{ +#ifdef QT_HAS_CONNECTIONAGENT + + char buffer[1024]; + int len = qt_safe_read(inotifyFileDescriptor, (void *)buffer, sizeof(buffer)); + if (len > 0) { + struct inotify_event *event = (struct inotify_event *)buffer; + if (event->wd == inotifyWatcher && (event->mask & IN_MODIFY) == 0) { + QTimer::singleShot(1000, this, SLOT(reEvaluateCellular())); //give this time to finish write + } + } +#endif +} + QT_END_NAMESPACE #endif // QT_NO_DBUS diff --git a/src/plugins/bearer/connman/qconnmanengine.h b/src/plugins/bearer/connman/qconnmanengine.h index 49a1a91d29..4a4e91659b 100644 --- a/src/plugins/bearer/connman/qconnmanengine.h +++ b/src/plugins/bearer/connman/qconnmanengine.h @@ -56,6 +56,7 @@ #include "../qbearerengine_impl.h" #include "qconnmanservice_linux_p.h" +#include "qofonoservice_linux_p.h" #include #include @@ -91,28 +92,32 @@ public: virtual quint64 bytesReceived(const QString &id); virtual quint64 startTime(const QString &id); - virtual QNetworkConfigurationManager::Capabilities capabilities() const; virtual QNetworkConfigurationPrivatePointer defaultConfiguration(); - void configurationChange(const QString &id); QList getConfigurations(); - private Q_SLOTS: void doRequestUpdate(); - void servicePropertyChangedContext(const QString &,const QString &,const QDBusVariant &); - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); - void technologyPropertyChangedContext(const QString &,const QString &, const QDBusVariant &); void updateServices(const ConnmanMapList &changed, const QList &removed); + void servicesReady(const QStringList &); + void finishedScan(); + void changedModem(); + void serviceStateChanged(const QString &state); + void configurationChange(QConnmanServiceInterface * service); + void reEvaluateCellular(); + void inotifyActivated(); private: QConnmanManagerInterface *connmanManager; + QOfonoManagerInterface *ofonoManager; + QOfonoNetworkRegistrationInterface *ofonoNetwork; + QOfonoDataConnectionManagerInterface *ofonoContextManager; + QList foundConfigurations; - QString serviceFromId(const QString &id); QString networkFromId(const QString &id); QNetworkConfiguration::StateFlags getStateForService(const QString &service); @@ -130,6 +135,11 @@ private: QNetworkConfiguration::BearerType ofonoTechToBearerType(const QString &type); bool isRoamingAllowed(const QString &context); bool isAlwaysAskRoaming(); + QMap connmanServiceInterfaces; + + int inotifyWatcher; + int inotifyFileDescriptor; + protected: bool requiresPolling() const; }; diff --git a/src/plugins/bearer/connman/qconnmanservice_linux.cpp b/src/plugins/bearer/connman/qconnmanservice_linux.cpp index 6d9ee265c6..46b24f77dd 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux.cpp +++ b/src/plugins/bearer/connman/qconnmanservice_linux.cpp @@ -75,708 +75,380 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &map) } QConnmanManagerInterface::QConnmanManagerInterface( QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), - QLatin1String(CONNMAN_MANAGER_PATH), + : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), CONNMAN_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); -} -QConnmanManagerInterface::~QConnmanManagerInterface() -{ -} + QList argumentList; + QDBusPendingReply props_reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(props_reply, this); -void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged); - if (signal == propertyChangedSignal) { - if(!connection().connect(QLatin1String(CONNMAN_SERVICE), - QLatin1String(CONNMAN_MANAGER_PATH), - QLatin1String(CONNMAN_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { - qWarning() << "PropertyChanged not connected"; - } - } + QObject::connect(watcher,SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(propertiesReply(QDBusPendingCallWatcher*))); - static const QMetaMethod stateChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::stateChanged); - if (signal == stateChangedSignal) { - if (!connection().connect(QLatin1String(CONNMAN_SERVICE), - QLatin1String(CONNMAN_MANAGER_PATH), - QLatin1String(CONNMAN_MANAGER_INTERFACE), - QLatin1String("StateChanged"), - this,SIGNAL(stateChanged(QString)))) { - qWarning() << "StateChanged not connected"; + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), + QStringLiteral(CONNMAN_SERVICE_INTERFACE), + QStringLiteral("PropertyChanged"), + this,SLOT(changedProperty(QString,QDBusVariant))); - } - } - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QConnmanDBusHelper *helper; - helper = new QConnmanDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - QLatin1String(CONNMAN_MANAGER_PATH), - QLatin1String(CONNMAN_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), + QStringLiteral(CONNMAN_SERVICE_INTERFACE), + QStringLiteral("TechnologyAdded"), + this,SLOT(technologyAdded(QDBusObjectPath,QVariantMap))); - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); - } - static const QMetaMethod servicesChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::servicesChanged); - if (signal == servicesChangedSignal) { - if (!connection().connect(QLatin1String(CONNMAN_SERVICE), - QLatin1String(CONNMAN_MANAGER_PATH), - QLatin1String(CONNMAN_MANAGER_INTERFACE), - QLatin1String("ServicesChanged"), - this,SLOT(onServicesChanged(ConnmanMapList, QList)))) { - qWarning() << "servicesChanged not connected"; - } - } -} - -void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList &removed) -{ - emit servicesChanged(changed, removed); -} - - -void QConnmanManagerInterface::disconnectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged); - if (signal == propertyChangedSignal) { - - } -} - -QVariant QConnmanManagerInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << "does not contain" << property; - } - return var; -} - -QVariantMap QConnmanManagerInterface::getProperties() -{ - if(this->isValid()) { - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); - } else return QVariantMap(); -} + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), + QStringLiteral(CONNMAN_SERVICE_INTERFACE), + QStringLiteral("TechnologyRemoved"), + this,SLOT(technologyRemoved(QDBusObjectPath))); -QString QConnmanManagerInterface::getState() -{ - QDBusReply reply = this->call("GetState"); - return reply.value(); -} + QList argumentList2; + QDBusPendingReply serv_reply = asyncCallWithArgumentList(QLatin1String("GetServices"), argumentList2); + QDBusPendingCallWatcher *watcher2 = new QDBusPendingCallWatcher(serv_reply, this); -bool QConnmanManagerInterface::setProperty(const QString &name, const QDBusVariant &value) -{ - Q_UNUSED(name); - Q_UNUSED(value); - return false; -} + QObject::connect(watcher2,SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(servicesReply(QDBusPendingCallWatcher*))); -QDBusObjectPath QConnmanManagerInterface::createProfile(const QString &/*name*/) -{ - return QDBusObjectPath(); } -bool QConnmanManagerInterface::removeProfile(QDBusObjectPath /*path*/) +QConnmanManagerInterface::~QConnmanManagerInterface() { - return false; } -bool QConnmanManagerInterface::requestScan(const QString &type) +void QConnmanManagerInterface::changedProperty(const QString &name, const QDBusVariant &value) { - QDBusReply reply = this->call(QLatin1String("RequestScan"), QVariant::fromValue(type)); - - bool ok = true; - if(reply.error().type() == QDBusError::InvalidArgs) { - qWarning() << reply.error().message(); - ok = false; - } - return ok; + propertiesCacheMap[name] = value.variant(); } -bool QConnmanManagerInterface::enableTechnology(const QString &type) +void QConnmanManagerInterface::propertiesReply(QDBusPendingCallWatcher *call) { - QDBusReply > reply = this->call(QLatin1String("EnableTechnology"), QVariant::fromValue(type)); - bool ok = true; - if(reply.error().type() == QDBusError::InvalidArgs) { - qWarning() << reply.error().message(); - ok = false; - } - return ok; -} + QDBusPendingReply props_reply = *call; -bool QConnmanManagerInterface::disableTechnology(const QString &type) -{ - QDBusReply > reply = this->call(QLatin1String("DisableTechnology"), QVariant::fromValue(type)); - bool ok = true; - if(reply.error().type() == QDBusError::InvalidArgs) { - qWarning() << reply.error().message(); - ok = false; + if (props_reply.isError()) { + qDebug() << props_reply.error().message(); + } else { + propertiesCacheMap = props_reply.value(); } - return ok; + call->deleteLater(); } -QDBusObjectPath QConnmanManagerInterface::connectService(QVariantMap &map) +void QConnmanManagerInterface::servicesReply(QDBusPendingCallWatcher *call) { - QDBusReply reply = this->call(QLatin1String("ConnectService"), QVariant::fromValue(map)); - if(!reply.isValid()) { - qDebug() << reply.error().message(); + QDBusPendingReply serv_reply = *call; + if (serv_reply.isError()) { + qDebug() << serv_reply.error().message(); + } else { + servicesList.clear(); //connman list changes order + ConnmanMap connmanobj; + Q_FOREACH (connmanobj, serv_reply.value()) { + servicesList << connmanobj.objectPath.path(); + } + Q_EMIT servicesReady(servicesList); } - return reply; + call->deleteLater(); } -void QConnmanManagerInterface::registerAgent(QDBusObjectPath &/*path*/) -{ -} - -void QConnmanManagerInterface::unregisterAgent(QDBusObjectPath /*path*/) +void QConnmanManagerInterface::connectNotify(const QMetaMethod &signal) { -} - -void QConnmanManagerInterface::registerCounter(const QString &path, quint32 interval) -{ QDBusReply > reply = this->call(QLatin1String("RegisterCounter"), - QVariant::fromValue(path), - QVariant::fromValue(interval)); - if(reply.error().type() == QDBusError::InvalidArgs) { - qWarning() << reply.error().message(); + static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::propertyChanged); + if (signal == propertyChangedSignal) { + if (!connection().connect(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), + QStringLiteral(CONNMAN_MANAGER_INTERFACE), + QStringLiteral("PropertyChanged"), + this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { + qWarning() << "PropertyChanged not connected"; + } } -} -void QConnmanManagerInterface::unregisterCounter(const QString &path) -{ QDBusReply > reply = this->call(QLatin1String("UnregisterCounter"), - QVariant::fromValue(path)); - if(reply.error().type() == QDBusError::InvalidArgs) { - qWarning() << reply.error().message(); + static const QMetaMethod servicesChangedSignal = QMetaMethod::fromSignal(&QConnmanManagerInterface::servicesChanged); + if (signal == servicesChangedSignal) { + if (!connection().connect(QStringLiteral(CONNMAN_SERVICE), + QStringLiteral(CONNMAN_MANAGER_PATH), + QStringLiteral(CONNMAN_MANAGER_INTERFACE), + QStringLiteral("ServicesChanged"), + this,SLOT(onServicesChanged(ConnmanMapList, QList)))) { + qWarning() << "servicesChanged not connected"; + } } } -QString QConnmanManagerInterface::requestSession(const QString &bearerName) -{ - QDBusReply > reply = this->call(QLatin1String("RequestSession"), - QVariant::fromValue(bearerName)); - return QString(); -} - -void QConnmanManagerInterface::releaseSession() -{ - QDBusReply > reply = this->call(QLatin1String("ReleaseSession")); -} - - -QDBusObjectPath QConnmanManagerInterface::lookupService(const QString &service) +void QConnmanManagerInterface::onServicesChanged(const ConnmanMapList &changed, const QList &removed) { - QDBusReply reply = this->call(QLatin1String("LookupService"), QVariant::fromValue(service)); - if(!reply.isValid()) { - qDebug() << reply.error().message(); + ConnmanMap connmanobj; + servicesList.clear(); //connman list changes order + Q_FOREACH (connmanobj, changed) { + const QString svcPath(connmanobj.objectPath.path()); + servicesList << svcPath; } - return reply; -} -// properties - -QStringList QConnmanManagerInterface::getAvailableTechnologies() -{ - QVariant var = getProperty("AvailableTechnologies"); - return qdbus_cast(var); + Q_EMIT servicesChanged(changed, removed); } -QStringList QConnmanManagerInterface::getEnabledTechnologies() +QVariant QConnmanManagerInterface::getProperty(const QString &property) { - QVariant var = getProperty("EnabledTechnologies"); - return qdbus_cast(var); + QVariant var; + var = propertiesCacheMap.value(property); + return var; } -QStringList QConnmanManagerInterface::getConnectedTechnologies() +QVariantMap QConnmanManagerInterface::getProperties() { - QVariant var = getProperty("ConnectedTechnologies"); - return qdbus_cast(var); + if (propertiesCacheMap.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetProperties")); + reply.waitForFinished(); + if (!reply.isError()) { + propertiesCacheMap = reply.value(); + } + } + return propertiesCacheMap; } -QString QConnmanManagerInterface::getDefaultTechnology() +QString QConnmanManagerInterface::getState() { - QVariant var = getProperty("DefaultTechnology"); - return qdbus_cast(var); + return getProperty(QStringLiteral("State")).toString(); } bool QConnmanManagerInterface::getOfflineMode() { - QVariant var = getProperty("OfflineMode"); + QVariant var = getProperty(QStringLiteral("OfflineMode")); return qdbus_cast(var); } -QString QConnmanManagerInterface::getActiveProfile() -{ - QVariant var = getProperty("ActiveProfile"); - return qdbus_cast(var); -} - -QStringList QConnmanManagerInterface::getProfiles() -{ - QVariant var = getProperty("Profiles"); - return qdbus_cast(var); -} - QStringList QConnmanManagerInterface::getTechnologies() { - QStringList list; - QDBusReply replyList = this->call(QLatin1String("GetTechnologies")); - if (replyList.isValid()) { - Q_FOREACH (ConnmanMap map, replyList.value()) { - list << map.objectPath.path(); - } - } else { - // try for older version - QVariant var = getProperty("Technologies"); - if (!var.isNull()) { - list = qdbus_cast(var); + if (technologiesMap.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetTechnologies")); + reply.waitForFinished(); + if (!reply.isError()) { + Q_FOREACH (ConnmanMap map, reply.value()) { + if (!technologiesMap.contains(map.objectPath.path())) { + technologyAdded(map.objectPath, map.propertyMap); + } + } } } - return list; + return technologiesMap.keys(); } QStringList QConnmanManagerInterface::getServices() { - QStringList list; - QDBusReply replyList = this->call(QLatin1String("GetServices")); - if (replyList.isValid()) { - Q_FOREACH (ConnmanMap map, replyList.value()) { - list << map.objectPath.path(); - } - } else { - QVariant var = getProperty("Services"); - if (!var.isNull()) { - list = qdbus_cast(var); + if (servicesList.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetServices")); + reply.waitForFinished(); + if (!reply.isError()) { + Q_FOREACH (ConnmanMap map, reply.value()) { + servicesList << map.objectPath.path(); + } } } - return list; + return servicesList; } -QString QConnmanManagerInterface::getPathForTechnology(const QString &name) +void QConnmanManagerInterface::requestScan(const QString &type) { - foreach (const QString &path, getTechnologies()) { - if(path.contains(name)) { - return path; + Q_FOREACH (QConnmanTechnologyInterface *tech, technologiesMap) { + if (tech->type() == type) { + tech->scan(); } } - return ""; -} - - -////////////////////////// -QConnmanProfileInterface::QConnmanProfileInterface(const QString &dbusPathName,QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), - dbusPathName, - CONNMAN_PROFILE_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QConnmanProfileInterface::~QConnmanProfileInterface() -{ } -void QConnmanProfileInterface::connectNotify(const QMetaMethod &signal) +void QConnmanManagerInterface::technologyAdded(const QDBusObjectPath &path, const QVariantMap &) { - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanProfileInterface::propertyChanged); - if (signal == propertyChangedSignal) { - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - this->path(), - QLatin1String(CONNMAN_PROFILE_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant))); + if (!technologiesList.contains(path.path())) { + technologiesList << path.path(); + QConnmanTechnologyInterface *tech; + tech = new QConnmanTechnologyInterface(path.path(),this); + technologiesMap.insert(path.path(),tech); + connect(tech,SIGNAL(scanFinished()),this,SIGNAL(scanFinished())); } } -void QConnmanProfileInterface::disconnectNotify(const QMetaMethod &signal) +void QConnmanManagerInterface::technologyRemoved(const QDBusObjectPath &path) { - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanProfileInterface::propertyChanged); - if (signal == propertyChangedSignal) { - + if (technologiesList.contains(path.path())) { + technologiesList.removeOne(path.path()); + QConnmanTechnologyInterface * tech = technologiesMap.take(path.path()); + delete tech; } } -QVariantMap QConnmanProfileInterface::getProperties() +QConnmanServiceInterface::QConnmanServiceInterface(const QString &dbusPathName,QObject *parent) + : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE), + dbusPathName, + CONNMAN_SERVICE_INTERFACE, + QDBusConnection::systemBus(), parent) { - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} + QList argumentList; + QDBusPendingReply props_reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); -QVariant QConnmanProfileInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } - return var; -} + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(props_reply, this); -// properties -QString QConnmanProfileInterface::getName() -{ + QObject::connect(watcher,SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(propertiesReply(QDBusPendingCallWatcher*))); - QVariant var = getProperty("Name"); - return qdbus_cast(var); + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + path(), + QStringLiteral(CONNMAN_SERVICE_INTERFACE), + QStringLiteral("PropertyChanged"), + this,SLOT(changedProperty(QString,QDBusVariant))); } -bool QConnmanProfileInterface::isOfflineMode() -{ - QVariant var = getProperty("OfflineMode"); - return qdbus_cast(var); -} - -QStringList QConnmanProfileInterface::getServices() +QConnmanServiceInterface::~QConnmanServiceInterface() { - QVariant var = getProperty("Services"); - return qdbus_cast(var); } - -/////////////////////////// -QConnmanServiceInterface::QConnmanServiceInterface(const QString &dbusPathName,QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), - dbusPathName, - CONNMAN_SERVICE_INTERFACE, - QDBusConnection::systemBus(), parent) +QVariantMap QConnmanServiceInterface::getProperties() { + if (propertiesCacheMap.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetProperties")); + reply.waitForFinished(); + if (!reply.isError()) { + propertiesCacheMap = reply.value(); + Q_EMIT propertiesReady(); + } + } + return propertiesCacheMap; } -QConnmanServiceInterface::~QConnmanServiceInterface() +void QConnmanServiceInterface::propertiesReply(QDBusPendingCallWatcher *call) { + QDBusPendingReply props_reply = *call; + if (props_reply.isError()) { + qDebug() << props_reply.error().message(); + return; + } + propertiesCacheMap = props_reply.value(); + Q_EMIT propertiesReady(); } void QConnmanServiceInterface::connectNotify(const QMetaMethod &signal) { static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChanged); if (signal == propertyChangedSignal) { - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - this->path(), - QLatin1String(CONNMAN_SERVICE_INTERFACE), - QLatin1String("PropertyChanged"), + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + path(), + QStringLiteral(CONNMAN_SERVICE_INTERFACE), + QStringLiteral("PropertyChanged"), this,SIGNAL(propertyChanged(QString,QDBusVariant))); } - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QConnmanDBusHelper *helper; - helper = new QConnmanDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - this->path(), - QLatin1String(CONNMAN_SERVICE_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); - } -} - -void QConnmanServiceInterface::disconnectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanServiceInterface::propertyChanged); - if (signal == propertyChangedSignal) { - - } } -QVariantMap QConnmanServiceInterface::getProperties() +void QConnmanServiceInterface::changedProperty(const QString &name, const QDBusVariant &value) { - if(this->isValid()) { - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); - } - else - return QVariantMap(); + propertiesCacheMap[name] = value.variant(); + if (name == QStringLiteral("State")) + Q_EMIT stateChanged(value.variant().toString()); } QVariant QConnmanServiceInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } + var = map.value(property); return var; } void QConnmanServiceInterface::connect() { - this->asyncCall(QLatin1String("Connect")); + asyncCall(QLatin1String("Connect")); } void QConnmanServiceInterface::disconnect() { - QDBusReply reply = this->call(QLatin1String("Disconnect")); + asyncCall(QLatin1String("Disconnect")); } void QConnmanServiceInterface::remove() { - QDBusReply reply = this->call(QLatin1String("Remove")); + asyncCall(QLatin1String("Remove")); } // properties -QString QConnmanServiceInterface::getState() +QString QConnmanServiceInterface::state() { - QVariant var = getProperty("State"); + QVariant var = getProperty(QStringLiteral("State")); return qdbus_cast(var); } -QString QConnmanServiceInterface::getError() +QString QConnmanServiceInterface::lastError() { - QVariant var = getProperty("Error"); + QVariant var = getProperty(QStringLiteral("Error")); return qdbus_cast(var); } -QString QConnmanServiceInterface::getName() +QString QConnmanServiceInterface::name() { - QVariant var = getProperty("Name"); + QVariant var = getProperty(QStringLiteral("Name")); return qdbus_cast(var); } -QString QConnmanServiceInterface::getType() +QString QConnmanServiceInterface::type() { - QVariant var = getProperty("Type"); + QVariant var = getProperty(QStringLiteral("Type")); return qdbus_cast(var); } -QString QConnmanServiceInterface::getMode() +QString QConnmanServiceInterface::security() { - QVariant var = getProperty("Mode"); + QVariant var = getProperty(QStringLiteral("Security")); return qdbus_cast(var); } -QString QConnmanServiceInterface::getSecurity() +bool QConnmanServiceInterface::favorite() { - QVariant var = getProperty("Security"); - return qdbus_cast(var); -} - -QString QConnmanServiceInterface::getPassphrase() -{ - QVariant var = getProperty("Passphrase"); - return qdbus_cast(var); -} - -bool QConnmanServiceInterface::isPassphraseRequired() -{ - QVariant var = getProperty("PassphraseRequired"); - return qdbus_cast(var); -} - -quint8 QConnmanServiceInterface::getSignalStrength() -{ - QVariant var = getProperty("Strength"); - return qdbus_cast(var); -} - -bool QConnmanServiceInterface::isFavorite() -{ - QVariant var = getProperty("Favorite"); + QVariant var = getProperty(QStringLiteral("Favorite")); return qdbus_cast(var); } -bool QConnmanServiceInterface::isImmutable() +bool QConnmanServiceInterface::autoConnect() { - QVariant var = getProperty("Immutable"); + QVariant var = getProperty(QStringLiteral("AutoConnect")); return qdbus_cast(var); } -bool QConnmanServiceInterface::isAutoConnect() +bool QConnmanServiceInterface::roaming() { - QVariant var = getProperty("AutoConnect"); + QVariant var = getProperty(QStringLiteral("Roaming")); return qdbus_cast(var); } -bool QConnmanServiceInterface::isSetupRequired() -{ - QVariant var = getProperty("SetupRequired"); - return qdbus_cast(var); -} - -QString QConnmanServiceInterface::getAPN() -{ - QVariant var = getProperty("APN"); - return qdbus_cast(var); -} - -QString QConnmanServiceInterface::getMCC() -{ - QVariant var = getProperty("MCC"); - return qdbus_cast(var); -} - -QString QConnmanServiceInterface::getMNC() -{ - QVariant var = getProperty("MNC"); - return qdbus_cast(var); -} - -bool QConnmanServiceInterface::isRoaming() -{ - QVariant var = getProperty("Roaming"); - return qdbus_cast(var); -} - -QStringList QConnmanServiceInterface::getNameservers() -{ - QVariant var = getProperty("NameServers"); - return qdbus_cast(var); -} - -QStringList QConnmanServiceInterface::getDomains() -{ - QVariant var = getProperty("Domains"); - return qdbus_cast(var); -} - -QVariantMap QConnmanServiceInterface::getIPv4() +QVariantMap QConnmanServiceInterface::ethernet() { - QVariant var = getProperty("IPv4"); + QVariant var = getProperty(QStringLiteral("Ethernet")); return qdbus_cast(var); } -QVariantMap QConnmanServiceInterface::getIPv4Configuration() -{ - QVariant var = getProperty("IPv4.Configuration"); - return qdbus_cast(var); -} - -QVariantMap QConnmanServiceInterface::getProxy() -{ - QVariant var = getProperty("Proxy"); - return qdbus_cast(var); -} - -QVariantMap QConnmanServiceInterface::getEthernet() -{ - QVariant var = getProperty("Ethernet"); - return qdbus_cast(var); -} - -QString QConnmanServiceInterface::getMethod() -{ - QVariant var; - QVariantMap map = getEthernet(); - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "Method") { - return it.value().toString(); - } - } - return QString(); -} - -QString QConnmanServiceInterface::getInterface() -{ - QVariant var; - QVariantMap map = getEthernet(); - - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "Interface") { - return it.value().toString(); - } - } - - return QString(); -} - -QString QConnmanServiceInterface::getMacAddress() -{ - QVariant var; - QVariantMap map = getEthernet(); - - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "Address") { - return it.value().toString(); - } - } - return QString(); -} - -quint16 QConnmanServiceInterface::getMtu() -{ - quint16 mtu=0; - QVariant var; - QVariantMap map = getEthernet(); - - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "MTU") { - return it.value().toUInt(); - } - } - return mtu; -} - -quint16 QConnmanServiceInterface::getSpeed() +QString QConnmanServiceInterface::serviceInterface() { - quint16 speed=0; - QVariant var; - QVariantMap map = getEthernet(); - - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "Speed") { - return it.value().toUInt(); - } - } - return speed; + QVariantMap map = ethernet(); + return map.value(QStringLiteral("Interface")).toString(); } -QString QConnmanServiceInterface::getDuplex() -{ - QVariant var; - QVariantMap map = getEthernet(); - - QMapIterator it(map); - while(it.hasNext()) { - it.next(); - if(it.key() == "Duplex") { - return it.value().toString(); - } - } - return QString(); -} - - bool QConnmanServiceInterface::isOfflineMode() { - QVariant var = getProperty("OfflineMode"); + QVariant var = getProperty(QStringLiteral("OfflineMode")); return qdbus_cast(var); } -QStringList QConnmanServiceInterface::getServices() +QStringList QConnmanServiceInterface::services() { - QVariant var = getProperty("Services"); + QVariant var = getProperty(QStringLiteral("Services")); return qdbus_cast(var); } - ////////////////////////// QConnmanTechnologyInterface::QConnmanTechnologyInterface(const QString &dbusPathName,QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), + : QDBusAbstractInterface(QStringLiteral(CONNMAN_SERVICE), dbusPathName, CONNMAN_TECHNOLOGY_INTERFACE, QDBusConnection::systemBus(), parent) @@ -791,154 +463,52 @@ void QConnmanTechnologyInterface::connectNotify(const QMetaMethod &signal) { static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChanged); if (signal == propertyChangedSignal) { - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - this->path(), - QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE), - QLatin1String("PropertyChanged"), + QDBusConnection::systemBus().connect(QStringLiteral(CONNMAN_SERVICE), + path(), + QStringLiteral(CONNMAN_TECHNOLOGY_INTERFACE), + QStringLiteral("PropertyChanged"), this,SIGNAL(propertyChanged(QString,QDBusVariant))); } - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QConnmanDBusHelper *helper; - helper = new QConnmanDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(CONNMAN_SERVICE), - this->path(), - QLatin1String(CONNMAN_TECHNOLOGY_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); - } } -void QConnmanTechnologyInterface::disconnectNotify(const QMetaMethod &signal) +QVariantMap QConnmanTechnologyInterface::properties() { - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QConnmanTechnologyInterface::propertyChanged); - if (signal == propertyChangedSignal) { - + if (propertiesMap.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetProperties")); + reply.waitForFinished(); + propertiesMap = reply.value(); } -} - -QVariantMap QConnmanTechnologyInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); + return propertiesMap; } QVariant QConnmanTechnologyInterface::getProperty(const QString &property) { QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } + QVariantMap map = properties(); + var = map.value(property); return var; } -// properties -QString QConnmanTechnologyInterface::getState() -{ - QVariant var = getProperty("State"); - return qdbus_cast(var); -} - -QString QConnmanTechnologyInterface::getName() -{ - QVariant var = getProperty("Name"); - return qdbus_cast(var); -} - -QString QConnmanTechnologyInterface::getType() +QString QConnmanTechnologyInterface::type() { - QVariant var = getProperty("Type"); + QVariant var = getProperty(QStringLiteral("Type")); return qdbus_cast(var); } - -////////////////////////////////// -QConnmanAgentInterface::QConnmanAgentInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), - dbusPathName, - CONNMAN_AGENT_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QConnmanAgentInterface::~QConnmanAgentInterface() -{ -} - -void QConnmanAgentInterface::connectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -} - -void QConnmanAgentInterface::disconnectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -} - - -void QConnmanAgentInterface::release() -{ -} - -void QConnmanAgentInterface::reportError(QDBusObjectPath &/*path*/, const QString &/*error*/) -{ -} - -void QConnmanAgentInterface::cancel() -{ -} - - -///////////////////////////////////////// -QConnmanCounterInterface::QConnmanCounterInterface(const QString &dbusPathName,QObject *parent) - : QDBusAbstractInterface(QLatin1String(CONNMAN_SERVICE), - dbusPathName, - CONNMAN_COUNTER_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QConnmanCounterInterface::~QConnmanCounterInterface() -{ -} - -quint32 QConnmanCounterInterface::getReceivedByteCount() -{ - return 0; -} - -quint32 QConnmanCounterInterface::getTransmittedByteCount() -{ - return 0; -} - -quint64 QConnmanCounterInterface::getTimeOnline() -{ - return 0; -} - -///////////////////////////////////////// -QConnmanDBusHelper::QConnmanDBusHelper(QObject * parent) - : QObject(parent) -{ -} - -QConnmanDBusHelper::~QConnmanDBusHelper() +void QConnmanTechnologyInterface::scan() { + QDBusPendingReply<> reply = asyncCall(QLatin1String("Scan")); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), + this, SLOT(scanReply(QDBusPendingCallWatcher*))); } -void QConnmanDBusHelper::propertyChanged(const QString &item, const QDBusVariant &var) +void QConnmanTechnologyInterface::scanReply(QDBusPendingCallWatcher *call) { - QDBusMessage msg = this->message(); - Q_EMIT propertyChangedContext(msg.path() ,item, var); + Q_EMIT scanFinished(); + call->deleteLater(); } -///////////////// QT_END_NAMESPACE #endif // QT_NO_DBUS diff --git a/src/plugins/bearer/connman/qconnmanservice_linux_p.h b/src/plugins/bearer/connman/qconnmanservice_linux_p.h index 6996fef5a7..250f90e2d0 100644 --- a/src/plugins/bearer/connman/qconnmanservice_linux_p.h +++ b/src/plugins/bearer/connman/qconnmanservice_linux_p.h @@ -73,19 +73,9 @@ #define CONNMAN_SERVICE "net.connman" #define CONNMAN_PATH "/net/connman" - -#define CONNMAN_DEBUG_INTERFACE CONNMAN_SERVICE ".Debug" -#define CONNMAN_ERROR_INTERFACE CONNMAN_SERVICE ".Error" -#define CONNMAN_AGENT_INTERFACE CONNMAN_SERVICE ".Agent" -#define CONNMAN_COUNTER_INTERFACE CONNMAN_SERVICE ".Counter" - -#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" -#define CONNMAN_MANAGER_PATH "/" - -#define CONNMAN_TASK_INTERFACE CONNMAN_SERVICE ".Task" -#define CONNMAN_PROFILE_INTERFACE CONNMAN_SERVICE ".Profile" -#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" -#define CONNMAN_PROVIDER_INTERFACE CONNMAN_SERVICE ".Provider" +#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" +#define CONNMAN_MANAGER_PATH "/" +#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" #define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology" #endif @@ -108,6 +98,9 @@ QT_BEGIN_NAMESPACE QDBusArgument &operator<<(QDBusArgument &argument, const ConnmanMap &obj); const QDBusArgument &operator>>(const QDBusArgument &argument, ConnmanMap &obj); +class QConnmanTechnologyInterface; +class QConnmanServiceInterface; + class QConnmanManagerInterface : public QDBusAbstractInterface { Q_OBJECT @@ -117,39 +110,16 @@ public: QConnmanManagerInterface( QObject *parent = 0); ~QConnmanManagerInterface(); - QDBusObjectPath path() const; - + QDBusObjectPath path() const; QVariantMap getProperties(); - bool setProperty(const QString &name, const QDBusVariant &value); - QDBusObjectPath createProfile(const QString &name); - bool removeProfile(QDBusObjectPath path); - bool requestScan(const QString &type); - bool enableTechnology(const QString &type); - bool disableTechnology(const QString &type); - QDBusObjectPath connectService(QVariantMap &map); - void registerAgent(QDBusObjectPath &path); - void unregisterAgent(QDBusObjectPath path); - void registerCounter(const QString &path, quint32 interval); - void unregisterCounter(const QString &path); - - QString requestSession(const QString &bearerName); - void releaseSession(); - - // properties + QString getState(); - QStringList getAvailableTechnologies(); - QStringList getEnabledTechnologies(); - QStringList getConnectedTechnologies(); - QString getDefaultTechnology(); bool getOfflineMode(); - QString getActiveProfile(); - QStringList getProfiles(); - QStringList getTechnologies(); + QStringList getTechnologies(); QStringList getServices(); - QDBusObjectPath lookupService(const QString &); - - QString getPathForTechnology(const QString &tech); + void requestScan(const QString &type); + QHash technologiesMap; Q_SIGNALS: void propertyChanged(const QString &, const QDBusVariant &value); @@ -157,41 +127,28 @@ Q_SIGNALS: void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); void servicesChanged(const ConnmanMapList&, const QList &); + void servicesReady(const QStringList &); + void scanFinished(); + protected: void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); QVariant getProperty(const QString &); +private: + QVariantMap propertiesCacheMap; + QStringList servicesList; + QStringList technologiesList; + private slots: void onServicesChanged(const ConnmanMapList&, const QList &); + void changedProperty(const QString &, const QDBusVariant &value); -}; - -class QConnmanProfileInterfacePrivate; -class QConnmanProfileInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: + void propertiesReply(QDBusPendingCallWatcher *call); + void servicesReply(QDBusPendingCallWatcher *call); - explicit QConnmanProfileInterface(const QString &dbusPathName,QObject *parent = 0); - ~QConnmanProfileInterface(); + void technologyAdded(const QDBusObjectPath &technology, const QVariantMap &properties); + void technologyRemoved(const QDBusObjectPath &technology); - QVariantMap getProperties(); -// properties - QString getName(); - bool isOfflineMode(); - QStringList getServices(); - -Q_SIGNALS: - void propertyChanged(const QString &, const QDBusVariant &value); -private: - QConnmanProfileInterfacePrivate *d; - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); }; class QConnmanServiceInterface : public QDBusAbstractInterface @@ -208,52 +165,37 @@ public: void connect(); void disconnect(); void remove(); - // void moveBefore(QDBusObjectPath &service); - // void moveAfter(QDBusObjectPath &service); // properties - QString getState(); - QString getError(); - QString getName(); - QString getType(); - QString getMode(); - QString getSecurity(); - QString getPassphrase(); - bool isPassphraseRequired(); - quint8 getSignalStrength(); - bool isFavorite(); - bool isImmutable(); - bool isAutoConnect(); - bool isSetupRequired(); - QString getAPN(); - QString getMCC(); - QString getMNC(); - bool isRoaming(); - QStringList getNameservers(); - QStringList getDomains(); - QVariantMap getIPv4(); - QVariantMap getIPv4Configuration(); - QVariantMap getProxy(); - QVariantMap getEthernet(); - - QString getMethod(); - QString getInterface(); - QString getMacAddress(); - quint16 getMtu(); - quint16 getSpeed(); - QString getDuplex(); + QString state(); + QString lastError(); + QString name(); + QString type(); + QString security(); + bool favorite(); + bool autoConnect(); + bool roaming(); + QVariantMap ethernet(); + QString serviceInterface(); bool isOfflineMode(); - QStringList getServices(); + QStringList services(); Q_SIGNALS: void propertyChanged(const QString &, const QDBusVariant &value); void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void propertiesReady(); + void stateChanged(const QString &state); protected: void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); QVariant getProperty(const QString &); +private: + QVariantMap propertiesCacheMap; +private slots: + void propertiesReply(QDBusPendingCallWatcher *call); + void changedProperty(const QString &, const QDBusVariant &value); + }; class QConnmanTechnologyInterface : public QDBusAbstractInterface @@ -265,72 +207,21 @@ public: explicit QConnmanTechnologyInterface(const QString &dbusPathName,QObject *parent = 0); ~QConnmanTechnologyInterface(); - QVariantMap getProperties(); -// properties - QString getState(); - QString getName(); - QString getType(); + QString type(); + void scan(); Q_SIGNALS: void propertyChanged(const QString &, const QDBusVariant &value); void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + void scanFinished(); protected: void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); QVariant getProperty(const QString &); - -}; - -class QConnmanAgentInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: - - explicit QConnmanAgentInterface(const QString &dbusPathName,QObject *parent = 0); - ~QConnmanAgentInterface(); - - void release(); - void reportError(QDBusObjectPath &path, const QString &error); -// dict requestInput(QDBusObjectPath &path, dict fields); - void cancel(); -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); -}; - -class QConnmanCounterInterfacePrivate; -class QConnmanCounterInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: - - explicit QConnmanCounterInterface(const QString &dbusPathName, QObject *parent = 0); - ~QConnmanCounterInterface(); - -// void release(); - QString getInterface(); - quint32 getReceivedByteCount(); - quint32 getTransmittedByteCount(); - quint64 getTimeOnline(); - private: - QConnmanCounterInterfacePrivate *d; -}; - -class QConnmanDBusHelper: public QObject, protected QDBusContext - { - Q_OBJECT - public: - QConnmanDBusHelper(QObject *parent = 0); - ~QConnmanDBusHelper(); + QVariantMap properties(); + QVariantMap propertiesMap; + void scanReply(QDBusPendingCallWatcher *call); - public slots: - void propertyChanged(const QString &, const QDBusVariant &); - -Q_SIGNALS: - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/connman/qofonoservice_linux.cpp b/src/plugins/bearer/connman/qofonoservice_linux.cpp index 1983276d94..f5da52a341 100644 --- a/src/plugins/bearer/connman/qofonoservice_linux.cpp +++ b/src/plugins/bearer/connman/qofonoservice_linux.cpp @@ -75,256 +75,133 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, ObjectPathPropert QT_BEGIN_NAMESPACE QOfonoManagerInterface::QOfonoManagerInterface( QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), - QLatin1String(OFONO_MANAGER_PATH), + : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), + QStringLiteral(OFONO_MANAGER_PATH), OFONO_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) { qDBusRegisterMetaType(); qDBusRegisterMetaType(); + + QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), + QStringLiteral(OFONO_MANAGER_PATH), + QStringLiteral(OFONO_MANAGER_INTERFACE), + QStringLiteral("ModemAdded"), + this,SLOT(modemAdded(QDBusObjectPath, QVariantMap))); + QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), + QStringLiteral(OFONO_MANAGER_PATH), + QStringLiteral(OFONO_MANAGER_INTERFACE), + QStringLiteral("ModemRemoved"), + this,SLOT(modemRemoved(QDBusObjectPath))); } QOfonoManagerInterface::~QOfonoManagerInterface() { } -QList QOfonoManagerInterface::getModems() +QStringList QOfonoManagerInterface::getModems() { - QList modemList; - QList argumentList; - QDBusReply reply = this->asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList); - if (reply.isValid()) { - foreach (ObjectPathProperties modem, reply.value()) { - modemList << modem.path; + if (modemList.isEmpty()) { + QList argumentList; + QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetModems"), argumentList); + reply.waitForFinished(); + if (!reply.isError()) { + foreach (ObjectPathProperties modem, reply.value()) { + modemList << modem.path.path(); + } + } else { + qDebug() << reply.error().message(); } } return modemList; } -QDBusObjectPath QOfonoManagerInterface::currentModem() +QString QOfonoManagerInterface::currentModem() { - QList modems = getModems(); - foreach (const QDBusObjectPath &modem, modems) { - QOfonoModemInterface device(modem.path()); + QStringList modems = getModems(); + foreach (const QString &modem, modems) { + QOfonoModemInterface device(modem); if (device.isPowered() && device.isOnline()) return modem; } - return QDBusObjectPath(); -} - - -void QOfonoManagerInterface::connectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoManagerInterface::propertyChanged); - if (signal == propertyChangedSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - QLatin1String(OFONO_MANAGER_PATH), - QLatin1String(OFONO_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { - qWarning() << "PropertyCHanged not connected"; - } - } - - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoManagerInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QOfonoDBusHelper *helper; - helper = new QOfonoDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), - QLatin1String(OFONO_MANAGER_PATH), - QLatin1String(OFONO_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))); - } + return QString(); } -void QOfonoManagerInterface::disconnectNotify(const QMetaMethod &signal) +void QOfonoManagerInterface::modemAdded(const QDBusObjectPath &path, const QVariantMap &/*var*/) { - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoManagerInterface::propertyChanged); - if (signal == propertyChangedSignal) { - + if (!modemList.contains(path.path())) { + modemList << path.path(); + Q_EMIT modemChanged(); } } -QVariant QOfonoManagerInterface::getProperty(const QString &property) +void QOfonoManagerInterface::modemRemoved(const QDBusObjectPath &path) { - QVariantMap map = getProperties(); - if (map.contains(property)) { - return map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; + if (modemList.contains(path.path())) { + modemList.removeOne(path.path()); + Q_EMIT modemChanged(); } - return QVariant(); -} - -QVariantMap QOfonoManagerInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - if (reply.isValid()) - return reply.value(); - else - return QVariantMap(); -} - -QOfonoDBusHelper::QOfonoDBusHelper(QObject * parent) - : QObject(parent) -{ -} - -QOfonoDBusHelper::~QOfonoDBusHelper() -{ -} - -void QOfonoDBusHelper::propertyChanged(const QString &item, const QDBusVariant &var) -{ - QDBusMessage msg = this->message(); - Q_EMIT propertyChangedContext(msg.path() ,item, var); } QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), + : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), dbusPathName, OFONO_MODEM_INTERFACE, QDBusConnection::systemBus(), parent) { + QDBusConnection::systemBus().connect(QStringLiteral(OFONO_SERVICE), + path(), + OFONO_MODEM_INTERFACE, + QStringLiteral("PropertyChanged"), + this,SLOT(propertyChanged(QString,QDBusVariant))); } QOfonoModemInterface::~QOfonoModemInterface() { } -bool QOfonoModemInterface::isPowered() +void QOfonoModemInterface::propertyChanged(const QString &name,const QDBusVariant &value) { - QVariant var = getProperty("Powered"); - return qdbus_cast(var); + propertiesMap[name] = value.variant(); } -bool QOfonoModemInterface::isOnline() +bool QOfonoModemInterface::isPowered() { - QVariant var = getProperty("Online"); + QVariant var = getProperty(QStringLiteral("Powered")); return qdbus_cast(var); } -QString QOfonoModemInterface::getName() -{ - QVariant var = getProperty("Name"); - return qdbus_cast(var); -} - -QString QOfonoModemInterface::getManufacturer() -{ - QVariant var = getProperty("Manufacturer"); - return qdbus_cast(var); - -} - -QString QOfonoModemInterface::getModel() -{ - - QVariant var = getProperty("Model"); - return qdbus_cast(var); -} - -QString QOfonoModemInterface::getRevision() -{ - QVariant var = getProperty("Revision"); - return qdbus_cast(var); - -} -QString QOfonoModemInterface::getSerial() -{ - QVariant var = getProperty("Serial"); - return qdbus_cast(var); - -} - -QStringList QOfonoModemInterface::getFeatures() -{ - //sms, sim - QVariant var = getProperty("Features"); - return qdbus_cast(var); -} - -QStringList QOfonoModemInterface::getInterfaces() -{ - QVariant var = getProperty("Interfaces"); - return qdbus_cast(var); -} - -QString QOfonoModemInterface::defaultInterface() +bool QOfonoModemInterface::isOnline() { - foreach (const QString &modem,getInterfaces()) { - return modem; - } - return QString(); + QVariant var = getProperty(QStringLiteral("Online")); + return qdbus_cast(var); } - -void QOfonoModemInterface::connectNotify(const QMetaMethod &signal) +QVariantMap QOfonoModemInterface::getProperties() { - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoModemInterface::propertyChanged); - if (signal == propertyChangedSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_MODEM_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { - qWarning() << "PropertyCHanged not connected"; - } + if (propertiesMap.isEmpty()) { + QList argumentList; + QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + if (!reply.isError()) { + propertiesMap = reply.value(); } - - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoModemInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QOfonoDBusHelper *helper; - helper = new QOfonoDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_MODEM_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); - }} - -void QOfonoModemInterface::disconnectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoModemInterface::propertyChanged); - if (signal == propertyChangedSignal) { - } -} - -QVariantMap QOfonoModemInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); + return propertiesMap; } QVariant QOfonoModemInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } + var = map.value(property); return var; } QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), + : QDBusAbstractInterface(QStringLiteral(OFONO_SERVICE), dbusPathName, OFONO_NETWORK_REGISTRATION_INTERFACE, QDBusConnection::systemBus(), parent) @@ -335,337 +212,33 @@ QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface() { } -QString QOfonoNetworkRegistrationInterface::getStatus() -{ - /* - "unregistered" Not registered to any network - "registered" Registered to home network - "searching" Not registered, but searching - "denied" Registration has been denied - "unknown" Status is unknown - "roaming" Registered, but roaming*/ - QVariant var = getProperty("Status"); - return qdbus_cast(var); -} - -quint16 QOfonoNetworkRegistrationInterface::getLac() -{ - QVariant var = getProperty("LocationAreaCode"); - return var.value(); -} - - -quint32 QOfonoNetworkRegistrationInterface::getCellId() -{ - QVariant var = getProperty("CellId"); - return var.value(); -} - QString QOfonoNetworkRegistrationInterface::getTechnology() { - // "gsm", "edge", "umts", "hspa","lte" - QVariant var = getProperty("Technology"); - return qdbus_cast(var); -} - -QString QOfonoNetworkRegistrationInterface::getOperatorName() -{ - QVariant var = getProperty("Name"); + QVariant var = getProperty(QStringLiteral("Technology")); return qdbus_cast(var); } -int QOfonoNetworkRegistrationInterface::getSignalStrength() -{ - QVariant var = getProperty("Strength"); - return qdbus_cast(var); - -} - -QString QOfonoNetworkRegistrationInterface::getBaseStation() -{ - QVariant var = getProperty("BaseStation"); - return qdbus_cast(var); -} - -QList QOfonoNetworkRegistrationInterface::getOperators() -{ - QList operatorList; - QList argumentList; - QDBusReply reply = this->asyncCallWithArgumentList(QLatin1String("GetOperators"), - argumentList); - if (reply.isValid()) { - foreach (ObjectPathProperties netop, reply.value()) { - operatorList << netop.path; - } - } - return operatorList; -} - -void QOfonoNetworkRegistrationInterface::connectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoNetworkRegistrationInterface::propertyChanged); - if (signal == propertyChangedSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_NETWORK_REGISTRATION_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { - qWarning() << "PropertyCHanged not connected"; - } - } - - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoNetworkRegistrationInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QOfonoDBusHelper *helper; - helper = new QOfonoDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_NETWORK_REGISTRATION_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); - } -} - -void QOfonoNetworkRegistrationInterface::disconnectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoNetworkRegistrationInterface::propertyChanged); - if (signal == propertyChangedSignal) { - - } -} - QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } + var = map.value(property); return var; } QVariantMap QOfonoNetworkRegistrationInterface::getProperties() { - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} - - - -QOfonoNetworkOperatorInterface::QOfonoNetworkOperatorInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), - dbusPathName, - OFONO_NETWORK_OPERATOR_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QOfonoNetworkOperatorInterface::~QOfonoNetworkOperatorInterface() -{ -} - -QString QOfonoNetworkOperatorInterface::getName() -{ - QVariant var = getProperty("Name"); - return qdbus_cast(var); -} - -QString QOfonoNetworkOperatorInterface::getStatus() -{ - // "unknown", "available", "current" and "forbidden" - QVariant var = getProperty("Status"); - return qdbus_cast(var); -} - -QString QOfonoNetworkOperatorInterface::getMcc() -{ - QVariant var = getProperty("MobileCountryCode"); - return qdbus_cast(var); -} - -QString QOfonoNetworkOperatorInterface::getMnc() -{ - QVariant var = getProperty("MobileNetworkCode"); - return qdbus_cast(var); -} - -QStringList QOfonoNetworkOperatorInterface::getTechnologies() -{ - QVariant var = getProperty("Technologies"); - return qdbus_cast(var); -} - -void QOfonoNetworkOperatorInterface::connectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoNetworkOperatorInterface::propertyChanged); -// if (signal == propertyChangedSignal) { -// if (!connection().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_NETWORK_OPERATOR_INTERFACE), -// QLatin1String("PropertyChanged"), -// this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { -// qWarning() << "PropertyCHanged not connected"; -// } -// } - -// static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoNetworkOperatorInterface::propertyChangedContext); -// if (signal == propertyChangedContextSignal) { -// QOfonoDBusHelper *helper; -// helper = new QOfonoDBusHelper(this); - -// QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_NETWORK_OPERATOR_INTERFACE), -// QLatin1String("PropertyChanged"), -// helper,SLOT(propertyChanged(QString,QDBusVariant))); - - -// QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), -// this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); -// } -} - -void QOfonoNetworkOperatorInterface::disconnectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoNetworkOperatorInterface::propertyChanged); -// if (signal == propertyChangedSignal) { - -// } -} - -QVariant QOfonoNetworkOperatorInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } - return var; -} - -QVariantMap QOfonoNetworkOperatorInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} - -QOfonoSimInterface::QOfonoSimInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), - dbusPathName, - OFONO_SIM_MANAGER_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QOfonoSimInterface::~QOfonoSimInterface() -{ -} - -bool QOfonoSimInterface::isPresent() -{ - QVariant var = getProperty("Present"); - return qdbus_cast(var); -} - -QString QOfonoSimInterface::getHomeMcc() -{ - QVariant var = getProperty("MobileCountryCode"); - return qdbus_cast(var); -} - -QString QOfonoSimInterface::getHomeMnc() -{ - QVariant var = getProperty("MobileNetworkCode"); - return qdbus_cast(var); -} - -// QStringList subscriberNumbers(); -// QMap serviceNumbers(); -QString QOfonoSimInterface::pinRequired() -{ - QVariant var = getProperty("PinRequired"); - return qdbus_cast(var); -} - -QString QOfonoSimInterface::lockedPins() -{ - QVariant var = getProperty("LockedPins"); - return qdbus_cast(var); -} - -QString QOfonoSimInterface::cardIdentifier() -{ - QVariant var = getProperty("CardIdentifier"); - return qdbus_cast(var); -} - -void QOfonoSimInterface::connectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoSimInterface::propertyChanged); -// if (signal == propertyChangedSignal) { -// if (!connection().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_SIM_MANAGER_INTERFACE), -// QLatin1String("PropertyChanged"), -// this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { -// qWarning() << "PropertyCHanged not connected"; -// } -// } - -// static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoSimInterface::propertyChangedContext); -// if (signal == propertyChangedContextSignal) { -// QOfonoDBusHelper *helper; -// helper = new QOfonoDBusHelper(this); - -// QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_SIM_MANAGER_INTERFACE), -// QLatin1String("PropertyChanged"), -// helper,SLOT(propertyChanged(QString,QDBusVariant))); - - -// QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), -// this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); -// } -} - -void QOfonoSimInterface::disconnectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoSimInterface::propertyChanged); -// if (signal == propertyChangedSignal) { - -// } -} - -QVariant QOfonoSimInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; + if (propertiesMap.isEmpty()) { + QList argumentList; + QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + reply.waitForFinished(); + if (!reply.isError()) { + propertiesMap = reply.value(); + } else { + qDebug() << reply.error().message(); + } } - return var; -} - -QVariantMap QOfonoSimInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); + return propertiesMap; } QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent) @@ -674,340 +247,62 @@ QOfonoDataConnectionManagerInterface::QOfonoDataConnectionManagerInterface(const OFONO_DATA_CONNECTION_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) { + QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), + path(), + QLatin1String(OFONO_MODEM_INTERFACE), + QLatin1String("PropertyChanged"), + this,SLOT(propertyChanged(QString,QDBusVariant))); } QOfonoDataConnectionManagerInterface::~QOfonoDataConnectionManagerInterface() { } -QList QOfonoDataConnectionManagerInterface::getPrimaryContexts() +QStringList QOfonoDataConnectionManagerInterface::contexts() { - QList contextList; - QList argumentList; - QDBusReply reply = this->asyncCallWithArgumentList(QLatin1String("GetContexts"), - argumentList); - if (reply.isValid()) { - foreach (ObjectPathProperties context, reply.value()) { - contextList << context.path; + if (contextList.isEmpty()) { + QDBusPendingReply reply = call(QLatin1String("GetContexts")); + reply.waitForFinished(); + if (!reply.isError()) { + foreach (ObjectPathProperties context, reply.value()) { + contextList << context.path.path(); + } } } return contextList; } -bool QOfonoDataConnectionManagerInterface::isAttached() -{ - QVariant var = getProperty("Attached"); - return qdbus_cast(var); -} - -bool QOfonoDataConnectionManagerInterface::isRoamingAllowed() +bool QOfonoDataConnectionManagerInterface::roamingAllowed() { - QVariant var = getProperty("RoamingAllowed"); + QVariant var = getProperty(QStringLiteral("RoamingAllowed")); return qdbus_cast(var); } -bool QOfonoDataConnectionManagerInterface::isPowered() -{ - QVariant var = getProperty("Powered"); - return qdbus_cast(var); -} - -void QOfonoDataConnectionManagerInterface::connectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoDataConnectionManagerInterface::propertyChanged); -// if (signal == propertyChangedSignal) { -// if (!connection().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_DATA_CONNECTION_MANAGER_INTERFACE), -// QLatin1String("PropertyChanged"), -// this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { -// qWarning() << "PropertyCHanged not connected"; -// } -// } - -// static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoDataConnectionManagerInterface::propertyChangedContext); -// if (signal == propertyChangedContextSignal) { -// QOfonoDBusHelper *helper; -// helper = new QOfonoDBusHelper(this); - -// QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_DATA_CONNECTION_MANAGER_INTERFACE), -// QLatin1String("PropertyChanged"), -// helper,SLOT(propertyChanged(QString,QDBusVariant))); - - -// QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), -// this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); -// } -} - -void QOfonoDataConnectionManagerInterface::disconnectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoDataConnectionManagerInterface::propertyChanged); -// if (signal == propertyChangedSignal) { - -// } -} - QVariant QOfonoDataConnectionManagerInterface::getProperty(const QString &property) { QVariant var; QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } + var = map.value(property); return var; } QVariantMap QOfonoDataConnectionManagerInterface::getProperties() { - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} - -QOfonoConnectionContextInterface::QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), - dbusPathName, - OFONO_DATA_CONTEXT_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QOfonoConnectionContextInterface::~QOfonoConnectionContextInterface() -{ -} - -bool QOfonoConnectionContextInterface::isActive() -{ - QVariant var = getProperty("Active"); - return qdbus_cast(var); -} - -QString QOfonoConnectionContextInterface::getApName() -{ - QVariant var = getProperty("AccessPointName"); - return qdbus_cast(var); -} - -QString QOfonoConnectionContextInterface::getType() -{ - QVariant var = getProperty("Type"); - return qdbus_cast(var); -} - -QString QOfonoConnectionContextInterface::getName() -{ - QVariant var = getProperty("Name"); - return qdbus_cast(var); -} - -QVariantMap QOfonoConnectionContextInterface::getSettings() -{ - QVariant var = getProperty("Settings"); - return qdbus_cast(var); -} - -QString QOfonoConnectionContextInterface::getInterface() -{ - QVariant var = getProperty("Interface"); - return qdbus_cast(var); -} - -QString QOfonoConnectionContextInterface::getAddress() -{ - QVariant var = getProperty("Address"); - return qdbus_cast(var); -} - -bool QOfonoConnectionContextInterface::setActive(bool on) -{ -// this->setProperty("Active", QVariant(on)); - - return setProp("Active", QVariant::fromValue(on)); -} - -bool QOfonoConnectionContextInterface::setApn(const QString &name) -{ - return setProp("AccessPointName", QVariant::fromValue(name)); -} - -void QOfonoConnectionContextInterface::connectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoConnectionContextInterface::propertyChanged); -// if (signal == propertyChangedSignal) { -// if (!connection().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_DATA_CONTEXT_INTERFACE), -// QLatin1String("PropertyChanged"), -// this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { -// qWarning() << "PropertyCHanged not connected"; -// } -// } - -// static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoConnectionContextInterface::propertyChangedContext); -// if (signal == propertyChangedContextSignal) { -// QOfonoDBusHelper *helper; -// helper = new QOfonoDBusHelper(this); - -// QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), -// this->path(), -// QLatin1String(OFONO_DATA_CONTEXT_INTERFACE), -// QLatin1String("PropertyChanged"), -// helper,SLOT(propertyChanged(QString,QDBusVariant))); - - -// QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), -// this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), Qt::UniqueConnection); -// } -} - -void QOfonoConnectionContextInterface::disconnectNotify(const QMetaMethod &signal) -{ - Q_UNUSED(signal); -// static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoConnectionContextInterface::propertyChanged); -// if (signal == propertyChangedSignal) { - -// } -} - -QVariant QOfonoConnectionContextInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } - return var; -} - -QVariantMap QOfonoConnectionContextInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} - -bool QOfonoConnectionContextInterface::setProp(const QString &property, const QVariant &var) -{ - QList args; - args << QVariant::fromValue(property) << QVariant::fromValue(QDBusVariant(var)); - - QDBusMessage reply = this->callWithArgumentList(QDBus::AutoDetect, - QLatin1String("SetProperty"), - args); - bool ok = true; - if (reply.type() != QDBusMessage::ReplyMessage) { - qWarning() << reply.errorMessage(); - ok = false; - } - qWarning() << reply.errorMessage(); - return ok; -} - -QOfonoSmsInterface::QOfonoSmsInterface(const QString &dbusPathName, QObject *parent) - : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), - dbusPathName, - OFONO_SMS_MANAGER_INTERFACE, - QDBusConnection::systemBus(), parent) -{ -} - -QOfonoSmsInterface::~QOfonoSmsInterface() -{ -} - -void QOfonoSmsInterface::connectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoSmsInterface::propertyChanged); - if (signal == propertyChangedSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_SMS_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - this,SIGNAL(propertyChanged(QString,QDBusVariant)))) { - qWarning() << "PropertyCHanged not connected"; - } - } - - static const QMetaMethod propertyChangedContextSignal = QMetaMethod::fromSignal(&QOfonoSmsInterface::propertyChangedContext); - if (signal == propertyChangedContextSignal) { - QOfonoDBusHelper *helper; - helper = new QOfonoDBusHelper(this); - - QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_SMS_MANAGER_INTERFACE), - QLatin1String("PropertyChanged"), - helper,SLOT(propertyChanged(QString,QDBusVariant))); - - - QObject::connect(helper,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), - this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))); - } - - static const QMetaMethod immediateMessageSignal = QMetaMethod::fromSignal(&QOfonoSmsInterface::immediateMessage); - if (signal == immediateMessageSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_SMS_MANAGER_INTERFACE), - QLatin1String("ImmediateMessage"), - this,SIGNAL(immediateMessage(QString,QVariantMap)))) { - qWarning() << "PropertyCHanged not connected"; - } - } - - static const QMetaMethod incomingMessageSignal = QMetaMethod::fromSignal(&QOfonoSmsInterface::incomingMessage); - if (signal == incomingMessageSignal) { - if (!connection().connect(QLatin1String(OFONO_SERVICE), - this->path(), - QLatin1String(OFONO_SMS_MANAGER_INTERFACE), - QLatin1String("IncomingMessage"), - this,SIGNAL(incomingMessage(QString,QVariantMap)))) { - qWarning() << "PropertyCHanged not connected"; + if (propertiesMap.isEmpty()) { + QList argumentList; + QDBusPendingReply reply = asyncCallWithArgumentList(QLatin1String("GetProperties"), argumentList); + if (!reply.isError()) { + propertiesMap = reply.value(); } } + return propertiesMap; } -void QOfonoSmsInterface::disconnectNotify(const QMetaMethod &signal) -{ - static const QMetaMethod propertyChangedSignal = QMetaMethod::fromSignal(&QOfonoSmsInterface::propertyChanged); - if (signal == propertyChangedSignal) { - - } -} - -QVariant QOfonoSmsInterface::getProperty(const QString &property) -{ - QVariant var; - QVariantMap map = getProperties(); - if (map.contains(property)) { - var = map.value(property); - } else { - qDebug() << Q_FUNC_INFO << "does not contain" << property; - } - return var; -} - -QVariantMap QOfonoSmsInterface::getProperties() -{ - QDBusReply reply = this->call(QLatin1String("GetProperties")); - return reply.value(); -} - -void QOfonoSmsInterface::sendMessage(const QString &to, const QString &message) +void QOfonoDataConnectionManagerInterface::propertyChanged(const QString &name, const QDBusVariant &value) { - QDBusReply reply = this->call(QLatin1String("SendMessage"), - QVariant::fromValue(to), - QVariant::fromValue(message)); - if (reply.error().type() == QDBusError::InvalidArgs) - qWarning("%s", qPrintable(reply.error().message())); + propertiesMap[name] = value.variant(); + if (name == QStringLiteral("RoamingAllowed")) + Q_EMIT roamingAllowedChanged(value.variant().toBool()); } QT_END_NAMESPACE diff --git a/src/plugins/bearer/connman/qofonoservice_linux_p.h b/src/plugins/bearer/connman/qofonoservice_linux_p.h index 4802e0dc70..8fea465fd0 100644 --- a/src/plugins/bearer/connman/qofonoservice_linux_p.h +++ b/src/plugins/bearer/connman/qofonoservice_linux_p.h @@ -71,18 +71,10 @@ #define OFONO_SERVICE "org.ofono" #define OFONO_MANAGER_INTERFACE "org.ofono.Manager" #define OFONO_MANAGER_PATH "/" + #define OFONO_MODEM_INTERFACE "org.ofono.Modem" #define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration" -#define OFONO_NETWORK_OPERATOR_INTERFACE "org.ofono.NetworkOperator" #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager" -#define OFONO_SIM_MANAGER_INTERFACE "org.ofono.SimManager" -#define OFONO_DATA_CONTEXT_INTERFACE "org.ofono.ConnectionContext" - -#define OFONO_SMS_MANAGER_INTERFACE "org.ofono.SmsManager" -#define OFONO_PHONEBOOK_INTERFACE "org.ofono.Phonebook" -#define OFONO_MESSAGE_WAITING_INTERFACE "org.ofono.MessageWaiting" - - QT_BEGIN_NAMESPACE @@ -108,35 +100,15 @@ public: QOfonoManagerInterface( QObject *parent = 0); ~QOfonoManagerInterface(); - QDBusObjectPath path() const; - - QVariantMap getProperties(); - bool setProperty(const QString &name, const QDBusVariant &value); - QList getModems(); - QDBusObjectPath currentModem(); - -Q_SIGNALS: - void propertyChanged(const QString &, const QDBusVariant &value); - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); - -}; - - -class QOfonoDBusHelper: public QObject, protected QDBusContext - { - Q_OBJECT - public: - QOfonoDBusHelper(QObject *parent = 0); - ~QOfonoDBusHelper(); - - public slots: - void propertyChanged(const QString &, const QDBusVariant &); - Q_SIGNALS: - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); + QStringList getModems(); + QString currentModem(); +signals: + void modemChanged(); +private: + QStringList modemList; +private slots: + void modemAdded(const QDBusObjectPath &path, const QVariantMap &var); + void modemRemoved(const QDBusObjectPath &path); }; class QOfonoModemInterface : public QDBusAbstractInterface @@ -148,27 +120,13 @@ public: explicit QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0); ~QOfonoModemInterface(); - QVariantMap getProperties(); - //properties bool isPowered(); bool isOnline(); - QString getName(); - QString getManufacturer(); - QString getModel(); - QString getRevision(); - QString getSerial(); - - QStringList getFeatures(); //sms, sim - QStringList getInterfaces(); - QString defaultInterface(); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); +private: + QVariantMap getProperties(); + QVariantMap propertiesMap; QVariant getProperty(const QString &); -Q_SIGNALS: void propertyChanged(const QString &, const QDBusVariant &value); - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); }; @@ -181,80 +139,16 @@ public: explicit QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0); ~QOfonoNetworkRegistrationInterface(); - QVariantMap getProperties(); - - //properties - QString getStatus(); - quint16 getLac(); - quint32 getCellId(); QString getTechnology(); - QString getOperatorName(); - int getSignalStrength(); - QString getBaseStation(); - QList getOperators(); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); -Q_SIGNALS: - void propertyChanged(const QString &, const QDBusVariant &value); - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); - -}; - -class QOfonoNetworkOperatorInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: -//modem or operator paths - explicit QOfonoNetworkOperatorInterface(const QString &dbusPathName, QObject *parent = 0); - ~QOfonoNetworkOperatorInterface(); - - QVariantMap getProperties(); - - //properties - QString getName(); - QString getStatus();// "unknown", "available", "current" and "forbidden" - QString getMcc(); - QString getMnc(); - QStringList getTechnologies(); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); -}; - -class QOfonoSimInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: - - explicit QOfonoSimInterface(const QString &dbusModemPathName, QObject *parent = 0); - ~QOfonoSimInterface(); +private: QVariantMap getProperties(); - - //properties - bool isPresent(); - QString getHomeMcc(); - QString getHomeMnc(); -// QStringList subscriberNumbers(); -// QMap serviceNumbers(); - QString pinRequired(); - QString lockedPins(); - QString cardIdentifier(); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); QVariant getProperty(const QString &); + QVariantMap propertiesMap; +Q_SIGNALS: + void propertyChanged(const QString &, const QDBusVariant &value); }; - class QOfonoDataConnectionManagerInterface : public QDBusAbstractInterface { Q_OBJECT @@ -264,82 +158,20 @@ public: explicit QOfonoDataConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0); ~QOfonoDataConnectionManagerInterface(); + QStringList contexts(); + bool roamingAllowed(); +Q_SIGNALS: + void roamingAllowedChanged(bool); +private: QVariantMap getProperties(); - - //properties - QList getPrimaryContexts(); - bool isAttached(); - bool isRoamingAllowed(); - bool isPowered(); - - bool setPower(bool on); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); -}; - - -class QOfonoConnectionContextInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: - - explicit QOfonoConnectionContextInterface(const QString &dbusPathName, QObject *parent = 0); - ~QOfonoConnectionContextInterface(); - - QVariantMap getProperties(); - - //properties - bool isActive(); - QString getApName(); - QString getType(); - QString getName(); - QVariantMap getSettings(); - QString getInterface(); - QString getAddress(); - - bool setActive(bool on); - bool setApn(const QString &name); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); - QVariant getProperty(const QString &); - bool setProp(const QString &, const QVariant &var); -}; - -class QOfonoSmsInterface : public QDBusAbstractInterface -{ - Q_OBJECT - -public: - - explicit QOfonoSmsInterface(const QString &dbusModemPathName, QObject *parent = 0); - ~QOfonoSmsInterface(); - - QVariantMap getProperties(); - void sendMessage(const QString &to, const QString &message); - - //properties - QString serviceCenterAddress(); - bool useDeliveryReports(); - QString bearer(); - -protected: - void connectNotify(const QMetaMethod &signal); - void disconnectNotify(const QMetaMethod &signal); + QVariantMap propertiesMap; QVariant getProperty(const QString &); - -Q_SIGNALS: + QStringList contextList; +private slots: void propertyChanged(const QString &, const QDBusVariant &value); - void propertyChangedContext(const QString &,const QString &,const QDBusVariant &); - void immediateMessage(const QString &message, const QVariantMap &info); - void incomingMessage(const QString &message, const QVariantMap &info); }; + QT_END_NAMESPACE #endif // QT_NO_DBUS -- cgit v1.2.3