summaryrefslogtreecommitdiff
path: root/src/webchannel/qmetaobjectpublisher_p.h
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-12-28 19:20:58 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-08 15:59:28 +0100
commit66c0d916131c1e9e896705971f20385c75e753a2 (patch)
tree59b25cd7b9bc1ff688ff46c2b4f4c21fa60019cf /src/webchannel/qmetaobjectpublisher_p.h
parent318576f0cc0ebef78c5b27106b1a8429eb54fac8 (diff)
downloadqtwebchannel-66c0d916131c1e9e896705971f20385c75e753a2.tar.gz
Simplify usage of QWebChannel on the server side.
This is achieved by hiding the MetaObjectPublisher completely as private API. The QWebChannel is the only publisher API and now handles both the socket as well as the publisher internally. This now allows us to create a proper QML api in the new QmlWebChannel. Change-Id: I3096364af8485353ca9bc19df4a81a8e4552c3d7 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher_p.h')
-rw-r--r--src/webchannel/qmetaobjectpublisher_p.h62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/webchannel/qmetaobjectpublisher_p.h b/src/webchannel/qmetaobjectpublisher_p.h
index 4df5b38..a7342d0 100644
--- a/src/webchannel/qmetaobjectpublisher_p.h
+++ b/src/webchannel/qmetaobjectpublisher_p.h
@@ -51,14 +51,40 @@
#include <QBasicTimer>
#include <QPointer>
-class QMetaObjectPublisher;
class QWebChannel;
#include "qwebchannelglobal.h"
-struct Q_WEBCHANNEL_EXPORT QMetaObjectPublisherPrivate
+class Q_WEBCHANNEL_EXPORT QMetaObjectPublisher : public QObject
{
- QMetaObjectPublisherPrivate(QMetaObjectPublisher *q);
+ Q_OBJECT
+
+public:
+ QMetaObjectPublisher(QWebChannel *webChannel);
+ virtual ~QMetaObjectPublisher();
+
+ /**
+ * Register @p object nuder the given @p id.
+ *
+ * The properties, signals and public methods of the QObject are
+ * published to the remote client, where an object with the given identifier
+ * is constructed.
+ *
+ * TODO: This must be called, before clients are initialized.
+ */
+ void registerObject(const QString &id, QObject *object);
+
+ /**
+ * Handle the given WebChannel client request and potentially give a response.
+ *
+ * @return true if the request was handled, false otherwise.
+ */
+ bool handleRequest(const QJsonObject &message);
+
+ /**
+ * Serialize the QMetaObject of @p object and return it in JSON form.
+ */
+ QJsonObject classInfoForObject(const QObject *object) const;
/**
* Set the client to idle or busy, based on the value of @p isIdle.
@@ -128,9 +154,33 @@ struct Q_WEBCHANNEL_EXPORT QMetaObjectPublisherPrivate
*/
void deleteWrappedObject(QObject *object) const;
- QMetaObjectPublisher *q;
- QPointer<QWebChannel> webChannel;
- SignalHandler<QMetaObjectPublisherPrivate> signalHandler;
+ /**
+ * When updates are blocked, no property updates are transmitted to remote clients.
+ */
+ void setBlockUpdates(bool block);
+
+public slots:
+ /**
+ * Helper slot which you can connect directly to WebChannel's rawMessageReceived signal.
+ *
+ * This slot then tries to parse the message as JSON and if it succeeds, calls handleRequest
+ * with the obtained JSON object.
+ */
+ void handleRawMessage(const QString &message);
+
+signals:
+ void blockUpdatesChanged(bool block);
+
+protected:
+ void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;
+
+private:
+ friend class QmlWebChannel;
+ friend class QWebChannel;
+ friend class TestWebChannel;
+
+ QWebChannel *webChannel;
+ SignalHandler<QMetaObjectPublisher> signalHandler;
// true when the client is idle, false otherwise
bool clientIsIdle;