diff options
author | Lincoln Ramsay <a1291762@gmail.com> | 2012-09-17 20:08:54 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-15 13:27:04 +0100 |
commit | daec59aefa9b458a9e50fee85b359d9da964a6f1 (patch) | |
tree | 4b5ee51d91fcaf153b8c429685ebc12fa53bc0ae /src/serviceframework | |
parent | 511d739cd984bcca944424513b8779fe17d7b151 (diff) |
Allow using QRemoteServiceRegister for types other than IPC.
Change-Id: Ic8ca7e4c48df42dad63bda87fc5d5ecb4cbd5410
Reviewed-by: Andrew Stanley-Jones <asj@cban.com>
Diffstat (limited to 'src/serviceframework')
-rw-r--r-- | src/serviceframework/ipc/qremoteserviceregister_p.cpp | 12 | ||||
-rw-r--r-- | src/serviceframework/ipc/qremoteserviceregister_p.h | 3 | ||||
-rw-r--r-- | src/serviceframework/qremoteserviceregister.cpp | 30 | ||||
-rw-r--r-- | src/serviceframework/qremoteserviceregister.h | 4 |
4 files changed, 47 insertions, 2 deletions
diff --git a/src/serviceframework/ipc/qremoteserviceregister_p.cpp b/src/serviceframework/ipc/qremoteserviceregister_p.cpp index 14688d11..1050ae27 100644 --- a/src/serviceframework/ipc/qremoteserviceregister_p.cpp +++ b/src/serviceframework/ipc/qremoteserviceregister_p.cpp @@ -141,6 +141,18 @@ bool QRemoteServiceRegisterPrivate::isBaseGroupIdentifierSet() const return groupIdentifierSet; } +QRemoteServiceRegisterPrivate *QRemoteServiceRegisterPrivate::constructPrivateObject(QService::Type serviceType, QObject *parent) +{ + QRemoteServiceRegisterPrivate *d = 0; + switch (serviceType) { + case QService::InterProcess: + d = QRemoteServiceRegisterPrivate::constructPrivateObject(parent); + break; + default: + qFatal("Cannot create a QRemoteServiceRegister with unknown service type %d", serviceType); + } + return d; +} #include "moc_qremoteserviceregister_p.cpp" QT_END_NAMESPACE diff --git a/src/serviceframework/ipc/qremoteserviceregister_p.h b/src/serviceframework/ipc/qremoteserviceregister_p.h index db6e672e..a3cecc64 100644 --- a/src/serviceframework/ipc/qremoteserviceregister_p.h +++ b/src/serviceframework/ipc/qremoteserviceregister_p.h @@ -93,9 +93,12 @@ private: bool groupIdentifierSet; public: + // These methods apply to IPC services only static QObject* proxyForService(const QRemoteServiceRegister::Entry& entry, const QString& location); static QRemoteServiceRegisterPrivate* constructPrivateObject(QObject *parent); static bool isServiceRunning(const QRemoteServiceRegister::Entry&, const QString& location); + // Create a private object based on the service type + static QRemoteServiceRegisterPrivate* constructPrivateObject(QService::Type serviceType, QObject *parent); }; QT_END_NAMESPACE diff --git a/src/serviceframework/qremoteserviceregister.cpp b/src/serviceframework/qremoteserviceregister.cpp index b82f6a18..8e505f47 100644 --- a/src/serviceframework/qremoteserviceregister.cpp +++ b/src/serviceframework/qremoteserviceregister.cpp @@ -46,6 +46,7 @@ #include "qserviceclientcredentials_p.h" #include <QtCore/QDataStream> +#include <QtCore/QEvent> QT_BEGIN_NAMESPACE @@ -293,9 +294,8 @@ QRemoteServiceRegister::InstanceType QRemoteServiceRegister::Entry::instantiatio */ QRemoteServiceRegister::QRemoteServiceRegister(QObject* parent) : QObject(parent) + , d(0) { - d = QRemoteServiceRegisterPrivate::constructPrivateObject(this); - connect(InstanceManager::instance(), SIGNAL(allInstancesClosed()), this, SIGNAL(allInstancesClosed())); connect(InstanceManager::instance(), SIGNAL(instanceClosed(QRemoteServiceRegister::Entry)), @@ -322,6 +322,7 @@ QRemoteServiceRegister::~QRemoteServiceRegister() */ void QRemoteServiceRegister::publishEntries(const QString& ident) { + if (!d) init(); d->publishServices(ident); } @@ -332,11 +333,13 @@ void QRemoteServiceRegister::publishEntries(const QString& ident) */ bool QRemoteServiceRegister::quitOnLastInstanceClosed() const { + if (!d) const_cast<QRemoteServiceRegister*>(this)->init(); return d->quitOnLastInstanceClosed(); } void QRemoteServiceRegister::setQuitOnLastInstanceClosed(bool quit) { + if (!d) init(); d->setQuitOnLastInstanceClosed(quit); } @@ -350,6 +353,7 @@ void QRemoteServiceRegister::setQuitOnLastInstanceClosed(bool quit) void QRemoteServiceRegister::setBaseUserIdentifier(qintptr uid) { + if (!d) init(); d->setBaseUserIdentifier(uid); } @@ -361,6 +365,7 @@ void QRemoteServiceRegister::setBaseUserIdentifier(qintptr uid) qintptr QRemoteServiceRegister::getBaseUserIdentifier() const { + if (!d) const_cast<QRemoteServiceRegister*>(this)->init(); return d->getBaseUserIdentifier(); } @@ -373,6 +378,7 @@ qintptr QRemoteServiceRegister::getBaseUserIdentifier() const void QRemoteServiceRegister::setBaseGroupIdentifier(qintptr gid) { + if (!d) init(); d->setBaseGroupIdentifier(gid); } @@ -384,6 +390,7 @@ void QRemoteServiceRegister::setBaseGroupIdentifier(qintptr gid) qintptr QRemoteServiceRegister::getBaseGroupIdentifier() const { + if (!d) const_cast<QRemoteServiceRegister*>(this)->init(); return d->getBaseGroupIdentifier(); } @@ -397,6 +404,7 @@ qintptr QRemoteServiceRegister::getBaseGroupIdentifier() const void QRemoteServiceRegister::setSecurityAccessOptions(SecurityAccessOptions options) { + if (!d) init(); d->setSecurityOptions(options); } @@ -437,6 +445,7 @@ void QRemoteServiceRegister::setSecurityAccessOptions(SecurityAccessOptions opti */ QRemoteServiceRegister::SecurityFilter QRemoteServiceRegister::setSecurityFilter(QRemoteServiceRegister::SecurityFilter filter) { + if (!d) init(); return d->setSecurityFilter(filter); } @@ -471,6 +480,23 @@ QRemoteServiceRegister::Entry QRemoteServiceRegister::createEntry(const QString& return e; } +bool QRemoteServiceRegister::event(QEvent *e) +{ + if (!d && e->type() == QEvent::DynamicPropertyChange) { + QDynamicPropertyChangeEvent *event = static_cast<QDynamicPropertyChangeEvent*>(e); + if (event->propertyName() == QByteArray("serviceType")) { + QService::Type serviceType = static_cast<QService::Type>(property("serviceType").toInt()); + d = QRemoteServiceRegisterPrivate::constructPrivateObject(serviceType, this); + } + } + + return QObject::event(e); +} + +void QRemoteServiceRegister::init() +{ + d = QRemoteServiceRegisterPrivate::constructPrivateObject(this); +} #ifndef QT_NO_DATASTREAM Q_SERVICEFW_EXPORT QDataStream& operator>>(QDataStream& s, QRemoteServiceRegister::Entry& entry) { diff --git a/src/serviceframework/qremoteserviceregister.h b/src/serviceframework/qremoteserviceregister.h index ffc135dc..93a5f49c 100644 --- a/src/serviceframework/qremoteserviceregister.h +++ b/src/serviceframework/qremoteserviceregister.h @@ -50,6 +50,7 @@ #include <QExplicitlySharedDataPointer> #include "qserviceclientcredentials.h" +#include "qservice.h" QT_BEGIN_NAMESPACE @@ -150,6 +151,9 @@ private: const QString& interfaceName, const QString& version, CreateServiceFunc cptr, const QMetaObject* meta); + void init(); + bool event(QEvent *e); + QRemoteServiceRegisterPrivate* d; }; |