summaryrefslogtreecommitdiff
path: root/src/webchannel/qmetaobjectpublisher_p.h
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-07-10 00:05:28 +0200
committerMilian Wolff <milian.wolff@kdab.com>2014-07-29 13:58:04 +0200
commit94912cf26ba70a2cadd23f1c931395be64c11eac (patch)
tree28cfa1d98bbcc7eeccba6de1e3317e30add56a2f /src/webchannel/qmetaobjectpublisher_p.h
parent77a4c34bb0f3b8cc3107f9fc6be0f5f7b23bb9d6 (diff)
downloadqtwebchannel-94912cf26ba70a2cadd23f1c931395be64c11eac.tar.gz
Refactor and streamline API and IPC protocol.
This patch removes the obsolete API support to send raw messages using a QWebChannel. Instead, it is encouraged to directly use WebSockets or navigator.qt. By doing so, we can cleanup the code considerably. While at it, the transport API is adapted to work on QJsonObject messages, instead of QStrings. This will allow us to use more efficient formats in e.g. QtWebKit or QtWebEngine. One could also implement a JSONRPC interface using a custom transport then. Change-Id: Ia8c125a5558507b3cbecf128a46b19fdb013f47b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher_p.h')
-rw-r--r--src/webchannel/qmetaobjectpublisher_p.h33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/webchannel/qmetaobjectpublisher_p.h b/src/webchannel/qmetaobjectpublisher_p.h
index 4da0c26..82afe57 100644
--- a/src/webchannel/qmetaobjectpublisher_p.h
+++ b/src/webchannel/qmetaobjectpublisher_p.h
@@ -54,7 +54,28 @@
QT_BEGIN_NAMESPACE
+// NOTE: keep in sync with corresponding maps in qwebchannel.js and WebChannelTest.qml
+enum MessageType {
+ TypeInvalid = 0,
+
+ TYPES_FIRST_VALUE = 1,
+
+ TypeSignal = 1,
+ TypePropertyUpdate = 2,
+ TypeInit = 3,
+ TypeIdle = 4,
+ TypeDebug = 5,
+ TypeInvokeMethod = 6,
+ TypeConnectToSignal = 7,
+ TypeDisconnectFromSignal = 8,
+ TypeSetProperty = 9,
+ TypeResponse = 10,
+
+ TYPES_LAST_VALUE = 10
+};
+
class QWebChannel;
+class QWebChannelAbstractTransport;
class Q_WEBCHANNEL_EXPORT QMetaObjectPublisher : public QObject
{
Q_OBJECT
@@ -75,11 +96,9 @@ public:
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.
+ * Send the given message to all known transports.
*/
- QByteArray handleRequest(const QJsonObject &message);
+ void broadcastMessage(const QJsonObject &message) const;
/**
* Serialize the QMetaObject of @p object and return it in JSON form.
@@ -125,7 +144,7 @@ public:
* The return value of the method invocation is then serialized and a response message
* is returned.
*/
- QByteArray invokeMethod(QObject *const object, const int methodIndex, const QJsonArray &args, const QJsonValue &id);
+ QJsonValue invokeMethod(QObject *const object, const int methodIndex, const QJsonArray &args);
/**
* Callback of the signalHandler which forwards the signal invocation to the webchannel clients.
@@ -164,9 +183,9 @@ Q_SIGNALS:
public Q_SLOTS:
/**
- * Parse the message as JSON and if it succeeds, call handleRequest with the obtained JSON object.
+ * Handle the @p message and if needed send a response to @p transport.
*/
- void handleMessage(const QString &message);
+ void handleMessage(const QJsonObject &message, QWebChannelAbstractTransport *transport);
protected:
void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE;