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 QREMOTEOBJECTREPLICA_P_H
5#define QREMOTEOBJECTREPLICA_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qremoteobjectreplica.h"
19
20#include "qremoteobjectpendingcall.h"
21
22#include "qremoteobjectpacket_p.h"
23
24#include <QtCore/qcompilerdetection.h>
25#include <QtCore/qdatastream.h>
26#include <QtCore/qpointer.h>
27#include <QtCore/qtimer.h>
28
29QT_BEGIN_NAMESPACE
30
31class QRemoteObjectReplica;
32class QRemoteObjectSource;
33class QtROIoDeviceBase;
34
35class QReplicaImplementationInterface
36{
37public:
38 virtual ~QReplicaImplementationInterface() {}
39 virtual const QVariant getProperty(int i) const = 0;
40 virtual void setProperties(QVariantList &&) = 0;
41 virtual void setProperty(int i, const QVariant &) = 0;
42 virtual bool isInitialized() const = 0;
43 virtual QRemoteObjectReplica::State state() const = 0;
44 virtual bool waitForSource(int) = 0;
45 virtual QRemoteObjectNode *node() const = 0;
46
47 virtual void _q_send(QMetaObject::Call call, int index, const QVariantList &args) = 0;
48 virtual QRemoteObjectPendingCall _q_sendWithReply(QMetaObject::Call call, int index, const QVariantList &args) = 0;
49};
50
51class QStubReplicaImplementation final : public QReplicaImplementationInterface
52{
53public:
54 explicit QStubReplicaImplementation();
55 ~QStubReplicaImplementation() override;
56
57 const QVariant getProperty(int i) const override;
58 void setProperties(QVariantList &&) override;
59 void setProperty(int i, const QVariant &) override;
60 bool isInitialized() const override { return false; }
61 QRemoteObjectReplica::State state() const override { return QRemoteObjectReplica::State::Uninitialized;}
62 bool waitForSource(int) override { return false; }
63 QRemoteObjectNode *node() const override { return nullptr; }
64
65 void _q_send(QMetaObject::Call call, int index, const QVariantList &args) override;
66 QRemoteObjectPendingCall _q_sendWithReply(QMetaObject::Call call, int index, const QVariantList &args) override;
67 QVariantList m_propertyStorage;
68};
69
70class QRemoteObjectReplicaImplementation : public QObject, public QReplicaImplementationInterface
71{
72public:
73 explicit QRemoteObjectReplicaImplementation(const QString &name, const QMetaObject *, QRemoteObjectNode *);
74 ~QRemoteObjectReplicaImplementation() override;
75
76 bool needsDynamicInitialization() const;
77
78 const QVariant getProperty(int i) const override = 0;
79 void setProperties(QVariantList &&) override = 0;
80 void setProperty(int i, const QVariant &) override = 0;
81 virtual bool isShortCircuit() const = 0;
82 bool isInitialized() const override { return true; }
83 QRemoteObjectReplica::State state() const override { return QRemoteObjectReplica::State(m_state.loadRelaxed()); }
84 void setState(QRemoteObjectReplica::State state);
85 bool waitForSource(int) override { return true; }
86 virtual bool waitForFinished(const QRemoteObjectPendingCall &, int) { return true; }
87 virtual void notifyAboutReply(int, const QVariant &) {}
88 virtual void configurePrivate(QRemoteObjectReplica *);
89 void emitInitialized();
90 void emitNotified();
91 QRemoteObjectNode *node() const override { return m_node; }
92
93 void _q_send(QMetaObject::Call call, int index, const QVariantList &args) override = 0;
94 QRemoteObjectPendingCall _q_sendWithReply(QMetaObject::Call call, int index, const QVariantList &args) override = 0;
95
96 //Dynamic replica functions
97 virtual void setDynamicMetaObject(const QMetaObject *meta);
98 virtual void setDynamicProperties(QVariantList &&values);
99
100 QString m_objectName;
101 const QMetaObject *m_metaObject;
102
103 //Dynamic Replica data
104 int m_numSignals;//TODO maybe here too
105 int m_methodOffset;
106 int m_signalOffset;
107 int m_propertyOffset;
108 QRemoteObjectNode *m_node;
109 QByteArray m_objectSignature;
110 QAtomicInt m_state;
111};
112
113class QConnectedReplicaImplementation final : public QRemoteObjectReplicaImplementation
114{
115public:
116 explicit QConnectedReplicaImplementation(const QString &name, const QMetaObject *, QRemoteObjectNode *);
117 ~QConnectedReplicaImplementation() override;
118 const QVariant getProperty(int i) const override;
119 void setProperties(QVariantList &&) override;
120 void setProperty(int i, const QVariant &) override;
121 bool isShortCircuit() const final { return false; }
122 bool isInitialized() const override;
123 bool waitForSource(int timeout) override;
124 QList<int> childIndices() const;
125 void initialize(QVariantList &&values);
126 void configurePrivate(QRemoteObjectReplica *) override;
127 void requestRemoteObjectSource();
128 bool sendCommand();
129 QRemoteObjectPendingCall sendCommandWithReply(int serialId);
130 bool waitForFinished(const QRemoteObjectPendingCall &call, int timeout) override;
131 void notifyAboutReply(int ackedSerialId, const QVariant &value) override;
132 void setConnection(QtROIoDeviceBase *conn);
133 void setDisconnected();
134
135 void _q_send(QMetaObject::Call call, int index, const QVariantList &args) override;
136 QRemoteObjectPendingCall _q_sendWithReply(QMetaObject::Call call, int index, const QVariantList& args) override;
137
138 void setDynamicMetaObject(const QMetaObject *meta) override;
139 void setDynamicProperties(QVariantList &&) override;
140 QList<QRemoteObjectReplica *> m_parentsNeedingConnect;
141 QVariantList m_propertyStorage;
142 QList<int> m_childIndices;
143 QPointer<QtROIoDeviceBase> connectionToSource;
144
145 // pending call data
146 int m_curSerialId = 1; // 0 is reserved for heartbeat signals
147 QHash<int, QRemoteObjectPendingCall> m_pendingCalls;
148 QTimer m_heartbeatTimer;
149};
150
151class QInProcessReplicaImplementation final : public QRemoteObjectReplicaImplementation
152{
153public:
154 explicit QInProcessReplicaImplementation(const QString &name, const QMetaObject *, QRemoteObjectNode *);
155 ~QInProcessReplicaImplementation() override;
156
157 const QVariant getProperty(int i) const override;
158 void setProperties(QVariantList &&) override;
159 void setProperty(int i, const QVariant &) override;
160 bool isShortCircuit() const final { return true; }
161
162 void _q_send(QMetaObject::Call call, int index, const QVariantList &args) override;
163 QRemoteObjectPendingCall _q_sendWithReply(QMetaObject::Call call, int index, const QVariantList& args) override;
164
165 QPointer<QRemoteObjectSourceBase> connectionToSource;
166};
167
168QT_END_NAMESPACE
169
170#endif
171

source code of qtremoteobjects/src/remoteobjects/qremoteobjectreplica_p.h