diff options
author | Evan Nguyen <evan.nguyen@nokia.com> | 2010-10-08 16:40:51 +1000 |
---|---|---|
committer | Evan Nguyen <evan.nguyen@nokia.com> | 2010-10-08 16:40:51 +1000 |
commit | b3dd79199a055bce44d44bc5db611271345c4b88 (patch) | |
tree | ee5dca461b897f0efd038bdf221c1e96698d678c | |
parent | b4fd47b40b16943289cc05279649bab189fee79e (diff) |
Fixed SFW InterfaceManager bug
Implements totalInstances()
-rw-r--r-- | examples/sfwecho/sfwecho_service/main.cpp | 2 | ||||
-rw-r--r-- | src/serviceframework/ipc/instancemanager.cpp | 24 | ||||
-rw-r--r-- | src/serviceframework/ipc/instancemanager_p.h | 1 | ||||
-rw-r--r-- | src/serviceframework/ipc/objectendpoint_dbus.cpp | 59 | ||||
-rw-r--r-- | src/serviceframework/ipc/qremoteserviceregister_dbus_p.cpp | 22 | ||||
-rw-r--r-- | src/serviceframework/ipc/qremoteserviceregister_dbus_p.h | 1 | ||||
-rw-r--r-- | src/serviceframework/ipc/qservicemetaobject_dbus.cpp | 13 |
7 files changed, 75 insertions, 47 deletions
diff --git a/examples/sfwecho/sfwecho_service/main.cpp b/examples/sfwecho/sfwecho_service/main.cpp index fe9c9a33e4..c32be8ce41 100644 --- a/examples/sfwecho/sfwecho_service/main.cpp +++ b/examples/sfwecho/sfwecho_service/main.cpp @@ -108,7 +108,7 @@ int main(int argc, char** argv) registerExampleService(); - QRemoteServiceRegister* serviceRegister = new QRemoteServiceRegister(); + QRemoteServiceRegister *serviceRegister = new QRemoteServiceRegister(); //serviceRegister->setSecurityFilter(check); QRemoteServiceRegister::Entry shared = serviceRegister->createEntry<EchoService>( diff --git a/src/serviceframework/ipc/instancemanager.cpp b/src/serviceframework/ipc/instancemanager.cpp index 4acf9aa97a..3ef8e784e2 100644 --- a/src/serviceframework/ipc/instancemanager.cpp +++ b/src/serviceframework/ipc/instancemanager.cpp @@ -158,8 +158,6 @@ void InstanceManager::removeObjectInstance(const QRemoteServiceRegister::Entry& if (!metaMap.contains(entry)) return; - emit instanceClosed(entry); - ServiceIdentDescriptor& descr = metaMap[entry]; if (descr.entryData->instanceType == QRemoteServiceRegister::GlobalInstance) { if (descr.globalRefCount < 1) @@ -180,11 +178,29 @@ void InstanceManager::removeObjectInstance(const QRemoteServiceRegister::Entry& if (service) { service->deleteLater(); } - metaMap.remove(entry); + + if (descr.individualInstances.size() < 1) + metaMap.remove(entry); } - if(metaMap.empty()) + emit instanceClosed(entry); + + // Check that no instances are open + if (totalInstances() < 1) emit allInstancesClosed(); +} + +int InstanceManager::totalInstances() const +{ + int total = 0; + + QList<QRemoteServiceRegister::Entry> allEntries = metaMap.keys(); + foreach (const QRemoteServiceRegister::Entry& entry, allEntries) { + ServiceIdentDescriptor descr = metaMap[entry]; + total += descr.globalRefCount; + total += descr.individualInstances.size(); + } + return total; } #include "moc_instancemanager_p.cpp" diff --git a/src/serviceframework/ipc/instancemanager_p.h b/src/serviceframework/ipc/instancemanager_p.h index 90e0fbe768..ceae3ec7d2 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); void removeObjectInstance(const QRemoteServiceRegister::Entry& entry, const QUuid& instanceId); diff --git a/src/serviceframework/ipc/objectendpoint_dbus.cpp b/src/serviceframework/ipc/objectendpoint_dbus.cpp index d1436dd452..50bd6d1c31 100644 --- a/src/serviceframework/ipc/objectendpoint_dbus.cpp +++ b/src/serviceframework/ipc/objectendpoint_dbus.cpp @@ -124,7 +124,7 @@ ObjectEndPoint::ObjectEndPoint(Type type, QServiceIpcEndPoint* comm, QObject* pa dispatch->setParent(this); connect(dispatch, SIGNAL(readyRead()), this, SLOT(newPackageReady())); - connect(dispatch, SIGNAL(disconnected()), this, SLOT(disconnected())); + //connect(dispatch, SIGNAL(disconnected()), this, SLOT(disconnected())); if (type == Client) { // client waiting for construct proxy and registers DBus custom type qDBusRegisterMetaType<QTM_PREPEND_NAMESPACE(QServiceUserTypeDBus)>(); @@ -186,39 +186,42 @@ QObject* ObjectEndPoint::constructProxy(const QRemoteServiceRegister::Entry& ent // Connect all DBus interface signals to the proxy slots const QMetaObject *mo = service->metaObject(); - for (int i = mo->methodOffset(); i < mo->methodCount(); i++) { - const QMetaMethod mm = mo->method(i); - if (mm.methodType() == QMetaMethod::Signal) { - QByteArray sig(mm.signature()); + while (mo && strcmp(mo->className(), "QObject")) { + for (int i = mo->methodOffset(); i < mo->methodCount(); i++) { + const QMetaMethod mm = mo->method(i); + if (mm.methodType() == QMetaMethod::Signal) { + QByteArray sig(mm.signature()); + + bool customType = false; + + QList<QByteArray> params = mm.parameterTypes(); + for (int arg = 0; arg < params.size(); arg++) { + const QByteArray& type = params[arg]; + int variantType = QVariant::nameToType(type); + if (variantType == QVariant::UserType) { + sig.replace(QByteArray(type), QByteArray("QDBusVariant")); + customType = true; + } + } - bool customType = false; + int serviceIndex = iface->metaObject()->indexOfSignal(sig); + QByteArray signal = QByteArray("2").append(sig); + QByteArray method = QByteArray("1").append(sig); - QList<QByteArray> params = mm.parameterTypes(); - for (int arg = 0; arg < params.size(); arg++) { - const QByteArray& type = params[arg]; - int variantType = QVariant::nameToType(type); - if (variantType == QVariant::UserType) { - sig.replace(QByteArray(type), QByteArray("QDBusVariant")); - customType = true; - } - } + if (serviceIndex > 0) { + if (customType) { + QObject::connect(iface, signal.constData(), signalsObject, signal.constData()); - int serviceIndex = iface->metaObject()->indexOfSignal(sig); - QByteArray signal = QByteArray("2").append(sig); - QByteArray method = QByteArray("1").append(sig); - - if (serviceIndex > 0) { - if (customType) { - QObject::connect(iface, signal.constData(), signalsObject, signal.constData()); - - ServiceSignalIntercepter *intercept = - new ServiceSignalIntercepter((QObject*)signalsObject, signal, this); - intercept->setMetaIndex(i); - } else { - QObject::connect(iface, signal.constData(), service, method.constData()); + ServiceSignalIntercepter *intercept = + new ServiceSignalIntercepter((QObject*)signalsObject, signal, this); + intercept->setMetaIndex(i); + } else { + QObject::connect(iface, signal.constData(), service, method.constData()); + } } } } + mo = mo->superClass(); } return service; diff --git a/src/serviceframework/ipc/qremoteserviceregister_dbus_p.cpp b/src/serviceframework/ipc/qremoteserviceregister_dbus_p.cpp index 1525f0c65f..4db03606d5 100644 --- a/src/serviceframework/ipc/qremoteserviceregister_dbus_p.cpp +++ b/src/serviceframework/ipc/qremoteserviceregister_dbus_p.cpp @@ -170,7 +170,7 @@ DBusSessionAdaptor::DBusSessionAdaptor(QObject *parent) } QRemoteServiceRegisterDBusPrivate::QRemoteServiceRegisterDBusPrivate(QObject* parent) - : QRemoteServiceRegisterPrivate(parent), instanceCount(0) + : QRemoteServiceRegisterPrivate(parent) { } @@ -211,7 +211,7 @@ bool QRemoteServiceRegisterDBusPrivate::createServiceEndPoint(const QString& /*i session = new DBusSession(); new DBusSessionAdaptor(session); QObject::connect(session, SIGNAL(newConnection(int,int)), this, SLOT(processIncoming(int,int))); - QObject::connect(session, SIGNAL(closeConnection()), this, SLOT(processClosing())); + //QObject::connect(session, SIGNAL(closeConnection()), this, SLOT(processClosing())); QString path = "/" + list[0].interfaceName() + "/DBusSession"; path.replace(QString("."), QString("/")); @@ -227,8 +227,12 @@ bool QRemoteServiceRegisterDBusPrivate::createServiceEndPoint(const QString& /*i } DBusEndPoint* ipcEndPoint = new DBusEndPoint(iface, SERVER); - ObjectEndPoint* endpoint = new ObjectEndPoint(ObjectEndPoint::Service, ipcEndPoint, this); - Q_UNUSED(endpoint); + ObjectEndPoint* endPoint = new ObjectEndPoint(ObjectEndPoint::Service, ipcEndPoint, this); + + // Connect session process disconnections + QObject::connect(session, SIGNAL(closeConnection()), endPoint, SLOT(disconnected())); + QObject::connect(iManager, SIGNAL(allInstancesClosed()), this, SLOT(processClosing())); + return true; } @@ -247,8 +251,9 @@ void QRemoteServiceRegisterDBusPrivate::processIncoming(int pid, int uid) if(!getSecurityFilter()(reinterpret_cast<const void *>(&cred))){ session->acceptIncoming(false); - // Close service if only client - if (instanceCount <= 0 && quitOnLastInstanceClosed()) + // Close service if no instances + if (quitOnLastInstanceClosed() && + InstanceManager::instance()->totalInstances() < 1) QCoreApplication::exit(); return; @@ -256,14 +261,11 @@ void QRemoteServiceRegisterDBusPrivate::processIncoming(int pid, int uid) } session->acceptIncoming(true); - instanceCount++; } void QRemoteServiceRegisterDBusPrivate::processClosing() { - instanceCount--; - - if (instanceCount <= 0 && quitOnLastInstanceClosed()) + if (quitOnLastInstanceClosed()) QCoreApplication::exit(); } diff --git a/src/serviceframework/ipc/qremoteserviceregister_dbus_p.h b/src/serviceframework/ipc/qremoteserviceregister_dbus_p.h index 15deb1131e..00e8a52f72 100644 --- a/src/serviceframework/ipc/qremoteserviceregister_dbus_p.h +++ b/src/serviceframework/ipc/qremoteserviceregister_dbus_p.h @@ -108,7 +108,6 @@ private: QList<ObjectEndPoint*> pendingConnections; QDBusInterface *iface; DBusSession *session; - int instanceCount; }; QTM_END_NAMESPACE diff --git a/src/serviceframework/ipc/qservicemetaobject_dbus.cpp b/src/serviceframework/ipc/qservicemetaobject_dbus.cpp index 54c0ec22ca..fc67273df3 100644 --- a/src/serviceframework/ipc/qservicemetaobject_dbus.cpp +++ b/src/serviceframework/ipc/qservicemetaobject_dbus.cpp @@ -99,8 +99,6 @@ QServiceMetaObjectDBus::QServiceMetaObjectDBus(QObject* service, bool signalsObj QServiceMetaObjectDBus::~QServiceMetaObjectDBus() { - if (d->serviceMeta) - delete d->serviceMeta; if (d->dbusMeta) delete d->dbusMeta; delete d; @@ -119,12 +117,19 @@ void QServiceMetaObjectDBus::connectMetaSignals(bool signalsObject) { int methodCount = d->serviceMeta->methodCount(); for (int i = 0; i < methodCount; i++) { QMetaMethod mm = d->serviceMeta->method(i); + if (mm.methodType() == QMetaMethod::Signal) { QByteArray sig(mm.signature()); bool customType = false; const QList<QByteArray> pTypes = mm.parameterTypes(); const int pTypesCount = pTypes.count(); + + // Ignore all QObject calls + const QMetaObject *mo = QObject::metaObject(); + int qobjectIndex = mo->indexOfMethod(sig); + if (qobjectIndex >= 0) + continue; // Detects custom types as passed arguments for (int arg = 0; arg < pTypesCount; arg++) { @@ -139,6 +144,7 @@ void QServiceMetaObjectDBus::connectMetaSignals(bool signalsObject) { // Connects the service signal to the corresponding DBus service signal if (customType) { QByteArray signal = mm.signature(); + qDebug() << "CONNECTING" << signal; ServiceMetaSignalIntercepter *intercept = new ServiceMetaSignalIntercepter(d->service, "2"+signal, this); intercept->setMetaIndex(i); @@ -162,6 +168,7 @@ void QServiceMetaObjectDBus::activateMetaSignal(int id, const QVariantList& args QVariantList convertedList = args; QByteArray sig(method.signature()); QList<QByteArray> params = method.parameterTypes(); + for (int i = 0; i < params.size(); i++) { QVariant dbusVariant = args[i]; @@ -342,7 +349,7 @@ int QServiceMetaObjectDBus::qt_metacall(QMetaObject::Call c, int id, void **a) if (c == QMetaObject::InvokeMetaMethod) { // METHOD CALL QMetaMethod method = d->dbusMeta->method(id); - + const bool isSignal = (method.methodType() == QMetaMethod::Signal); ///////////////////// CHECK SPECIAL PROPERTY /////////////////////// |