1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 Ford Motor Company
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtRemoteObjects module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef QTREMOTEOBJECTGLOBAL_H
41 #define QTREMOTEOBJECTGLOBAL_H
42
43 #include <QtCore/qglobal.h>
44 #include <QtCore/qhash.h>
45 #include <QtCore/qurl.h>
46 #include <QtCore/qloggingcategory.h>
47
48 QT_BEGIN_NAMESPACE
49
50 struct QRemoteObjectSourceLocationInfo
51 {
52 QRemoteObjectSourceLocationInfo() = default;
QRemoteObjectSourceLocationInfoQRemoteObjectSourceLocationInfo53 QRemoteObjectSourceLocationInfo(const QString &typeName_, const QUrl &hostUrl_)
54 : typeName(typeName_), hostUrl(hostUrl_) {}
55
56 inline bool operator==(const QRemoteObjectSourceLocationInfo &other) const Q_DECL_NOTHROW
57 {
58 return other.typeName == typeName && other.hostUrl == hostUrl;
59 }
60 inline bool operator!=(const QRemoteObjectSourceLocationInfo &other) const Q_DECL_NOTHROW
61 {
62 return !(*this == other);
63 }
64
65 QString typeName;
66 QUrl hostUrl;
67 };
68
69 inline QDebug operator<<(QDebug dbg, const QRemoteObjectSourceLocationInfo &info)
70 {
71 dbg.nospace() << "SourceLocationInfo(" << info.typeName << ", " << info.hostUrl << ")";
72 return dbg.space();
73 }
74
75 inline QDataStream& operator<<(QDataStream &stream, const QRemoteObjectSourceLocationInfo &info)
76 {
77 return stream << info.typeName << info.hostUrl;
78 }
79
80 inline QDataStream& operator>>(QDataStream &stream, QRemoteObjectSourceLocationInfo &info)
81 {
82 return stream >> info.typeName >> info.hostUrl;
83 }
84
85 typedef QPair<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocation;
86 typedef QHash<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocations;
87 typedef QHash<int, QByteArray> QIntHash;
88
89 QT_END_NAMESPACE
90 Q_DECLARE_METATYPE(QRemoteObjectSourceLocation)
91 Q_DECLARE_METATYPE(QRemoteObjectSourceLocations)
92 Q_DECLARE_METATYPE(QIntHash)
93 QT_BEGIN_NAMESPACE
94
95 #ifndef QT_STATIC
96 # if defined(QT_BUILD_REMOTEOBJECTS_LIB)
97 # define Q_REMOTEOBJECTS_EXPORT Q_DECL_EXPORT
98 # else
99 # define Q_REMOTEOBJECTS_EXPORT Q_DECL_IMPORT
100 # endif
101 #else
102 # define Q_REMOTEOBJECTS_EXPORT
103 #endif
104
105 #define QCLASSINFO_REMOTEOBJECT_TYPE "RemoteObject Type"
106 #define QCLASSINFO_REMOTEOBJECT_SIGNATURE "RemoteObject Signature"
107
108 class QDataStream;
109
110 namespace QRemoteObjectStringLiterals {
111
112 // when QStringLiteral is used with the same string in different functions,
113 // it creates duplicate static data. Wrapping it in inline functions prevents it.
114
local()115 inline QString local() { return QStringLiteral("local"); }
tcp()116 inline QString tcp() { return QStringLiteral("tcp"); }
CLASS()117 inline QString CLASS() { return QStringLiteral("Class::%1"); }
MODEL()118 inline QString MODEL() { return QStringLiteral("Model::%1"); }
QAIMADAPTER()119 inline QString QAIMADAPTER() { return QStringLiteral("QAbstractItemModelAdapter"); }
120
121 }
122
123 Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT)
Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_MODELS)124 Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_MODELS)
125 Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_IO)
126
127 namespace QtRemoteObjects {
128
129 Q_NAMESPACE
130
131 Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, void *dst);
132 Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, QDataStream &dst);
133 Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, QDataStream &src, void *dst);
134
135 QString getTypeNameAndMetaobjectFromClassInfo(const QMetaObject *& meta);
136
137 template <typename T>
138 void copyStoredProperties(const T *src, T *dst)
139 {
140 copyStoredProperties(&T::staticMetaObject, src, dst);
141 }
142
143 template <typename T>
144 void copyStoredProperties(const T *src, QDataStream &dst)
145 {
146 copyStoredProperties(&T::staticMetaObject, src, dst);
147 }
148
149 template <typename T>
150 void copyStoredProperties(QDataStream &src, T *dst)
151 {
152 copyStoredProperties(&T::staticMetaObject, src, dst);
153 }
154
155 enum QRemoteObjectPacketTypeEnum
156 {
157 Invalid = 0,
158 Handshake,
159 InitPacket,
160 InitDynamicPacket,
161 AddObject,
162 RemoveObject,
163 InvokePacket,
164 InvokeReplyPacket,
165 PropertyChangePacket,
166 ObjectList,
167 Ping,
168 Pong
169 };
170 Q_ENUM_NS(QRemoteObjectPacketTypeEnum)
171
172 enum InitialAction {
173 FetchRootSize,
174 PrefetchData
175 };
176 Q_ENUM_NS(InitialAction)
177
178 }
179
180 QT_END_NAMESPACE
181
182 #endif // QTREMOTEOBJECTSGLOBAL_H
183