diff options
Diffstat (limited to 'src/webchannel/qmetaobjectpublisher_p.h')
-rw-r--r-- | src/webchannel/qmetaobjectpublisher_p.h | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/webchannel/qmetaobjectpublisher_p.h b/src/webchannel/qmetaobjectpublisher_p.h index 05f33bd..359135c 100644 --- a/src/webchannel/qmetaobjectpublisher_p.h +++ b/src/webchannel/qmetaobjectpublisher_p.h @@ -40,6 +40,8 @@ #include <QStringList> #include <QMetaObject> #include <QBasicTimer> +#include <QPointer> +#include <QJsonObject> #include "qwebchannelglobal.h" @@ -70,7 +72,6 @@ class QWebChannelAbstractTransport; class Q_WEBCHANNEL_EXPORT QMetaObjectPublisher : public QObject { Q_OBJECT - public: explicit QMetaObjectPublisher(QWebChannel *webChannel); virtual ~QMetaObjectPublisher(); @@ -94,7 +95,7 @@ public: /** * Serialize the QMetaObject of @p object and return it in JSON form. */ - QJsonObject classInfoForObject(const QObject *object); + QJsonObject classInfoForObject(const QObject *object, QWebChannelAbstractTransport *transport); /** * Set the client to idle or busy, based on the value of @p isIdle. @@ -108,7 +109,7 @@ public: * * Furthermore, if that was not done already, connect to their property notify signals. */ - void initializeClients(); + QJsonObject initializeClient(QWebChannelAbstractTransport *transport); /** * Go through all properties of the given object and connect to their notify signal. @@ -135,7 +136,7 @@ public: * The return value of the method invocation is then serialized and a response message * is returned. */ - QJsonValue invokeMethod(QObject *const object, const int methodIndex, const QJsonArray &args); + QVariant invokeMethod(QObject *const object, const int methodIndex, const QJsonArray &args); /** * Callback of the signalHandler which forwards the signal invocation to the webchannel clients. @@ -155,14 +156,16 @@ public: * * All other input types are returned as-is. */ - QJsonValue wrapResult(const QVariant &result); + QJsonValue wrapResult(const QVariant &result, QWebChannelAbstractTransport *transport, + const QString &parentObjectId = QString()); /** * Convert a list of variant values for consumption by the client. * * This properly handles QML values and also wraps the result if required. */ - QJsonArray wrapList(const QVariantList &list); + QJsonArray wrapList(const QVariantList &list, QWebChannelAbstractTransport *transport, + const QString &parentObjectId = QString()); /** * Invoke delete later on @p object. @@ -200,10 +203,6 @@ private: // true when no property updates should be sent, false otherwise bool blockUpdates; - // true when at least one client needs to be initialized, - // i.e. when a Qt.init came in which was not handled yet. - bool pendingInit; - // true when at least one client was initialized and thus // the property updates have been initialized and the // object info map set. @@ -215,6 +214,24 @@ private: // Map the registered objects to their id. QHash<const QObject *, QString> registeredObjectIds; + // Groups individually wrapped objects with their class information and the transports that have access to it. + struct ObjectInfo + { + ObjectInfo() + : object(Q_NULLPTR) + {} + ObjectInfo(QObject *o, const QJsonObject &i) + : object(o) + , classinfo(i) + {} + QObject *object; + QJsonObject classinfo; + QVector<QWebChannelAbstractTransport*> transports; + }; + + // Map of objects wrapped from invocation returns + QHash<QString, ObjectInfo> wrappedObjects; + // Map of objects to maps of signal indices to a set of all their property indices. // The last value is a set as a signal can be the notify signal of multiple properties. typedef QHash<int, QSet<int> > SignalToPropertyNameMap; @@ -226,9 +243,6 @@ private: typedef QHash<const QObject *, SignalToArgumentsMap> PendingPropertyUpdates; PendingPropertyUpdates pendingPropertyUpdates; - // Maps wrapped object to class info - QHash<const QObject *, QJsonObject> wrappedObjects; - // Aggregate property updates since we get multiple Qt.idle message when we have multiple // clients. They all share the same QWebProcess though so we must take special care to // prevent message flooding. |