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

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