summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvan Nguyen <evan.nguyen@nokia.com>2010-06-24 17:06:35 +1000
committerEvan Nguyen <evan.nguyen@nokia.com>2010-06-24 17:06:35 +1000
commitbff2d829b773650c59e26cbe3508783fa113d186 (patch)
tree18c16c7214b1ce6b753e21cce12c54f0faa19822
parent43fa409adc4afffa67f6bda5c69009ad63e3651b (diff)
Added ServiceName to QRemoteServiceIdentifier for DBUS use
QRemoteServiceIdentifier is now a struct class behaving similiarly to a QPair, except that it allows for the 3 Q_SERVICE macro inputs. This cascades throughout the entire IPC architecture - localsocket & symbiam IPC may need to be revised to reflect this change
-rw-r--r--src/serviceframework/ipc/instancemanager.cpp6
-rw-r--r--src/serviceframework/ipc/instancemanager_p.h4
-rw-r--r--src/serviceframework/qremoteserviceclassregister.cpp10
-rw-r--r--src/serviceframework/qremoteserviceclassregister.h62
-rw-r--r--src/serviceframework/qservicemanager.cpp18
-rw-r--r--tests/auto/qservicemanager_ipc/service/main.cpp6
6 files changed, 85 insertions, 21 deletions
diff --git a/src/serviceframework/ipc/instancemanager.cpp b/src/serviceframework/ipc/instancemanager.cpp
index 71b7b2a2fd..f408de0bfd 100644
--- a/src/serviceframework/ipc/instancemanager.cpp
+++ b/src/serviceframework/ipc/instancemanager.cpp
@@ -74,7 +74,7 @@ InstanceManager::~InstanceManager()
}
-bool InstanceManager::addType(const QMetaObject* meta,
+bool InstanceManager::addType(const QMetaObject* meta,
QRemoteServiceClassRegister::CreateServiceFunc func,
QRemoteServiceClassRegister::TypeIdentFunc typeFunc,
QRemoteServiceClassRegister::InstanceType type)
@@ -84,13 +84,13 @@ bool InstanceManager::addType(const QMetaObject* meta,
QMutexLocker ml(&lock);
if (metaMap.contains(ident)) {
- qWarning() << "Service" << ident.first << "(" << ident.second << ")"
+ qWarning() << "Service" << ident.name << "(" << ident.interface << ", " << ident.version << ")"
<< "already registered";
} else {
ServiceIdentDescriptor d;
d.meta = meta;
- d.instanceType = type;
d.create = func;
+ d.instanceType = type;
metaMap.insert(ident, d);
return true;
}
diff --git a/src/serviceframework/ipc/instancemanager_p.h b/src/serviceframework/ipc/instancemanager_p.h
index 569f19afb6..215326ba67 100644
--- a/src/serviceframework/ipc/instancemanager_p.h
+++ b/src/serviceframework/ipc/instancemanager_p.h
@@ -60,11 +60,11 @@ struct ServiceIdentDescriptor
}
const QMetaObject* meta;
+ QRemoteServiceClassRegister::CreateServiceFunc create;
QRemoteServiceClassRegister::InstanceType instanceType;
QHash<QUuid, QObject*> individualInstances;
QObject* sharedInstance;
QUuid sharedId;
- QRemoteServiceClassRegister::CreateServiceFunc create;
int sharedRefCount;
};
@@ -74,7 +74,7 @@ public:
InstanceManager();
~InstanceManager();
- bool addType(const QMetaObject* meta,
+ bool addType(const QMetaObject* meta,
QRemoteServiceClassRegister::CreateServiceFunc func,
QRemoteServiceClassRegister::TypeIdentFunc typeFunc,
QRemoteServiceClassRegister::InstanceType type);
diff --git a/src/serviceframework/qremoteserviceclassregister.cpp b/src/serviceframework/qremoteserviceclassregister.cpp
index dd0c3de96e..e94707247a 100644
--- a/src/serviceframework/qremoteserviceclassregister.cpp
+++ b/src/serviceframework/qremoteserviceclassregister.cpp
@@ -97,20 +97,20 @@ QTM_BEGIN_NAMESPACE
*/
/*!
- \macro Q_SERVICE(T, interface, version)
+ \macro Q_SERVICE(T, name, interface, version)
\relates QRemoteServiceClassRegister
This macro marks a class as remote service and should be placed next to the Q_OBJECT
- macro. \a T represents the name of the class implementing the service, \a interface
- specifies the service framework interface name and \a version represents the interface version. Version
- and interface parameter must match the interface information provided by the associated
+ macro. \a T represents the name of the class implementing the service, \a interface specifies
+ the service framework service name, interface name and \a version represents the interface
+ version. All parameters must match the interface information provided by the associated
service XML file.
\code
class ServiceClass : public QObject
{
Q_OBJECT
- Q_SERVICE(ServiceClass, "com.nokia.qt.interfacename", "1.2");
+ Q_SERVICE(ServiceClass, "ServiceName", "com.nokia.qt.interfacename", "1.2");
public:
ServiceClass(QObject* parent) : QObject(parent) {};
public slots:
diff --git a/src/serviceframework/qremoteserviceclassregister.h b/src/serviceframework/qremoteserviceclassregister.h
index 3ea3a25653..87c4b21ab4 100644
--- a/src/serviceframework/qremoteserviceclassregister.h
+++ b/src/serviceframework/qremoteserviceclassregister.h
@@ -45,10 +45,66 @@
#include "qmobilityglobal.h"
#include <QList>
#include <QPair>
+#include <QDebug>
+#include <QHash>
+
+QT_BEGIN_NAMESPACE
+class QDataStream;
+class QDebug;
+QT_END_NAMESPACE
QTM_BEGIN_NAMESPACE
-typedef QPair<QByteArray, QByteArray> QRemoteServiceIdentifier;
+//typedef QPair<QByteArray, QByteArray> QRemoteServiceIdentifier;
+
+struct QRemoteServiceIdentifier
+{
+ QByteArray name;
+ QByteArray interface;
+ QByteArray version;
+
+ QRemoteServiceIdentifier() : name(QByteArray()), interface(QByteArray()), version(QByteArray()) {}
+
+ QRemoteServiceIdentifier(const QByteArray &n, const QByteArray &i, const QByteArray &v) :
+ name(n), interface(i), version(v) {}
+
+ QRemoteServiceIdentifier& operator=(const QRemoteServiceIdentifier& other)
+ { name = other.name; interface = other.interface; version = other.version; return *this; }
+
+ bool operator==(const QRemoteServiceIdentifier& other) const {
+ if ( name == other.name && interface == other.interface && version == other.version ) return true;
+ return false;
+ }
+
+ inline bool operator!=(const QRemoteServiceIdentifier& other ) { return !operator==(other); }
+};
+
+ inline uint qHash(const QRemoteServiceIdentifier& key) {
+ return ( qHash(key.name) + qHash(key.interface) + qHash(key.version) );
+ }
+
+#ifndef QT_NO_DATASTREAM
+ inline QDataStream& operator>>(QDataStream& s, QRemoteServiceIdentifier& ident) {
+ s >> ident.name >> ident.interface >> ident.version;
+ return s;
+ }
+
+ inline QDataStream& operator<<(QDataStream& s, const QRemoteServiceIdentifier& ident) {
+ s << ident.name << ident.interface << ident.version;
+ return s;
+ }
+#endif
+
+#ifndef QT_NO_DEBUG_STREAM
+ inline QDebug operator<<(QDebug dbg, const QRemoteServiceIdentifier& ident) {
+ dbg.nospace() << "QRemoteServiceIdentifier("
+ << ident.name << ", "
+ << ident.interface << ", "
+ << ident.version << ")";
+ return dbg.space();
+ }
+#endif
+
class Q_SERVICEFW_EXPORT QRemoteServiceClassRegister
{
@@ -72,7 +128,7 @@ public:
}
};
-#define Q_SERVICE(T, interface, version) \
+#define Q_SERVICE(T, service, interface, version) \
public:\
static QObject* qt_sfw_create_instance() \
{ \
@@ -80,7 +136,7 @@ public:\
} \
static QRemoteServiceIdentifier qt_sfw_type_ident() \
{ \
- return QRemoteServiceIdentifier(interface, version); \
+ return QRemoteServiceIdentifier(service, interface, version); \
} \
private:
diff --git a/src/serviceframework/qservicemanager.cpp b/src/serviceframework/qservicemanager.cpp
index 400a27e098..5540bff685 100644
--- a/src/serviceframework/qservicemanager.cpp
+++ b/src/serviceframework/qservicemanager.cpp
@@ -44,11 +44,17 @@
#include "qabstractsecuritysession.h"
#include "qserviceinterfacedescriptor_p.h"
#ifdef Q_OS_SYMBIAN
- #include "databasemanager_symbian_p.h"
#include "qremoteservicecontrol_s60_p.h"
+#elif QT_NO_DBUS
+ #include "qremoteservicecontrol_p.h"
+#else
+ #include "qremoteservicecontrol_dbus_p.h"
+#endif
+
+#ifdef Q_OS_SYMBIAN
+ #include "databasemanager_symbian_p.h"
#else
#include "databasemanager_p.h"
- #include "qremoteservicecontrol_p.h"
#endif
#include <QObject>
@@ -98,7 +104,8 @@ static QString qservicemanager_resolveLibraryPath(const QString &libNameOrPath)
}
/*!
- For now we assume that localsocket means IPC via QLocalSocket.
+ For now we assume that localsocket means IPC via QLocalSocket and
+ dbus means IPC via QDBusConnection on the system bus.
This needs to be extended as new IPC mechanisms are incorporated.
*/
static bool qservicemanager_isIpcBasedService(const QString& location)
@@ -107,7 +114,8 @@ static bool qservicemanager_isIpcBasedService(const QString& location)
// TODO: we don't actually have to specify the specific ipc mechanism
// a simple flag would do.
if (location.startsWith("localsocket:") ||
- location.startsWith("symbianclientserver:"))
+ location.startsWith("symbianclientserver:") ||
+ location.startsWith("dbus:"))
return true;
return false;
}
@@ -416,7 +424,7 @@ QObject* QServiceManager::loadInterface(const QServiceInterfaceDescriptor& descr
if (qservicemanager_isIpcBasedService(location)) {
const QByteArray version = QString("%1.%2").arg(descriptor.majorVersion())
.arg(descriptor.minorVersion()).toLatin1();
- const QRemoteServiceIdentifier ident(descriptor.interfaceName().toLatin1(), version);
+ const QRemoteServiceIdentifier ident(descriptor.serviceName().toLatin1(), descriptor.interfaceName().toLatin1(), version);
QObject* service = QRemoteServiceControlPrivate::proxyForService(ident, location);
if (!service)
d->setError(InvalidServiceLocation);
diff --git a/tests/auto/qservicemanager_ipc/service/main.cpp b/tests/auto/qservicemanager_ipc/service/main.cpp
index 0d60c17f09..ed90a4a8dc 100644
--- a/tests/auto/qservicemanager_ipc/service/main.cpp
+++ b/tests/auto/qservicemanager_ipc/service/main.cpp
@@ -55,7 +55,7 @@ Q_DECLARE_METATYPE(QVariant)
class SharedTestService : public QObject
{
Q_OBJECT
- Q_SERVICE(SharedTestService, "com.nokia.qt.ipcunittest", "3.4")
+ Q_SERVICE(SharedTestService, "IPCExampleService", "com.nokia.qt.ipcunittest", "3.4")
Q_PROPERTY(QString value READ value WRITE setValue RESET resetValue NOTIFY valueChanged SCRIPTABLE true DESIGNABLE true STORED true);
public:
@@ -169,7 +169,7 @@ private:
class UniqueTestService : public QObject
{
Q_OBJECT
- Q_SERVICE(UniqueTestService, "com.nokia.qt.ipcunittest", "3.5")
+ Q_SERVICE(UniqueTestService, "IPCExampleService", "com.nokia.qt.ipcunittest", "3.5")
Q_CLASSINFO("UniqueTestService", "First test");
Q_CLASSINFO("Key", "Value");
@@ -352,7 +352,7 @@ Q_DECLARE_METATYPE(QMetaType::Type);
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
-
+
qRegisterMetaType<QServiceFilter>();
qRegisterMetaTypeStreamOperators<QServiceFilter>("QServiceFilter");
// QVariant is built in with 4.7