| 1 | // Copyright (C) 2017 Ford Motor Company |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQREMOTEOBJECTREPLICA_H |
| 5 | #define QQREMOTEOBJECTREPLICA_H |
| 6 | |
| 7 | #include <QtRemoteObjects/qtremoteobjectglobal.h> |
| 8 | |
| 9 | #include <QtCore/qobject.h> |
| 10 | #include <QtCore/qsharedpointer.h> |
| 11 | |
| 12 | Q_MOC_INCLUDE(<QtRemoteObjects/qremoteobjectnode.h>) |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QObjectPrivate; |
| 17 | class QRemoteObjectPendingCall; |
| 18 | class QRemoteObjectReplicaImplementation; |
| 19 | class QReplicaImplementationInterface; |
| 20 | class QRemoteObjectNode; |
| 21 | |
| 22 | class Q_REMOTEOBJECTS_EXPORT QRemoteObjectReplica : public QObject |
| 23 | { |
| 24 | Q_OBJECT |
| 25 | Q_PROPERTY(QRemoteObjectNode *node READ node WRITE setNode) |
| 26 | Q_PROPERTY(State state READ state NOTIFY stateChanged) |
| 27 | public: |
| 28 | enum State { |
| 29 | Uninitialized, |
| 30 | Default, |
| 31 | Valid, |
| 32 | Suspect, |
| 33 | SignatureMismatch |
| 34 | }; |
| 35 | Q_ENUM(State) |
| 36 | |
| 37 | public: |
| 38 | ~QRemoteObjectReplica() override; |
| 39 | |
| 40 | bool isReplicaValid() const; |
| 41 | bool waitForSource(int timeout = 30000); |
| 42 | bool isInitialized() const; |
| 43 | State state() const; |
| 44 | QRemoteObjectNode *node() const; |
| 45 | virtual void setNode(QRemoteObjectNode *node); |
| 46 | |
| 47 | Q_SIGNALS: |
| 48 | void initialized(); |
| 49 | void notified(); |
| 50 | void stateChanged(State state, State oldState); |
| 51 | |
| 52 | protected: |
| 53 | enum ConstructorType {DefaultConstructor, ConstructWithNode}; |
| 54 | explicit QRemoteObjectReplica(ConstructorType t = DefaultConstructor); |
| 55 | QRemoteObjectReplica(QObjectPrivate &dptr, QObject *parent); |
| 56 | |
| 57 | virtual void initialize(); |
| 58 | void send(QMetaObject::Call call, int index, const QVariantList &args); |
| 59 | QRemoteObjectPendingCall sendWithReply(QMetaObject::Call call, int index, const QVariantList &args); |
| 60 | |
| 61 | protected: |
| 62 | void setProperties(QVariantList &&); |
| 63 | void setChild(int i, const QVariant &); |
| 64 | const QVariant propAsVariant(int i) const; |
| 65 | void persistProperties(const QString &repName, const QByteArray &repSig, const QVariantList &props) const; |
| 66 | QVariantList retrieveProperties(const QString &repName, const QByteArray &repSig) const; |
| 67 | void initializeNode(QRemoteObjectNode *node, const QString &name = QString()); |
| 68 | QSharedPointer<QReplicaImplementationInterface> d_impl; |
| 69 | private: |
| 70 | friend class QRemoteObjectNodePrivate; |
| 71 | friend class QConnectedReplicaImplementation; |
| 72 | }; |
| 73 | |
| 74 | QT_END_NAMESPACE |
| 75 | |
| 76 | #endif |
| 77 | |