diff options
author | Evan Nguyen <evan.nguyen@nokia.com> | 2010-10-18 18:22:20 +1000 |
---|---|---|
committer | Evan Nguyen <evan.nguyen@nokia.com> | 2010-10-18 18:22:20 +1000 |
commit | 8704533113ffcd7684c2f70e15c94aa9e27c0882 (patch) | |
tree | 76a7840ef9b9c2adb5b0de74fee6e73c6032aa4f | |
parent | e0b012e2822257137b7e0096b6dabf2deef8915e (diff) |
Fixed bug that unregistered DBus objects prematurely
-rw-r--r-- | src/serviceframework/ipc/instancemanager.cpp | 6 | ||||
-rw-r--r-- | src/serviceframework/ipc/instancemanager_p.h | 2 | ||||
-rw-r--r-- | src/serviceframework/ipc/objectendpoint_dbus.cpp | 53 | ||||
-rw-r--r-- | src/serviceframework/ipc/objectendpoint_dbus_p.h | 1 |
4 files changed, 38 insertions, 24 deletions
diff --git a/src/serviceframework/ipc/instancemanager.cpp b/src/serviceframework/ipc/instancemanager.cpp index 56c586855e..bace862690 100644 --- a/src/serviceframework/ipc/instancemanager.cpp +++ b/src/serviceframework/ipc/instancemanager.cpp @@ -196,6 +196,8 @@ void InstanceManager::removeObjectInstance(const QRemoteServiceRegister::Entry& descr.globalInstance = 0; descr.globalId = QUuid(); descr.globalRefCount = 0; + emit instanceClosed(entry); + emit instanceClosed(entry, instanceId); //internal use } else { descr.globalRefCount--; } @@ -203,10 +205,10 @@ void InstanceManager::removeObjectInstance(const QRemoteServiceRegister::Entry& QObject* service = descr.individualInstances.take(instanceId); if (service) { service->deleteLater(); + emit instanceClosed(entry); + emit instanceClosed(entry, instanceId); //internal use } } - - emit instanceClosed(entry); // Check that no instances are open if (totalInstances() < 1) diff --git a/src/serviceframework/ipc/instancemanager_p.h b/src/serviceframework/ipc/instancemanager_p.h index ceae3ec7d2..3f4796b1e8 100644 --- a/src/serviceframework/ipc/instancemanager_p.h +++ b/src/serviceframework/ipc/instancemanager_p.h @@ -79,6 +79,7 @@ public: const QMetaObject* metaObject(const QRemoteServiceRegister::Entry& ident) const; QList<QRemoteServiceRegister::Entry> allEntries() const; + int totalInstances() const; QObject* createObjectInstance(const QRemoteServiceRegister::Entry& entry, QUuid& instanceId); @@ -89,6 +90,7 @@ public: Q_SIGNALS: void allInstancesClosed(); void instanceClosed(const QRemoteServiceRegister::Entry&); + void instanceClosed(const QRemoteServiceRegister::Entry&, const QUuid&); private: mutable QMutex lock; diff --git a/src/serviceframework/ipc/objectendpoint_dbus.cpp b/src/serviceframework/ipc/objectendpoint_dbus.cpp index d61710bdac..be307870dd 100644 --- a/src/serviceframework/ipc/objectendpoint_dbus.cpp +++ b/src/serviceframework/ipc/objectendpoint_dbus.cpp @@ -139,6 +139,10 @@ ObjectEndPoint::ObjectEndPoint(Type type, QServiceIpcEndPoint* comm, QObject* pa qRegisterMetaType<QTM_PREPEND_NAMESPACE(QServiceUserTypeDBus)>(); return; } else { + connect(InstanceManager::instance(), + SIGNAL(instanceClosed(QRemoteServiceRegister::Entry,QUuid)), + this, SLOT(unregisterObjectDBus(QRemoteServiceRegister::Entry,QUuid))); + if (dispatch->packageAvailable()) QTimer::singleShot(0, this, SLOT(newPackageReady())); } @@ -149,36 +153,42 @@ ObjectEndPoint::~ObjectEndPoint() delete d; } +/*! + Removes all instances of the client from the instance manager +*/ void ObjectEndPoint::disconnected(const QString& clientId, const QString& instanceId) { // Service Side - if (d->endPointType == Service) { - for (int i=d->clientList.size()-1; i>=0; i--) { - // Find right client process - if (d->clientList[i].clientId == clientId) { - //QRemoteServiceRegister::Entry entry = d->clientList[i].second.first; - //QUuid instance = d->clientList[i].second.second; - QRemoteServiceRegister::Entry entry = d->clientList[i].entry; - QUuid instance = d->clientList[i].instanceId; - - if (instance.toString() == instanceId) { - // Remove an instance from the InstanceManager and local list - InstanceManager::instance()->removeObjectInstance(entry, instance); - d->clientList.removeAt(i); - - // Unregister object from D-Bus - uint hash = qHash(instance.toString()); - QString objPath = "/" + entry.interfaceName() + "/" + entry.version() + - "/" + QString::number(hash); - objPath.replace(QString("."), QString("/")); - connection->unregisterObject(objPath, QDBusConnection::UnregisterTree); - } + Q_ASSERT(d->endPointType != ObjectEndPoint::Client); + + for (int i=d->clientList.size()-1; i>=0; i--) { + // Find right client process + if (d->clientList[i].clientId == clientId) { + QRemoteServiceRegister::Entry entry = d->clientList[i].entry; + QUuid instance = d->clientList[i].instanceId; + + if (instance.toString() == instanceId) { + // Remove an instance from the InstanceManager and local list + InstanceManager::instance()->removeObjectInstance(entry, instance); + d->clientList.removeAt(i); } } } } /*! + Unregisters the DBus object +*/ +void ObjectEndPoint::unregisterObjectDBus(const QRemoteServiceRegister::Entry& entry, const QUuid& id) +{ + uint hash = qHash(id.toString()); + QString objPath = "/" + entry.interfaceName() + "/" + entry.version() + + "/" + QString::number(hash); + objPath.replace(QString("."), QString("/")); + connection->unregisterObject(objPath, QDBusConnection::UnregisterTree); +} + +/*! Client requests proxy object. The proxy is owned by calling code and this object must clean itself up upon destruction of proxy. @@ -329,7 +339,6 @@ void ObjectEndPoint::objectRequest(const QServicePackage& p) // Service side Q_ASSERT(d->endPointType == ObjectEndPoint::Service); - QServicePackage response = p.createResponse(); InstanceManager* iManager = InstanceManager::instance(); diff --git a/src/serviceframework/ipc/objectendpoint_dbus_p.h b/src/serviceframework/ipc/objectendpoint_dbus_p.h index 7eb23c7973..83d64b8abf 100644 --- a/src/serviceframework/ipc/objectendpoint_dbus_p.h +++ b/src/serviceframework/ipc/objectendpoint_dbus_p.h @@ -84,6 +84,7 @@ Q_SIGNALS: public Q_SLOTS: void newPackageReady(); void disconnected(const QString& clientId, const QString & instanceId); + void unregisterObjectDBus(const QRemoteServiceRegister::Entry& entry, const QUuid& id); private: void waitForResponse(const QUuid& requestId); |