summaryrefslogtreecommitdiffstats
path: root/src/imports/serviceframework/qdeclarativeservice_p.h
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2012-04-26 19:32:48 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-19 06:39:41 +0200
commitffc209f6e365e7a32cb3c7b5d09f72c54f47d2a2 (patch)
treeb57f9eac92bdf43bf3bba852bd0b52c495e495be /src/imports/serviceframework/qdeclarativeservice_p.h
parentb04b5a3f5b7696c3d23cefaae23359fb9efcd315 (diff)
Adds new asynchronous friendly types.
The old types will probably be deprecated at some point, but they're still provided so that users have time to switch. Change-Id: I0f3068e77d4252e777a2771950fc665f0d509bb7 Reviewed-by: Andrew Stanley-Jones <andrew.stanley-jones@nokia.com>
Diffstat (limited to 'src/imports/serviceframework/qdeclarativeservice_p.h')
-rw-r--r--src/imports/serviceframework/qdeclarativeservice_p.h378
1 files changed, 263 insertions, 115 deletions
diff --git a/src/imports/serviceframework/qdeclarativeservice_p.h b/src/imports/serviceframework/qdeclarativeservice_p.h
index 396fb8d7..e2e0756d 100644
--- a/src/imports/serviceframework/qdeclarativeservice_p.h
+++ b/src/imports/serviceframework/qdeclarativeservice_p.h
@@ -39,9 +39,8 @@
**
***************************************************************************/
-#ifndef QDECLARATIVESERVICE_H
-#define QDECLARATIVESERVICE_H
-
+#ifndef QDECLARATIVESERVICE_P_H
+#define QDECLARATIVESERVICE_P_H
#include <QtCore>
#include <qserviceinterfacedescriptor.h>
#include <qservicemanager.h>
@@ -50,160 +49,309 @@
QT_BEGIN_NAMESPACE
-class QDeclarativeService : public QObject, public QQmlParserStatus {
+class QDeclarativeServiceDescriptor : public QObject, public QServiceInterfaceDescriptor {
+ Q_OBJECT
+ Q_PROPERTY(QString serviceName READ serviceName CONSTANT)
+ Q_PROPERTY(QString interfaceName READ interfaceName CONSTANT)
+ Q_PROPERTY(int majorVersion READ majorVersion CONSTANT)
+ Q_PROPERTY(int minorVersion READ minorVersion CONSTANT)
+ Q_PROPERTY(bool valid READ isValid CONSTANT)
+
+public:
+ QDeclarativeServiceDescriptor(QObject* parent = 0) : QObject(parent) {}
+ QDeclarativeServiceDescriptor(const QDeclarativeServiceDescriptor& other)
+ : QObject(0), QServiceInterfaceDescriptor(other) {}
+ QDeclarativeServiceDescriptor(const QServiceInterfaceDescriptor& other)
+ : QObject(0), QServiceInterfaceDescriptor(other) {}
+ bool operator==(const QServiceInterfaceDescriptor& other) const
+ { return QServiceInterfaceDescriptor::operator==(other); }
+ QDeclarativeServiceDescriptor& operator=(const QServiceInterfaceDescriptor& other)
+ {
+ QServiceInterfaceDescriptor::operator=(other);
+ return *this;
+ }
+ QDeclarativeServiceDescriptor& operator=(const QDeclarativeServiceDescriptor& other)
+ {
+ QServiceInterfaceDescriptor::operator=(other);
+ return *this;
+ }
+};
+
+class QDeclarativeServiceLoader : public QObject, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
- Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
- Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged)
- Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged)
- Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
+ // ### Rename descriptor?
+ Q_PROPERTY(QDeclarativeServiceDescriptor* serviceDescriptor READ serviceDescriptor WRITE setServiceDescriptor NOTIFY serviceDescriptorChanged RESET resetServiceDescriptor) //Takes precedence over interfaceName if set
+ Q_PROPERTY(Status status READ status NOTIFY statusChanged)
+ Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
+ // ### Rename object?
Q_PROPERTY(QObject* serviceObject READ serviceObject NOTIFY serviceObjectChanged)
- Q_PROPERTY(QString error READ lastError NOTIFY error)
+ Q_ENUMS(Status)
public:
- QDeclarativeService();
- ~QDeclarativeService();
-
- void setInterfaceDesc(const QServiceInterfaceDescriptor& desc);
- QServiceInterfaceDescriptor interfaceDesc() const;
-
- void setInterfaceName(const QString& interface);
- QString interfaceName() const;
- QString serviceName() const;
- void setServiceName(const QString &service);
- int majorVersion() const;
- void setMajorVersion(int version);
- int minorVersion() const;
- void setMinorVersion(int version);
- QString lastError() const;
-
- bool isValid() const;
- QObject* serviceObject();
-
- //Derived from QQmlParserStatus
- virtual void classBegin();
- virtual void componentComplete();
+ enum Status {
+ Null = 0,
+ Ready,
+ Loading,
+ Error
+ };
- bool operator== ( const QServiceInterfaceDescriptor& other ) const;
+ QDeclarativeServiceLoader();
+ ~QDeclarativeServiceLoader();
+
+ Q_INVOKABLE QString errorString() const
+ {
+ if (m_status == Error)
+ return m_errorString;
+ else
+ return "";
+ }
+
+ QString interfaceName() const
+ {
+ return m_interfaceName;
+ }
+
+ QDeclarativeServiceDescriptor* serviceDescriptor() const
+ {
+ return m_serviceDescriptor;
+ }
+
+ void resetServiceDescriptor()
+ {
+ setServiceDescriptor(0);
+ }
+
+ Status status() const
+ {
+ return m_status;
+ }
+
+ bool asynchronous() const
+ {
+ return m_asynchronous;
+ }
+
+ QObject* serviceObject() const
+ {
+ return m_serviceObject;
+ }
+
+public slots:
+ void setInterfaceName(QString arg)
+ {
+ if (m_interfaceName != arg) {
+ m_interfaceName = arg;
+ emit interfaceNameChanged(arg);
+ if (!m_serviceDescriptor && m_componentComplete)
+ startLoading();
+ }
+ }
+
+ void setServiceDescriptor(QDeclarativeServiceDescriptor* arg)
+ {
+ if (m_serviceDescriptor != arg) {
+ m_serviceDescriptor = arg;
+ emit serviceDescriptorChanged(arg);
+ if (m_componentComplete)
+ startLoading();
+ }
+ }
+
+ void setAsynchronous(bool arg)
+ {
+ if (m_asynchronous != arg) {
+ m_asynchronous = arg;
+ emit asynchronousChanged(arg);
+ }
+ }
-Q_SIGNALS:
- void validChanged();
- void serviceObjectChanged();
- void interfaceNameChanged();
- void serviceNameChanged();
- void majorVersionChanged();
- void minorVersionChanged();
+private Q_SLOTS:
+ void setStatus(Status arg)
+ {
+ if (m_status != arg) {
+ m_status = arg;
+ emit statusChanged(arg);
+ }
+ }
+
+protected:
+ virtual void classBegin() {}
+ virtual void componentComplete();
- void error(const QString &errorString);
+signals:
+ void interfaceNameChanged(QString arg);
-private Q_SLOTS:
- void IPCFault(QService::UnrecoverableIPCError);
+ void serviceDescriptorChanged(QServiceInterfaceDescriptor* arg);
-private:
- void updateDescriptor();
- void setServiceObject(QObject *object);
+ void statusChanged(Status arg);
- QPointer<QObject> m_serviceInstance;
- QServiceManager* m_serviceManager;
+ void asynchronousChanged(bool arg);
- QServiceInterfaceDescriptor m_descriptor;
+ void serviceObjectChanged(QObject* arg);
- int m_minor;
- int m_major;
- QString m_service;
- QString m_interface;
+private slots:
+ void startLoading();
+ void finishLoading();
+ void IPCFault(QService::UnrecoverableIPCError);
- QString m_error;
+private:
+ QString m_interfaceName;
+ QDeclarativeServiceDescriptor* m_serviceDescriptor;
+ Status m_status;
+ bool m_asynchronous;
+ QObject* m_serviceObject;
+ QString m_errorString;
bool m_componentComplete;
+ QServiceManager* m_serviceManager;
+ QServiceReply* m_serviceReply;
};
-
-class QDeclarativeServiceList : public QObject, public QQmlParserStatus {
+class QDeclarativeServiceFilter : public QObject, public QQmlParserStatus {
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QString serviceName READ serviceName WRITE setServiceName NOTIFY serviceNameChanged)
Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName NOTIFY interfaceNameChanged)
Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged)
Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged)
+ Q_PROPERTY(bool exactVersionMatching READ exactVersionMatching WRITE setExactVersionMatching NOTIFY exactVersionMatchingChanged)
+ // ### Rename monitorRegistrations ?
Q_PROPERTY(bool monitorServiceRegistrations READ monitorServiceRegistrations WRITE setMonitorServiceRegistrations NOTIFY monitorServiceRegistrationsChanged)
- Q_PROPERTY(QQmlListProperty<QDeclarativeService> services READ services NOTIFY resultsChanged)
-
- Q_PROPERTY(MatchRule versionMatch READ versionMatch WRITE setVersionMatch NOTIFY versionMatchChanged)
- Q_ENUMS(MatchRule)
-
+ // ### Rename services ?
+ Q_PROPERTY(QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions READ serviceDescriptions NOTIFY serviceDescriptionsChanged)
public:
- enum MatchRule {
- Minimum = 0,
- Exact
- };
-
- QDeclarativeServiceList();
- ~QDeclarativeServiceList();
+ QDeclarativeServiceFilter(QObject* parent = 0);
+ ~QDeclarativeServiceFilter();
+ QString serviceName() const
+ {
+ return m_serviceName;
+ }
+
+ QString interfaceName() const
+ {
+ return m_interfaceName;
+ }
+
+ int majorVersion() const
+ {
+ return m_majorVersion;
+ }
+
+ int minorVersion() const
+ {
+ return m_minorVersion;
+ }
+
+ bool exactVersionMatching() const
+ {
+ return m_exactVersionMatching;
+ }
+
+ bool monitorServiceRegistrations() const
+ {
+ return m_monitorServiceRegistrations;
+ }
+
+ QQmlListProperty<QDeclarativeServiceDescriptor> serviceDescriptions()
+ {
+ return QQmlListProperty<QDeclarativeServiceDescriptor> (this, 0, s_append, s_count, s_at, s_clear);
+ }
+
+public slots:
+ void setServiceName(QString arg)
+ {
+ if (m_serviceName != arg) {
+ m_serviceName = arg;
+ emit serviceNameChanged(arg);
+ updateServiceList();
+ }
+ }
+
+ void setInterfaceName(QString arg)
+ {
+ if (m_interfaceName != arg) {
+ m_interfaceName = arg;
+ emit interfaceNameChanged(arg);
+ updateServiceList();
+ }
+ }
+
+ void setMajorVersion(int arg)
+ {
+ if (m_majorVersion != arg) {
+ m_majorVersion = arg;
+ emit majorVersionChanged(arg);
+ updateServiceList();
+ }
+ }
+
+ void setMinorVersion(int arg)
+ {
+ if (m_minorVersion != arg) {
+ m_minorVersion = arg;
+ emit minorVersionChanged(arg);
+ updateServiceList();
+ }
+ }
+
+ void setExactVersionMatching(bool arg)
+ {
+ if (m_exactVersionMatching != arg) {
+ m_exactVersionMatching = arg;
+ emit exactVersionMatchingChanged(arg);
+ updateServiceList();
+ }
+ }
- QQmlListProperty<QDeclarativeService> services();
-
- void setServiceName(const QString& service);
- QString serviceName() const;
+ void setMonitorServiceRegistrations(bool updates);
- void setInterfaceName(const QString& interface);
- QString interfaceName() const;
+protected:
+ virtual void classBegin() {}
+ virtual void componentComplete();
+signals:
+ void serviceNameChanged(QString arg);
- void setMinorVersion(int minor);
- int minorVersion() const;
+ void interfaceNameChanged(QString arg);
- void setMajorVersion(int major);
- int majorVersion() const;
+ void majorVersionChanged(int arg);
- void setMonitorServiceRegistrations(bool updates);
- bool monitorServiceRegistrations() const;
+ void minorVersionChanged(int arg);
- void setVersionMatch(QDeclarativeServiceList::MatchRule match);
- QDeclarativeServiceList::MatchRule versionMatch() const;
+ void exactVersionMatchingChanged(bool arg);
- void listUpdated();
+ void monitorServiceRegistrationsChanged(bool arg);
- //Derived from QQmlParserStatus
- virtual void classBegin();
- virtual void componentComplete();
+ void serviceDescriptionsChanged();
-Q_SIGNALS:
- void resultsChanged();
- void servicesChanged(const QQmlListProperty<QDeclarativeService>&);
- void serviceNameChanged();
- void interfaceNameChanged();
- void minorVersionChanged();
- void majorVersionChanged();
- void versionMatchChanged();
- void monitorServiceRegistrationsChanged();
-
-protected Q_SLOTS:
- void servicesAddedRemoved();
- void updateFilterResults();
+private slots:
void updateServiceList();
-
+ void servicesAddedRemoved();
private:
- QList<QDeclarativeService *> m_services;
- QList<QServiceInterfaceDescriptor> m_currentList;
- QServiceManager* serviceManager;
- QString m_service;
- QString m_interface;
- int m_major;
- int m_minor;
- QDeclarativeServiceList::MatchRule m_match;
+ QString m_serviceName;
+ QString m_interfaceName;
+ int m_majorVersion;
+ int m_minorVersion;
+ bool m_exactVersionMatching;
+ bool m_monitorServiceRegistrations;
+ QQmlListProperty<QDeclarativeServiceDescriptor*> m_serviceDescriptions;
+ QList<QDeclarativeServiceDescriptor> m_services;
+
+ QServiceManager* m_serviceManager;
bool m_componentComplete;
- bool m_dynamicUpdates;
- static void s_append(QQmlListProperty<QDeclarativeService> *prop, QDeclarativeService *service);
- static int s_count(QQmlListProperty<QDeclarativeService> *prop);
- static QDeclarativeService* s_at(QQmlListProperty<QDeclarativeService> *prop, int index);
- static void s_clear(QQmlListProperty<QDeclarativeService> *prop);
+ static void s_append(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, QDeclarativeServiceDescriptor *service);
+ static int s_count(QQmlListProperty<QDeclarativeServiceDescriptor> *prop);
+ static QDeclarativeServiceDescriptor* s_at(QQmlListProperty<QDeclarativeServiceDescriptor> *prop, int index);
+ static void s_clear(QQmlListProperty<QDeclarativeServiceDescriptor> *prop);
};
QT_END_NAMESPACE
-QML_DECLARE_TYPE(QDeclarativeService);
-QML_DECLARE_TYPE(QDeclarativeServiceList);
+QML_DECLARE_TYPE(QDeclarativeServiceLoader);
+QML_DECLARE_TYPE(QDeclarativeServiceDescriptor);
+QML_DECLARE_TYPE(QDeclarativeServiceFilter);
+
-#endif
+#endif // QDECLARATIVESERVICE_P_H