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 QREMOTEOBJECTNODE_P_H
5#define QREMOTEOBJECTNODE_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 <QtCore/private/qobject_p.h>
19#include "qremoteobjectsourceio_p.h"
20#include "qremoteobjectreplica.h"
21#include "qremoteobjectnode.h"
22
23#include <QtCore/qbasictimer.h>
24#include <QtCore/qmutex.h>
25
26QT_BEGIN_NAMESPACE
27
28#define qRODebug(x) qCDebug(QT_REMOTEOBJECT) << qPrintable(QtPrivate::deref_for_methodcall(x).objectName())
29#define qROWarning(x) qCWarning(QT_REMOTEOBJECT) << qPrintable(QtPrivate::deref_for_methodcall(x).objectName())
30#define qROCritical(x) qCCritical(QT_REMOTEOBJECT) << qPrintable(QtPrivate::deref_for_methodcall(x).objectName())
31#define qROFatal(x) qCFatal(QT_REMOTEOBJECT) << qPrintable(QtPrivate::deref_for_methodcall(x).objectName())
32#define qROPrivDebug() qCDebug(QT_REMOTEOBJECT) << qPrintable(q_ptr->objectName())
33#define qROPrivWarning() qCWarning(QT_REMOTEOBJECT) << qPrintable(q_ptr->objectName())
34#define qROPrivCritical() qCCritical(QT_REMOTEOBJECT) << qPrintable(q_ptr->objectName())
35#define qROPrivFatal() qCFatal(QT_REMOTEOBJECT) << qPrintable(q_ptr->objectName())
36
37class QRemoteObjectRegistry;
38class QRegistrySource;
39class QConnectedReplicaImplementation;
40
41class QRemoteObjectAbstractPersistedStorePrivate : public QObjectPrivate
42{
43public:
44 QRemoteObjectAbstractPersistedStorePrivate();
45 virtual ~QRemoteObjectAbstractPersistedStorePrivate();
46
47 Q_DECLARE_PUBLIC(QRemoteObjectAbstractPersistedStore)
48};
49
50class QRemoteObjectMetaObjectManager
51{
52public:
53 QRemoteObjectMetaObjectManager() {}
54 ~QRemoteObjectMetaObjectManager();
55
56 const QMetaObject *metaObjectForType(const QString &type);
57 QMetaObject *addDynamicType(QtROIoDeviceBase* connection, QDataStream &in);
58 void addFromMetaObject(const QMetaObject *);
59
60private:
61 QHash<QString, QMetaObject*> dynamicTypes;
62 QHash<QString, const QMetaObject*> staticTypes;
63 QHash<QtPrivate::QMetaTypeInterface *, QMetaType> enumsToBeAssignedMetaObject;
64 QHash<QMetaObject *, QList<QMetaType>> enumTypes;
65};
66
67struct ProxyReplicaInfo;
68class ProxyInfo : public QObject
69{
70 Q_OBJECT
71public:
72 ProxyInfo(QRemoteObjectNode *node, QRemoteObjectHostBase *parent, QRemoteObjectHostBase::RemoteObjectNameFilter filter);
73 ~ProxyInfo() override;
74 enum class ProxyDirection { Forward, Reverse };
75
76 bool setReverseProxy(QRemoteObjectHostBase::RemoteObjectNameFilter filter);
77 void proxyObject(const QRemoteObjectSourceLocation &entry, ProxyDirection direction = ProxyDirection::Forward);
78 void unproxyObject(const QRemoteObjectSourceLocation &entry);
79
80 QRemoteObjectNode *proxyNode;
81 QRemoteObjectHostBase *parentNode;
82 QRemoteObjectHostBase::RemoteObjectNameFilter proxyFilter;
83 QRemoteObjectHostBase::RemoteObjectNameFilter reverseFilter;
84 QHash<QString, ProxyReplicaInfo*> proxiedReplicas;
85
86private:
87 void disableAndDeleteObject(ProxyReplicaInfo* info);
88};
89
90struct ProxyReplicaInfo
91{
92 // We need QObject, so we can hold Dynamic Replicas and QAIM Adapters
93 QObject* replica;
94 ProxyInfo::ProxyDirection direction;
95 ~ProxyReplicaInfo() { delete replica; }
96};
97
98class QRemoteObjectNodePrivate : public QObjectPrivate
99{
100public:
101 QRemoteObjectNodePrivate();
102 ~QRemoteObjectNodePrivate() override;
103
104 virtual QRemoteObjectSourceLocations remoteObjectAddresses() const;
105
106 void setReplicaImplementation(const QMetaObject *, QRemoteObjectReplica *, const QString &);
107
108 void setLastError(QRemoteObjectNode::ErrorCode errorCode);
109
110 void connectReplica(QObject *object, QRemoteObjectReplica *instance);
111 void openConnectionIfNeeded(const QString &name);
112
113 bool initConnection(const QUrl &address);
114 bool hasInstance(const QString &name);
115 void setRegistry(QRemoteObjectRegistry *);
116 QVariant handlePointerToQObjectProperty(QConnectedReplicaImplementation *rep, int index, const QVariant &property);
117 void handlePointerToQObjectProperties(QConnectedReplicaImplementation *rep, QVariantList &properties);
118
119 void onClientRead(QObject *obj);
120 void onRemoteObjectSourceAdded(const QRemoteObjectSourceLocation &entry);
121 void onRemoteObjectSourceRemoved(const QRemoteObjectSourceLocation &entry);
122 void onRegistryInitialized();
123 void onShouldReconnect(QtROClientIoDevice *ioDevice);
124
125 virtual QReplicaImplementationInterface *handleNewAcquire(const QMetaObject *meta, QRemoteObjectReplica *instance, const QString &name);
126 void handleReplicaConnection(const QString &name);
127 void handleReplicaConnection(const QByteArray &sourceSignature, QConnectedReplicaImplementation *rep, QtROIoDeviceBase *connection);
128 void initialize();
129 bool setRegistryUrlNodeImpl(const QUrl &registryAddr);
130
131private:
132 bool checkSignatures(const QByteArray &a, const QByteArray &b);
133
134public:
135 struct SourceInfo
136 {
137 QtROIoDeviceBase* device;
138 QString typeName;
139 QByteArray objectSignature;
140 };
141
142 QMutex mutex;
143 QUrl registryAddress;
144 QHash<QString, QWeakPointer<QReplicaImplementationInterface> > replicas;
145 QMap<QString, SourceInfo> connectedSources;
146 QMap<QString, QRemoteObjectNode::RemoteObjectSchemaHandler> schemaHandlers;
147 QSet<QtROClientIoDevice*> pendingReconnect;
148 QSet<QUrl> requestedUrls;
149 QRemoteObjectRegistry *registry;
150 int retryInterval;
151 QBasicTimer reconnectTimer;
152 QRemoteObjectNode::ErrorCode lastError;
153 QString rxName;
154 QRemoteObjectPackets::ObjectInfoList rxObjects;
155 QVariantList rxArgs;
156 QVariant rxValue;
157 QRemoteObjectAbstractPersistedStore *persistedStore;
158 int m_heartbeatInterval = 0;
159 QRemoteObjectMetaObjectManager dynamicTypeManager;
160 Q_DECLARE_PUBLIC(QRemoteObjectNode)
161};
162
163class QRemoteObjectHostBasePrivate : public QRemoteObjectNodePrivate
164{
165public:
166 QRemoteObjectHostBasePrivate();
167 ~QRemoteObjectHostBasePrivate() override;
168 QReplicaImplementationInterface *handleNewAcquire(const QMetaObject *meta, QRemoteObjectReplica *instance, const QString &name) override;
169
170 bool setHostUrlBaseImpl(const QUrl &hostAddress,
171 QRemoteObjectHostBase::AllowedSchemas allowedSchemas =
172 QRemoteObjectHostBase::BuiltInSchemasOnly);
173
174public:
175 QRemoteObjectSourceIo *remoteObjectIo;
176 ProxyInfo *proxyInfo = nullptr;
177 Q_DECLARE_PUBLIC(QRemoteObjectHostBase);
178};
179
180class QRemoteObjectHostPrivate : public QRemoteObjectHostBasePrivate
181{
182public:
183 QRemoteObjectHostPrivate();
184 ~QRemoteObjectHostPrivate() override;
185
186 bool setHostUrlHostImpl(const QUrl &hostAddress,
187 QRemoteObjectHostBase::AllowedSchemas allowedSchemas =
188 QRemoteObjectHostBase::BuiltInSchemasOnly);
189
190 Q_DECLARE_PUBLIC(QRemoteObjectHost);
191};
192
193class QRemoteObjectRegistryHostPrivate : public QRemoteObjectHostBasePrivate
194{
195public:
196 QRemoteObjectRegistryHostPrivate();
197 ~QRemoteObjectRegistryHostPrivate() override;
198 QRemoteObjectSourceLocations remoteObjectAddresses() const override;
199 QRegistrySource *registrySource;
200
201 bool setRegistryUrlRegistryHostImpl(const QUrl &registryUrl);
202
203 Q_DECLARE_PUBLIC(QRemoteObjectRegistryHost);
204};
205
206QT_END_NAMESPACE
207
208#endif
209

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