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 QTREMOTEOBJECTGLOBAL_H |
5 | #define QTREMOTEOBJECTGLOBAL_H |
6 | |
7 | #include <QtCore/qglobal.h> |
8 | #include <QtCore/qhash.h> |
9 | #include <QtCore/qurl.h> |
10 | #include <QtCore/qloggingcategory.h> |
11 | #include <QtRemoteObjects/qtremoteobjectsexports.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | struct QRemoteObjectSourceLocationInfo |
16 | { |
17 | QRemoteObjectSourceLocationInfo() = default; |
18 | QRemoteObjectSourceLocationInfo(const QString &typeName_, const QUrl &hostUrl_) |
19 | : typeName(typeName_), hostUrl(hostUrl_) {} |
20 | |
21 | inline bool operator==(const QRemoteObjectSourceLocationInfo &other) const Q_DECL_NOTHROW |
22 | { |
23 | return other.typeName == typeName && other.hostUrl == hostUrl; |
24 | } |
25 | inline bool operator!=(const QRemoteObjectSourceLocationInfo &other) const Q_DECL_NOTHROW |
26 | { |
27 | return !(*this == other); |
28 | } |
29 | |
30 | QString typeName; |
31 | QUrl hostUrl; |
32 | }; |
33 | |
34 | inline QDebug operator<<(QDebug dbg, const QRemoteObjectSourceLocationInfo &info) |
35 | { |
36 | dbg.nospace() << "SourceLocationInfo(" << info.typeName << ", " << info.hostUrl << ")" ; |
37 | return dbg.space(); |
38 | } |
39 | |
40 | inline QDataStream& operator<<(QDataStream &stream, const QRemoteObjectSourceLocationInfo &info) |
41 | { |
42 | return stream << info.typeName << info.hostUrl; |
43 | } |
44 | |
45 | inline QDataStream& operator>>(QDataStream &stream, QRemoteObjectSourceLocationInfo &info) |
46 | { |
47 | return stream >> info.typeName >> info.hostUrl; |
48 | } |
49 | |
50 | typedef QPair<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocation; |
51 | typedef QHash<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocations; |
52 | typedef QHash<int, QByteArray> QIntHash; |
53 | |
54 | QT_END_NAMESPACE |
55 | QT_DECL_METATYPE_EXTERN(QRemoteObjectSourceLocation, Q_REMOTEOBJECTS_EXPORT) |
56 | QT_DECL_METATYPE_EXTERN(QRemoteObjectSourceLocations, Q_REMOTEOBJECTS_EXPORT) |
57 | QT_DECL_METATYPE_EXTERN(QIntHash, /* not exported */) |
58 | QT_BEGIN_NAMESPACE |
59 | |
60 | #define QCLASSINFO_REMOTEOBJECT_TYPE "RemoteObject Type" |
61 | #define QCLASSINFO_REMOTEOBJECT_SIGNATURE "RemoteObject Signature" |
62 | |
63 | class QDataStream; |
64 | |
65 | namespace QRemoteObjectStringLiterals { |
66 | |
67 | // when QStringLiteral is used with the same string in different functions, |
68 | // it creates duplicate static data. Wrapping it in inline functions prevents it. |
69 | |
70 | inline QString local() { return QStringLiteral("local" ); } |
71 | inline QString localabstract() { return QStringLiteral("localabstract" ); } |
72 | inline QString tcp() { return QStringLiteral("tcp" ); } |
73 | inline QString CLASS() { return QStringLiteral("Class::%1" ); } |
74 | inline QString MODEL() { return QStringLiteral("Model::%1" ); } |
75 | inline QString QAIMADAPTER() { return QStringLiteral("QAbstractItemModelAdapter" ); } |
76 | |
77 | } |
78 | |
79 | Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT) |
80 | Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_MODELS) |
81 | Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_IO) |
82 | |
83 | namespace QtRemoteObjects { |
84 | |
85 | Q_NAMESPACE |
86 | |
87 | Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, void *dst); |
88 | Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, QDataStream &dst); |
89 | Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, QDataStream &src, void *dst); |
90 | |
91 | QString getTypeNameAndMetaobjectFromClassInfo(const QMetaObject *& meta); |
92 | |
93 | template <typename T> |
94 | void copyStoredProperties(const T *src, T *dst) |
95 | { |
96 | copyStoredProperties(&T::staticMetaObject, src, dst); |
97 | } |
98 | |
99 | template <typename T> |
100 | void copyStoredProperties(const T *src, QDataStream &dst) |
101 | { |
102 | copyStoredProperties(&T::staticMetaObject, src, dst); |
103 | } |
104 | |
105 | template <typename T> |
106 | void copyStoredProperties(QDataStream &src, T *dst) |
107 | { |
108 | copyStoredProperties(&T::staticMetaObject, src, dst); |
109 | } |
110 | |
111 | template <typename E> |
112 | constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept { |
113 | return static_cast<typename std::underlying_type<E>::type>(e); |
114 | } |
115 | |
116 | enum QRemoteObjectPacketTypeEnum |
117 | { |
118 | Invalid = 0, |
119 | Handshake, |
120 | InitPacket, |
121 | InitDynamicPacket, |
122 | AddObject, |
123 | RemoveObject, |
124 | InvokePacket, |
125 | InvokeReplyPacket, |
126 | PropertyChangePacket, |
127 | ObjectList, |
128 | Ping, |
129 | Pong |
130 | }; |
131 | Q_ENUM_NS(QRemoteObjectPacketTypeEnum) |
132 | |
133 | enum InitialAction { |
134 | FetchRootSize, |
135 | PrefetchData |
136 | }; |
137 | Q_ENUM_NS(InitialAction) |
138 | |
139 | } |
140 | |
141 | QT_END_NAMESPACE |
142 | |
143 | #endif // QTREMOTEOBJECTSGLOBAL_H |
144 | |