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
13QT_BEGIN_NAMESPACE
14
15struct 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
34inline QDebug operator<<(QDebug dbg, const QRemoteObjectSourceLocationInfo &info)
35{
36 dbg.nospace() << "SourceLocationInfo(" << info.typeName << ", " << info.hostUrl << ")";
37 return dbg.space();
38}
39
40inline QDataStream& operator<<(QDataStream &stream, const QRemoteObjectSourceLocationInfo &info)
41{
42 return stream << info.typeName << info.hostUrl;
43}
44
45inline QDataStream& operator>>(QDataStream &stream, QRemoteObjectSourceLocationInfo &info)
46{
47 return stream >> info.typeName >> info.hostUrl;
48}
49
50typedef QPair<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocation;
51typedef QHash<QString, QRemoteObjectSourceLocationInfo> QRemoteObjectSourceLocations;
52typedef QHash<int, QByteArray> QIntHash;
53
54QT_END_NAMESPACE
55QT_DECL_METATYPE_EXTERN(QRemoteObjectSourceLocation, Q_REMOTEOBJECTS_EXPORT)
56QT_DECL_METATYPE_EXTERN(QRemoteObjectSourceLocations, Q_REMOTEOBJECTS_EXPORT)
57QT_DECL_METATYPE_EXTERN(QIntHash, /* not exported */)
58QT_BEGIN_NAMESPACE
59
60#define QCLASSINFO_REMOTEOBJECT_TYPE "RemoteObject Type"
61#define QCLASSINFO_REMOTEOBJECT_SIGNATURE "RemoteObject Signature"
62
63class QDataStream;
64
65namespace 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
70inline QString local() { return QStringLiteral("local"); }
71inline QString localabstract() { return QStringLiteral("localabstract"); }
72inline QString tcp() { return QStringLiteral("tcp"); }
73inline QString CLASS() { return QStringLiteral("Class::%1"); }
74inline QString MODEL() { return QStringLiteral("Model::%1"); }
75inline QString QAIMADAPTER() { return QStringLiteral("QAbstractItemModelAdapter"); }
76
77}
78
79Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT)
80Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_MODELS)
81Q_DECLARE_LOGGING_CATEGORY(QT_REMOTEOBJECT_IO)
82
83namespace QtRemoteObjects {
84
85Q_NAMESPACE
86
87Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, void *dst);
88Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, const void *src, QDataStream &dst);
89Q_REMOTEOBJECTS_EXPORT void copyStoredProperties(const QMetaObject *mo, QDataStream &src, void *dst);
90
91QString getTypeNameAndMetaobjectFromClassInfo(const QMetaObject *& meta);
92
93template <typename T>
94void copyStoredProperties(const T *src, T *dst)
95{
96 copyStoredProperties(&T::staticMetaObject, src, dst);
97}
98
99template <typename T>
100void copyStoredProperties(const T *src, QDataStream &dst)
101{
102 copyStoredProperties(&T::staticMetaObject, src, dst);
103}
104
105template <typename T>
106void copyStoredProperties(QDataStream &src, T *dst)
107{
108 copyStoredProperties(&T::staticMetaObject, src, dst);
109}
110
111template <typename E>
112constexpr typename std::underlying_type<E>::type to_underlying(E e) noexcept {
113 return static_cast<typename std::underlying_type<E>::type>(e);
114}
115
116enum 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};
131Q_ENUM_NS(QRemoteObjectPacketTypeEnum)
132
133enum InitialAction {
134 FetchRootSize,
135 PrefetchData
136};
137Q_ENUM_NS(InitialAction)
138
139}
140
141QT_END_NAMESPACE
142
143#endif // QTREMOTEOBJECTSGLOBAL_H
144

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