diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-12-08 07:48:14 (GMT) |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2010-12-15 04:44:23 (GMT) |
commit | c9faf2defa9fa3209e44e8a5c1ae2da8e630d379 (patch) | |
tree | 733a13d33ea53effe70c546ab924ea3b83f4688d | |
parent | c031e5808ee406277a5401c69801e5c6e2ebfaea (diff) | |
download | Qt-c9faf2defa9fa3209e44e8a5c1ae2da8e630d379.zip Qt-c9faf2defa9fa3209e44e8a5c1ae2da8e630d379.tar.gz Qt-c9faf2defa9fa3209e44e8a5c1ae2da8e630d379.tar.bz2 |
Ensure that DBus is connected before all uses.
In early system startup applications may try to use ICD before it is
contactable. Ensure that the connection to ICD is established before all
calls are made.
If ICD is still not contactable QDBusServiceWatcher is used to monitor
registration of the com.nokia.icd2 address and reconnection is attempted
once ICD is started.
Task-number: Maemo 199755
-rw-r--r-- | src/plugins/bearer/icd/qicdengine.cpp | 93 | ||||
-rw-r--r-- | src/plugins/bearer/icd/qicdengine.h | 6 |
2 files changed, 88 insertions, 11 deletions
diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index bdf4e2e..a5a183b 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -229,7 +229,7 @@ void IapMonitor::iapRemoved(const QString &iap_id) /******************************************************************************/ QIcdEngine::QIcdEngine(QObject *parent) -: QBearerEngine(parent), iapMonitor(0), m_dbusInterface(0), +: QBearerEngine(parent), iapMonitor(0), m_dbusInterface(0), m_icdServiceWatcher(0), firstUpdate(true), m_scanGoingOn(false) { } @@ -248,9 +248,10 @@ QNetworkConfigurationManager::Capabilities QIcdEngine::capabilities() const QNetworkConfigurationManager::NetworkSessionRequired; } -void QIcdEngine::initialize() +bool QIcdEngine::ensureDBusConnection() { - QMutexLocker locker(&mutex); + if (m_dbusInterface) + return true; // Setup DBus Interface for ICD m_dbusInterface = new QDBusInterface(ICD_DBUS_API_INTERFACE, @@ -259,9 +260,22 @@ void QIcdEngine::initialize() QDBusConnection::systemBus(), this); - // abort if cannot connect to DBus. - if (!m_dbusInterface->isValid()) - return; + if (!m_dbusInterface->isValid()) { + delete m_dbusInterface; + m_dbusInterface = 0; + + if (!m_icdServiceWatcher) { + m_icdServiceWatcher = new QDBusServiceWatcher(ICD_DBUS_API_INTERFACE, + QDBusConnection::systemBus(), + QDBusServiceWatcher::WatchForOwnerChange, + this); + + connect(m_icdServiceWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), + this, SLOT(icdServiceOwnerChanged(QString,QString,QString))); + } + + return false; + } connect(&m_scanTimer, SIGNAL(timeout()), this, SLOT(finishAsyncConfigurationUpdate())); m_scanTimer.setSingleShot(true); @@ -289,6 +303,19 @@ void QIcdEngine::initialize() doRequestUpdate(); getIcdInitialState(); + + return true; +} + +void QIcdEngine::initialize() +{ + QMutexLocker locker(&mutex); + + if (!ensureDBusConnection()) { + locker.unlock(); + emit updateCompleted(); + locker.relock(); + } } static inline QString network_attrs_to_security(uint network_attrs) @@ -792,6 +819,9 @@ QNetworkConfigurationPrivatePointer QIcdEngine::defaultConfiguration() { QMutexLocker locker(&mutex); + if (!ensureDBusConnection()) + return QNetworkConfigurationPrivatePointer(); + // Here we just return [ANY] request to icd and let the icd decide which IAP to connect. return userChoiceConfigurations.value(OSSO_IAP_ANY); } @@ -933,13 +963,52 @@ void QIcdEngine::connectionStateSignalsSlot(QDBusMessage msg) locker.relock(); } +void QIcdEngine::icdServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, + const QString &newOwner) +{ + QMutexLocker locker(&mutex); + + if (newOwner.isEmpty()) { + // Disconnected from ICD, remove all configurations + cleanup(); + delete iapMonitor; + iapMonitor = 0; + delete m_dbusInterface; + m_dbusInterface = 0; + + QMutableHashIterator<QString, QNetworkConfigurationPrivatePointer> i(accessPointConfigurations); + while (i.hasNext()) { + i.next(); + + QNetworkConfigurationPrivatePointer ptr = i.value(); + i.remove(); + + locker.unlock(); + emit configurationRemoved(ptr); + locker.relock(); + } + + userChoiceConfigurations.clear(); + } else { + // Connected to ICD ensure connection. + ensureDBusConnection(); + } +} + void QIcdEngine::requestUpdate() { QMutexLocker locker(&mutex); - if (m_scanGoingOn) { + if (!ensureDBusConnection()) { + locker.unlock(); + emit updateCompleted(); + locker.relock(); return; } + + if (m_scanGoingOn) + return; + m_scanGoingOn = true; m_dbusInterface->connection().connect(ICD_DBUS_API_INTERFACE, @@ -956,14 +1025,16 @@ void QIcdEngine::requestUpdate() void QIcdEngine::cancelAsyncConfigurationUpdate() { - if (!m_scanGoingOn) { + if (!ensureDBusConnection()) return; - } + + if (!m_scanGoingOn) + return; + m_scanGoingOn = false; - if (m_scanTimer.isActive()) { + if (m_scanTimer.isActive()) m_scanTimer.stop(); - } m_dbusInterface->connection().disconnect(ICD_DBUS_API_INTERFACE, ICD_DBUS_API_PATH, diff --git a/src/plugins/bearer/icd/qicdengine.h b/src/plugins/bearer/icd/qicdengine.h index d528f15..d5b4fb3 100644 --- a/src/plugins/bearer/icd/qicdengine.h +++ b/src/plugins/bearer/icd/qicdengine.h @@ -53,6 +53,7 @@ QT_BEGIN_NAMESPACE class QNetworkConfigurationPrivate; class IapMonitor; class QDBusInterface; +class QDBusServiceWatcher; inline QNetworkConfiguration::BearerType bearerTypeFromIapType(const QString &iapType) { @@ -147,12 +148,15 @@ private Q_SLOTS: void finishAsyncConfigurationUpdate(); void asyncUpdateConfigurationsSlot(QDBusMessage msg); void connectionStateSignalsSlot(QDBusMessage msg); + void icdServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, + const QString &newOwner); private: void startListeningStateSignalsForAllConnections(); void doRequestUpdate(QList<Maemo::IcdScanResult> scanned = QList<Maemo::IcdScanResult>()); void cancelAsyncConfigurationUpdate(); void getIcdInitialState(); + bool ensureDBusConnection(); private: IapMonitor *iapMonitor; @@ -162,6 +166,8 @@ private: QStringList m_typesToBeScanned; QList<Maemo::IcdScanResult> m_scanResult; + QDBusServiceWatcher *m_icdServiceWatcher; + bool firstUpdate; bool m_scanGoingOn; }; |