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 QREMOTEOBJECTSOURCE_H
6#define QREMOTEOBJECTSOURCE_H
7
8#include <QtCore/qscopedpointer.h>
9#include <QtRemoteObjects/qtremoteobjectglobal.h>
10#include <QtCore/qmetaobject.h>
11
12QT_BEGIN_NAMESPACE
13
14namespace QtPrivate {
15
16//Based on compile time checks for static connect() from qobjectdefs_impl.h
17template <class ObjectType, typename Func1, typename Func2>
18static inline int qtro_property_index(Func1, Func2, const char *propName)
19{
20 typedef QtPrivate::FunctionPointer<Func1> Type1;
21 typedef QtPrivate::FunctionPointer<Func2> Type2;
22
23 //compilation error if the arguments do not match.
24 Q_STATIC_ASSERT_X(int(Type1::ArgumentCount) >= int(Type2::ArgumentCount),
25 "Argument counts are not compatible.");
26 Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename Type1::Arguments, typename Type2::Arguments>::value),
27 "Arguments are not compatible.");
28 Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename Type1::ReturnType, typename Type2::ReturnType>::value),
29 "Return types are not compatible.");
30 return ObjectType::staticMetaObject.indexOfProperty(propName);
31}
32
33template <class ObjectType, typename Func1, typename Func2>
34static inline int qtro_signal_index(Func1 func, Func2, int *count, int const **types)
35{
36 typedef QtPrivate::FunctionPointer<Func1> Type1;
37 typedef QtPrivate::FunctionPointer<Func2> Type2;
38
39 //compilation error if the arguments do not match.
40 Q_STATIC_ASSERT_X(int(Type1::ArgumentCount) >= int(Type2::ArgumentCount),
41 "Argument counts are not compatible.");
42 Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename Type1::Arguments, typename Type2::Arguments>::value),
43 "Arguments are not compatible.");
44 Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename Type1::ReturnType, typename Type2::ReturnType>::value),
45 "Return types are not compatible.");
46 const QMetaMethod sig = QMetaMethod::fromSignal(func);
47 *count = Type2::ArgumentCount;
48 *types = QtPrivate::ConnectionTypes<typename Type2::Arguments>::types();
49 return sig.methodIndex();
50}
51
52template <class ObjectType, typename Func1, typename Func2>
53static inline void qtro_method_test(Func1, Func2)
54{
55 typedef QtPrivate::FunctionPointer<Func1> Type1;
56 typedef QtPrivate::FunctionPointer<Func2> Type2;
57
58 //compilation error if the arguments do not match.
59 Q_STATIC_ASSERT_X(int(Type1::ArgumentCount) >= int(Type2::ArgumentCount),
60 "Argument counts are not compatible.");
61 Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename Type1::Arguments, typename Type2::Arguments>::value),
62 "Arguments are not compatible.");
63 Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename Type1::ReturnType, typename Type2::ReturnType>::value),
64 "Return types are not compatible.");
65}
66
67Q_REMOTEOBJECTS_EXPORT
68int qtro_method_index_impl(const QMetaObject *staticMetaObj, const char *className,
69 const char *methodName, int *count, const int **types);
70
71template <class ObjectType, typename Func1, typename Func2>
72static inline int qtro_method_index(Func1, Func2, const char *methodName, int *count, int const **types)
73{
74 typedef QtPrivate::FunctionPointer<Func1> Type1;
75 typedef QtPrivate::FunctionPointer<Func2> Type2;
76
77 //compilation error if the arguments do not match.
78 Q_STATIC_ASSERT_X(int(Type1::ArgumentCount) >= int(Type2::ArgumentCount),
79 "Argument counts are not compatible.");
80 Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename Type1::Arguments, typename Type2::Arguments>::value),
81 "Arguments are not compatible.");
82 Q_STATIC_ASSERT_X((QtPrivate::AreArgumentsCompatible<typename Type1::ReturnType, typename Type2::ReturnType>::value),
83 "Return types are not compatible.");
84 *count = Type2::ArgumentCount;
85 *types = QtPrivate::ConnectionTypes<typename Type2::Arguments>::types();
86
87 return qtro_method_index_impl(&ObjectType::staticMetaObject,
88 ObjectType::staticMetaObject.className(), methodName, count,
89 types);
90}
91
92template <class ObjectType>
93static inline QByteArray qtro_enum_signature(const char *enumName)
94{
95 const auto qme = ObjectType::staticMetaObject.enumerator(ObjectType::staticMetaObject.indexOfEnumerator(enumName));
96 return QByteArrayLiteral("1::2").replace("1", qme.scope()).replace("2", qme.name());
97}
98
99QByteArray qtro_classinfo_signature(const QMetaObject *metaObject);
100
101}
102
103// TODO ModelInfo just needs roles, and no need for SubclassInfo
104class QAbstractItemModel;
105
106struct ModelInfo
107{
108 QAbstractItemModel *ptr;
109 QString name;
110 QByteArray roles;
111};
112
113class Q_REMOTEOBJECTS_EXPORT SourceApiMap
114{
115protected:
116 SourceApiMap() {}
117public:
118 virtual ~SourceApiMap();
119 virtual QString name() const = 0;
120 virtual QString typeName() const = 0;
121 virtual QByteArray className() const { return typeName().toLatin1().append(s: "Source"); }
122 virtual int enumCount() const = 0;
123 virtual int propertyCount() const = 0;
124 virtual int signalCount() const = 0;
125 virtual int methodCount() const = 0;
126 virtual int sourceEnumIndex(int index) const = 0;
127 virtual int sourcePropertyIndex(int index) const = 0;
128 virtual int sourceSignalIndex(int index) const = 0;
129 virtual int sourceMethodIndex(int index) const = 0;
130 virtual int signalParameterCount(int index) const = 0;
131 virtual int signalParameterType(int sigIndex, int paramIndex) const = 0;
132 virtual const QByteArray signalSignature(int index) const = 0;
133 virtual QByteArrayList signalParameterNames(int index) const = 0;
134 virtual int methodParameterCount(int index) const = 0;
135 virtual int methodParameterType(int methodIndex, int paramIndex) const = 0;
136 virtual const QByteArray methodSignature(int index) const = 0;
137 virtual QMetaMethod::MethodType methodType(int index) const = 0;
138 virtual const QByteArray typeName(int index) const = 0;
139 virtual QByteArrayList methodParameterNames(int index) const = 0;
140 virtual int propertyIndexFromSignal(int index) const = 0;
141 virtual int propertyRawIndexFromSignal(int index) const = 0;
142 virtual QByteArray objectSignature() const = 0;
143 virtual bool isDynamic() const { return false; }
144 virtual bool isAdapterSignal(int) const { return false; }
145 virtual bool isAdapterMethod(int) const { return false; }
146 virtual bool isAdapterProperty(int) const { return false; }
147 QList<ModelInfo> m_models;
148 QList<SourceApiMap *> m_subclasses;
149};
150
151QT_END_NAMESPACE
152
153#endif
154

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