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:critical reason:data-parser
4
5#include "qremoteobjectsource.h"
6#include "qremoteobjectsource_p.h"
7#include "qremoteobjectnode.h"
8#include "qremoteobjectdynamicreplica.h"
9
10#include "qconnectionfactories_p.h"
11#include "qremoteobjectsourceio_p.h"
12#include "qremoteobjectabstractitemmodeladapter_p.h"
13
14#include <QtCore/qmetaobject.h>
15#include <QtCore/qvarlengtharray.h>
16#include <QtCore/qabstractitemmodel.h>
17
18#include <algorithm>
19#include <iterator>
20
21QT_BEGIN_NAMESPACE
22
23using namespace QRemoteObjectPackets;
24using namespace QRemoteObjectStringLiterals;
25
26const int QRemoteObjectSourceBase::qobjectPropertyOffset = QObject::staticMetaObject.propertyCount();
27const int QRemoteObjectSourceBase::qobjectMethodOffset = QObject::staticMetaObject.methodCount();
28static const QByteArray s_classinfoRemoteobjectSignature(QCLASSINFO_REMOTEOBJECT_SIGNATURE);
29
30namespace QtPrivate {
31
32// The stringData, methodMatch and QMetaObjectPrivate methods are modified versions of the code
33// from qmetaobject_p.h/qmetaobject.cpp. The modifications are based on our custom need to match
34// a method name that comes from the .rep file.
35// The QMetaObjectPrivate struct should only have members appended to maintain binary compatibility,
36// so we should be fine with only the listed version with the fields we use.
37inline const QByteArray apiStringData(const QMetaObject *mo, int index)
38{
39 uint offset = mo->d.stringdata[2*index];
40 uint length = mo->d.stringdata[2*index + 1];
41 const char *string = reinterpret_cast<const char *>(mo->d.stringdata) + offset;
42 return QByteArray::fromRawData(data: string, size: length);
43}
44
45
46// From QMetaMethod in qmetaobject.h
47struct Data {
48 enum { Size = 6 };
49
50 uint name() const { return d[0]; }
51 uint argc() const { return d[1]; }
52 uint parameters() const { return d[2]; }
53 uint tag() const { return d[3]; }
54 uint flags() const { return d[4]; }
55 uint metaTypeOffset() const { return d[5]; }
56 bool operator==(const Data &other) const { return d == other.d; }
57
58 const uint *d;
59};
60
61inline bool apiMethodMatch(const QMetaObject *m, const Data &data, const QByteArray &name, int argc,
62 const int *types)
63{
64 if (data.argc() != uint(argc))
65 return false;
66 if (apiStringData(mo: m, index: data.name()) != name)
67 return false;
68 for (int i = 0; i < argc; ++i) {
69 auto mt = QMetaType(m->d.metaTypes[data.metaTypeOffset() + i + 1]);
70 if (mt != QMetaType(types[i]))
71 return false;
72 }
73 return true;
74}
75
76struct QMetaObjectPrivate
77{
78 // revision 7 is Qt 5.0 everything lower is not supported
79 // revision 8 is Qt 5.12: It adds the enum name to QMetaEnum
80 enum { OutputRevision = 8 }; // Used by moc, qmetaobjectbuilder and qdbus
81
82 int revision;
83 int className;
84 int classInfoCount, classInfoData;
85 int methodCount, methodData;
86 int propertyCount, propertyData;
87 int enumeratorCount, enumeratorData;
88 int constructorCount, constructorData;
89 int flags;
90 int signalCount;
91};
92
93inline Data fromRelativeMethodIndex(const QMetaObject *mobj, int index)
94{
95 const auto priv = reinterpret_cast<const QMetaObjectPrivate*>(mobj->d.data);
96 return { .d: mobj->d.data + priv->methodData + index * Data::Size };
97}
98
99int qtro_method_index_impl(const QMetaObject * staticMetaObj, const char *className,
100 const char *methodName, int *count, int const **types)
101{
102 int result = staticMetaObj->indexOfMethod(method: methodName);
103 if (result >= 0)
104 return result;
105 // We can have issues, specifically with enums, since the compiler can infer the class. Since
106 // indexOfMethod() is doing string comparisons for registered types, "MyEnum" and "MyClass::MyEnum"
107 // won't match.
108 // Below is similar to QMetaObject->indexOfMethod, but template magic has already matched parameter
109 // types, so we need to find a match for the API method name + parameters. Neither approach works
110 // 100%, as the below code doesn't match a parameter of type "size_t" (which the template match
111 // identifies as "ulong"). These subtleties can cause the below string comparison fails.
112 // There is no known case that would fail both methods.
113 // TODO: is there a way to make this a constexpr so a failure is detected at compile time?
114 int nameLength = strchr(s: methodName, c: '(') - methodName;
115 const auto name = QByteArray::fromRawData(data: methodName, size: nameLength);
116 for (const QMetaObject *m = staticMetaObj; m; m = m->d.superdata) {
117 const auto priv = reinterpret_cast<const QMetaObjectPrivate*>(m->d.data);
118 int i = (priv->methodCount - 1);
119 const int end = priv->signalCount;
120 for (; i >= end; --i) {
121 const Data data = fromRelativeMethodIndex(mobj: m, index: i);
122 if (apiMethodMatch(m, data, name, argc: *count, types: *types))
123 return i + m->methodOffset();
124 }
125 }
126 qWarning() << "No matching method for" << methodName << "in the provided metaclass" << className;
127 return -1;
128}
129
130} // namespace QtPrivate
131
132QByteArray QtPrivate::qtro_classinfo_signature(const QMetaObject *metaObject)
133{
134 if (!metaObject)
135 return QByteArray{};
136
137 for (int i = metaObject->classInfoOffset(); i < metaObject->classInfoCount(); ++i) {
138 auto ci = metaObject->classInfo(index: i);
139 if (s_classinfoRemoteobjectSignature == ci.name())
140 return ci.value();
141 }
142 return QByteArray{};
143}
144
145inline bool qtro_is_cloned_method(const QMetaObject *mobj, int index)
146{
147 int local_method_index = index - mobj->methodOffset();
148 if (local_method_index < 0 && mobj->superClass())
149 return qtro_is_cloned_method(mobj: mobj->superClass(), index);
150 const QtPrivate::Data data = QtPrivate::fromRelativeMethodIndex(mobj, index: local_method_index);
151 if (data.flags() & 0x20 /*MethodFlags::MethodCloned*/)
152 return true;
153 return false;
154}
155
156SourceApiMap::~SourceApiMap()
157 = default;
158
159QRemoteObjectSourceBase::QRemoteObjectSourceBase(QObject *obj, Private *d, const SourceApiMap *api,
160 QObject *adapter)
161 : QObject(obj),
162 m_object(obj),
163 m_adapter(adapter),
164 m_api(api),
165 d(d)
166{
167 if (!obj) {
168 qCWarning(QT_REMOTEOBJECT) << "QRemoteObjectSourceBase: Cannot replicate a NULL object" << m_api->name();
169 return;
170 }
171
172 setConnections();
173
174 const auto nChildren = api->m_models.size() + api->m_subclasses.size();
175 if (nChildren > 0) {
176 QList<int> roles;
177 const int numProperties = api->propertyCount();
178 int modelIndex = 0, subclassIndex = 0;
179 for (int i = 0; i < numProperties; ++i) {
180 if (api->isAdapterProperty(i))
181 continue;
182 const int index = api->sourcePropertyIndex(index: i);
183 const auto property = m_object->metaObject()->property(index);
184 const auto metaType = property.metaType();
185 if (metaType.flags().testFlag(flag: QMetaType::PointerToQObject)) {
186 auto propertyMeta = metaType.metaObject();
187 QObject *child = property.read(obj: m_object).value<QObject *>();
188 const QMetaObject *meta = child ? child->metaObject() : propertyMeta;
189 if (!meta)
190 continue;
191 if (meta->inherits(metaObject: &QAbstractItemModel::staticMetaObject)) {
192 const auto modelInfo = api->m_models.at(i: modelIndex++);
193 QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(object: child);
194 QAbstractItemAdapterSourceAPI<QAbstractItemModel, QAbstractItemModelSourceAdapter> *modelApi =
195 new QAbstractItemAdapterSourceAPI<QAbstractItemModel, QAbstractItemModelSourceAdapter>(modelInfo.name);
196 if (!model)
197 m_children.insert(key: i, value: new QRemoteObjectSource(nullptr, d, modelApi, nullptr, api->name()));
198 else {
199 roles.clear();
200 const auto knownRoles = model->roleNames();
201 for (auto role : modelInfo.roles.split(sep: '|')) {
202 if (role.isEmpty())
203 continue;
204 const int roleIndex = knownRoles.key(value: role, defaultKey: -1);
205 if (roleIndex == -1) {
206 qCWarning(QT_REMOTEOBJECT) << "Invalid role" << role << "for model" << model->metaObject()->className();
207 qCWarning(QT_REMOTEOBJECT) << " known roles:" << knownRoles;
208 } else
209 roles << roleIndex;
210 }
211 auto adapter = new QAbstractItemModelSourceAdapter(model, nullptr,
212 roles.isEmpty() ? knownRoles.keys().toVector() : roles);
213 m_children.insert(key: i, value: new QRemoteObjectSource(model, d, modelApi, adapter, api->name()));
214 }
215 } else {
216 const auto classApi = api->m_subclasses.at(i: subclassIndex++);
217 m_children.insert(key: i, value: new QRemoteObjectSource(child, d, classApi, nullptr, api->name()));
218 }
219 }
220 }
221 }
222}
223
224QRemoteObjectSource::QRemoteObjectSource(QObject *obj, Private *dd, const SourceApiMap *api, QObject *adapter, const QString &parentName)
225 : QRemoteObjectSourceBase(obj, dd, api, adapter)
226 , m_name(api->typeName() == QLatin1String("QAbstractItemModelAdapter") ? MODEL().arg(a: parentName + QLatin1String("::") + api->name()) :
227 CLASS().arg(a: parentName + QLatin1String("::") + api->name()))
228{
229 if (obj)
230 d->m_sourceIo->registerSource(source: this);
231}
232
233QRemoteObjectRootSource::QRemoteObjectRootSource(QObject *obj, const SourceApiMap *api,
234 QObject *adapter, QRemoteObjectSourceIo *sourceIo)
235 : QRemoteObjectSourceBase(obj, new Private(sourceIo, this), api, adapter)
236 , m_name(api->name())
237{
238 d->m_sourceIo->registerSource(source: this);
239}
240
241QRemoteObjectSourceBase::~QRemoteObjectSourceBase()
242{
243 delete m_api;
244}
245
246void QRemoteObjectSourceBase::setConnections()
247{
248 const QMetaObject *meta = m_object->metaObject();
249
250 const int index = meta->indexOfClassInfo(QCLASSINFO_REMOTEOBJECT_TYPE);
251 if (index != -1) { //We have an object created from repc or at least with QCLASSINFO defined
252 while (true) {
253 Q_ASSERT(meta->superClass()); //This recurses to QObject, which doesn't have QCLASSINFO_REMOTEOBJECT_TYPE
254 if (index != meta->superClass()->indexOfClassInfo(QCLASSINFO_REMOTEOBJECT_TYPE)) //At the point we don't find the same QCLASSINFO_REMOTEOBJECT_TYPE,
255 //we have the metaobject we should work from
256 break;
257 meta = meta->superClass();
258 }
259 }
260
261 for (int idx = 0; idx < m_api->signalCount(); ++idx) {
262 const int sourceIndex = m_api->sourceSignalIndex(index: idx);
263 const bool isAdapter = m_api->isAdapterSignal(idx);
264 const auto targetMeta = isAdapter ? m_adapter->metaObject() : meta;
265
266 // don't connect cloned signals, or we end up with multiple emissions
267 if (qtro_is_cloned_method(mobj: targetMeta, index: sourceIndex))
268 continue;
269 // This basically connects the parent Signals (note, all dynamic properties have onChange
270 //notifications, thus signals) to us. Normally each Signal is mapped to a unique index,
271 //but since we are forwarding them all, we keep the offset constant.
272 //
273 //We know no one will inherit from this class, so no need to worry about indices from
274 //derived classes.
275 const auto target = isAdapter ? m_adapter : m_object;
276 if (!QMetaObject::connect(sender: target, signal_index: sourceIndex, receiver: this, method_index: QRemoteObjectSource::qobjectMethodOffset+idx, type: Qt::DirectConnection, types: nullptr)) {
277 qCWarning(QT_REMOTEOBJECT) << "QRemoteObjectSourceBase: QMetaObject::connect returned false. Unable to connect.";
278 return;
279 }
280
281 qCDebug(QT_REMOTEOBJECT) << "Connection made" << idx << sourceIndex
282 << targetMeta->method(index: sourceIndex).name();
283 }
284}
285
286void QRemoteObjectSourceBase::resetObject(QObject *newObject)
287{
288 if (m_object)
289 m_object->disconnect(receiver: this);
290 if (m_adapter) {
291 m_adapter->disconnect(receiver: this);
292 delete m_adapter;
293 m_adapter = nullptr;
294 }
295 // We need some dynamic replica specific code here, in case an object had null sub-classes that
296 // have been replaced with real objects. In this case, the ApiMap could be wrong and need updating.
297 if (newObject && qobject_cast<QRemoteObjectDynamicReplica *>(object: newObject) && m_api->isDynamic()) {
298 auto api = static_cast<const DynamicApiMap*>(m_api);
299 if (api->m_properties[0] == 0) { // 0 is an index into QObject itself, so this isn't a valid QtRO index
300 const auto rep = qobject_cast<QRemoteObjectDynamicReplica *>(object: newObject);
301 auto tmp = m_api;
302 m_api = new DynamicApiMap(newObject, rep->metaObject(), api->m_name, QLatin1String(rep->metaObject()->className()));
303 qCDebug(QT_REMOTEOBJECT) << " Reset m_api for" << api->m_name << "using new metaObject:" << rep->metaObject()->className();
304 delete tmp;
305 }
306 }
307
308 m_object = newObject;
309 auto model = qobject_cast<QAbstractItemModel *>(object: newObject);
310 if (model) {
311 d->m_sourceIo->registerSource(source: this);
312 m_adapter = new QAbstractItemModelSourceAdapter(model, nullptr, model->roleNames().keys().toVector());
313 }
314
315 setParent(newObject);
316 if (newObject)
317 setConnections();
318
319 const auto nChildren = m_api->m_models.size() + m_api->m_subclasses.size();
320 if (nChildren == 0)
321 return;
322
323 if (!newObject) {
324 for (auto child : m_children)
325 child->resetObject(newObject: nullptr);
326 return;
327 }
328
329 for (int i : m_children.keys()) {
330 const int index = m_api->sourcePropertyIndex(index: i);
331 const auto property = m_object->metaObject()->property(index);
332 QObject *child = property.read(obj: m_object).value<QObject *>();
333 m_children[i]->resetObject(newObject: child);
334 }
335}
336
337QRemoteObjectSource::~QRemoteObjectSource()
338{
339 for (auto it : m_children) {
340 // We used QPointers for m_children because we don't control the lifetime of child QObjects
341 // Since the this/source QObject's parent is the referenced QObject, it could have already
342 // been deleted
343 delete it;
344 }
345}
346
347QRemoteObjectRootSource::~QRemoteObjectRootSource()
348{
349 for (auto it : m_children) {
350 // We used QPointers for m_children because we don't control the lifetime of child QObjects
351 // Since the this/source QObject's parent is the referenced QObject, it could have already
352 // been deleted
353 delete it;
354 }
355 d->m_sourceIo->unregisterSource(source: this);
356 // removeListener tries to modify d->m_listeners, this is O(N²),
357 // so clear d->m_listeners prior to calling unregister (consume loop).
358 // We can do this, because we don't care about the return value of removeListener() here.
359 for (QtROIoDeviceBase *io : std::exchange(obj&: d->m_listeners, new_val: {})) {
360 removeListener(io, shouldSendRemove: true);
361 }
362 delete d;
363}
364
365QVariantList* QRemoteObjectSourceBase::marshalArgs(int index, void **a)
366{
367 QVariantList &list = m_marshalledArgs;
368 int N = m_api->signalParameterCount(index);
369 if (N == 1 && QMetaType(m_api->signalParameterType(sigIndex: index, paramIndex: 0)).flags().testFlag(flag: QMetaType::PointerToQObject))
370 N = 0; // Don't try to send pointers, the will be handle by QRO_
371 if (list.size() < N)
372 list.reserve(asize: N);
373 const int minFill = std::min(a: int(list.size()), b: N);
374 for (int i = 0; i < minFill; ++i) {
375 const int type = m_api->signalParameterType(sigIndex: index, paramIndex: i);
376 if (type == QMetaType::QVariant)
377 list[i] = *reinterpret_cast<QVariant *>(a[i + 1]);
378 else
379 list[i] = QVariant(QMetaType(type), a[i + 1]);
380 }
381 for (int i = int(list.size()); i < N; ++i) {
382 const int type = m_api->signalParameterType(sigIndex: index, paramIndex: i);
383 if (type == QMetaType::QVariant)
384 list << *reinterpret_cast<QVariant *>(a[i + 1]);
385 else
386 list << QVariant(QMetaType(type), a[i + 1]);
387 }
388 for (int i = N; i < list.size(); ++i)
389 list.removeLast();
390 return &m_marshalledArgs;
391}
392
393bool QRemoteObjectSourceBase::invoke(QMetaObject::Call c, int index, const QVariantList &args, QVariant* returnValue)
394{
395 int status = -1;
396 int flags = 0;
397 bool forAdapter = (c == QMetaObject::InvokeMetaMethod ? m_api->isAdapterMethod(index) : m_api->isAdapterProperty(index));
398 int resolvedIndex = (c == QMetaObject::InvokeMetaMethod ? m_api->sourceMethodIndex(index) : m_api->sourcePropertyIndex(index));
399 if (resolvedIndex < 0)
400 return false;
401 QVarLengthArray<void*, 10> param(args.size() + 1);
402
403 if (c == QMetaObject::InvokeMetaMethod) {
404 QMetaMethod method;
405 if (!forAdapter)
406 method = parent()->metaObject()->method(index: resolvedIndex);
407
408 if (returnValue) {
409 if (!forAdapter && method.isValid() && method.returnType() == QMetaType::QVariant)
410 param[0] = const_cast<void*>(reinterpret_cast<const void*>(returnValue));
411 else
412 param[0] = returnValue->data();
413 } else {
414 param[0] = nullptr;
415 }
416
417 auto argument = [&](int i) -> void * {
418 if ((forAdapter && m_api->methodParameterType(methodIndex: index, paramIndex: i) == QMetaType::QVariant) ||
419 (method.isValid() && method.parameterType(index: i) == QMetaType::QVariant)) {
420 return const_cast<void*>(reinterpret_cast<const void*>(&args.at(i)));
421 }
422 return const_cast<void*>(args.at(i).data());
423 };
424
425 for (int i = 0; i < args.size(); ++i) {
426 param[i + 1] = argument(i);
427 }
428 } else if (c == QMetaObject::WriteProperty || c == QMetaObject::ReadProperty) {
429 bool isQVariant = !forAdapter && parent()->metaObject()->property(index: resolvedIndex).userType() == QMetaType::QVariant;
430 for (int i = 0; i < args.size(); ++i) {
431 if (isQVariant)
432 param[i] = const_cast<void*>(reinterpret_cast<const void*>(&args.at(i)));
433 else
434 param[i] = const_cast<void*>(args.at(i).data());
435 }
436 if (c == QMetaObject::WriteProperty) {
437 Q_ASSERT(param.size() == 2); // for return-value and setter value
438 // check QMetaProperty::write for an explanation of these
439 param.append(t: &status);
440 param.append(t: &flags);
441 }
442 } else {
443 // Better safe than sorry
444 return false;
445 }
446 int r = -1;
447 if (forAdapter)
448 r = m_adapter->qt_metacall(c, resolvedIndex, param.data());
449 else
450 r = parent()->qt_metacall(c, resolvedIndex, param.data());
451 return r == -1 && status == -1;
452}
453
454void QRemoteObjectSourceBase::handleMetaCall(int index, QMetaObject::Call call, void **a)
455{
456 if (d->m_listeners.empty())
457 return;
458
459 int propertyIndex = m_api->propertyIndexFromSignal(index);
460 if (propertyIndex >= 0) {
461 const int internalIndex = m_api->propertyRawIndexFromSignal(index);
462 const auto target = m_api->isAdapterProperty(internalIndex) ? m_adapter : m_object;
463 const QMetaProperty mp = target->metaObject()->property(index: propertyIndex);
464 qCDebug(QT_REMOTEOBJECT) << "Sending Invoke Property" << (m_api->isAdapterSignal(internalIndex) ? "via adapter" : "") << internalIndex << propertyIndex << mp.name() << mp.read(obj: target);
465
466 d->codec->serializePropertyChangePacket(source: this, signalIndex: index);
467 propertyIndex = internalIndex;
468 }
469
470 qCDebug(QT_REMOTEOBJECT) << "# Listeners" << d->m_listeners.size();
471 qCDebug(QT_REMOTEOBJECT) << "Invoke args:" << m_object
472 << (call == 0 ? QLatin1String("InvokeMetaMethod") : QStringLiteral("Non-invoked call: %d").arg(a: call))
473 << m_api->signalSignature(index) << *marshalArgs(index, a);
474
475 d->codec->serializeInvokePacket(name: name(), call, index, args: *marshalArgs(index, a), serialId: -1, propertyIndex);
476
477 d->codec->send(connections: d->m_listeners);
478}
479
480void QRemoteObjectRootSource::addListener(QtROIoDeviceBase *io, bool dynamic)
481{
482 d->m_listeners.append(t: io);
483 d->isDynamic = d->isDynamic || dynamic;
484
485 if (dynamic) {
486 d->sentTypes.clear();
487 d->codec->serializeInitDynamicPacket(this);
488 d->codec->send(connection: io);
489 } else {
490 d->codec->serializeInitPacket(this);
491 d->codec->send(connection: io);
492 }
493}
494
495int QRemoteObjectRootSource::removeListener(QtROIoDeviceBase *io, bool shouldSendRemove)
496{
497 d->m_listeners.removeAll(t: io);
498 if (shouldSendRemove)
499 {
500 d->codec->serializeRemoveObjectPacket(name: m_api->name());
501 d->codec->send(connection: io);
502 }
503 return int(d->m_listeners.size());
504}
505
506int QRemoteObjectSourceBase::qt_metacall(QMetaObject::Call call, int methodId, void **a)
507{
508 methodId = QObject::qt_metacall(call, methodId, a);
509 if (methodId < 0)
510 return methodId;
511
512 if (call == QMetaObject::InvokeMetaMethod)
513 handleMetaCall(index: methodId, call, a);
514
515 return -1;
516}
517
518DynamicApiMap::DynamicApiMap(QObject *object, const QMetaObject *metaObject, const QString &name, const QString &typeName)
519 : m_name(name),
520 m_typeName(typeName),
521 m_metaObject(metaObject),
522 m_cachedMetamethodIndex(-1)
523{
524 m_enumOffset = metaObject->enumeratorOffset();
525 m_enumCount = metaObject->enumeratorCount() - m_enumOffset;
526
527 const int propCount = metaObject->propertyCount();
528 const int propOffset = metaObject->propertyOffset();
529 m_properties.reserve(asize: propCount-propOffset);
530 QSet<int> invalidSignals;
531 for (int i = propOffset; i < propCount; ++i) {
532 const QMetaProperty property = metaObject->property(index: i);
533 const auto metaType = property.metaType();
534 if (metaType.flags().testFlag(flag: QMetaType::PointerToQObject)) {
535 auto propertyMeta = metaType.metaObject();
536 QObject *child = property.read(obj: object).value<QObject *>();
537 const QMetaObject *meta = child ? child->metaObject() : propertyMeta;
538 if (!meta) {
539 const int notifyIndex = metaObject->property(index: i).notifySignalIndex();
540 if (notifyIndex != -1)
541 invalidSignals << notifyIndex;
542 continue;
543 }
544 if (meta->inherits(metaObject: &QAbstractItemModel::staticMetaObject)) {
545 const QByteArray name = QByteArray::fromRawData(data: property.name(),
546 size: qsizetype(qstrlen(str: property.name())));
547 const QByteArray infoName = name.toUpper() + QByteArrayLiteral("_ROLES");
548 const int infoIndex = metaObject->indexOfClassInfo(name: infoName.constData());
549 QByteArray roleInfo;
550 if (infoIndex >= 0) {
551 auto ci = metaObject->classInfo(index: infoIndex);
552 roleInfo = QByteArray::fromRawData(data: ci.value(), size: qsizetype(qstrlen(str: ci.value())));
553 }
554 m_models << ModelInfo({.ptr: qobject_cast<QAbstractItemModel *>(object: child),
555 .name: QString::fromLatin1(ba: property.name()),
556 .roles: roleInfo});
557 } else {
558 QString typeName = QtRemoteObjects::getTypeNameAndMetaobjectFromClassInfo(meta);
559 if (typeName.isNull()) {
560 typeName = QString::fromLatin1(ba: meta->className());
561 if (typeName.contains(s: QLatin1String("QQuick")))
562 typeName.remove(s: QLatin1String("QQuick"));
563 else if (int index = typeName.indexOf(s: QLatin1String("_QMLTYPE_")))
564 typeName.truncate(pos: index);
565 // TODO better way to ensure we have consistent typenames between source/replicas?
566 else if (typeName.endsWith(s: QLatin1String("Source")))
567 typeName.chop(n: 6);
568 }
569
570 m_subclasses << new DynamicApiMap(child, meta, QString::fromLatin1(ba: property.name()), typeName);
571 }
572 }
573 m_properties << i;
574 const int notifyIndex = metaObject->property(index: i).notifySignalIndex();
575 if (notifyIndex != -1) {
576 m_signals << notifyIndex;
577 m_propertyAssociatedWithSignal.append(t: i-propOffset);
578 //The starting values of _signals will be the notify signals
579 //So if we are processing _signal with index i, api->sourcePropertyIndex(_propertyAssociatedWithSignal.at(i))
580 //will be the property that changed. This is only valid if i < _propertyAssociatedWithSignal.size().
581 }
582 }
583 const int methodCount = metaObject->methodCount();
584 const int methodOffset = metaObject->methodOffset();
585 for (int i = methodOffset; i < methodCount; ++i) {
586 const QMetaMethod mm = metaObject->method(index: i);
587 const QMetaMethod::MethodType m = mm.methodType();
588 if (m == QMetaMethod::Signal) {
589 if (m_signals.indexOf(t: i) >= 0) // Already added as a property notifier
590 continue;
591 if (invalidSignals.contains(value: i)) // QObject with no metatype
592 continue;
593 m_signals << i;
594 } else if (m == QMetaMethod::Slot || m == QMetaMethod::Method)
595 m_methods << i;
596 }
597
598 m_objectSignature = QtPrivate::qtro_classinfo_signature(metaObject);
599}
600
601QByteArrayList DynamicApiMap::signalParameterNames(int index) const
602{
603 const int objectIndex = m_signals.at(i: index);
604 checkCache(objectIndex);
605 return m_cachedMetamethod.parameterNames();
606}
607
608int DynamicApiMap::parameterCount(int objectIndex) const
609{
610 checkCache(objectIndex);
611 return m_cachedMetamethod.parameterCount();
612}
613
614int DynamicApiMap::parameterType(int objectIndex, int paramIndex) const
615{
616 checkCache(objectIndex);
617 return m_cachedMetamethod.parameterType(index: paramIndex);
618}
619
620const QByteArray DynamicApiMap::signature(int objectIndex) const
621{
622 checkCache(objectIndex);
623 return m_cachedMetamethod.methodSignature();
624}
625
626QMetaMethod::MethodType DynamicApiMap::methodType(int index) const
627{
628 const int objectIndex = m_methods.at(i: index);
629 checkCache(objectIndex);
630 return m_cachedMetamethod.methodType();
631}
632
633const QByteArray DynamicApiMap::typeName(int index) const
634{
635 const int objectIndex = m_methods.at(i: index);
636 checkCache(objectIndex);
637 return m_cachedMetamethod.typeName();
638}
639
640QByteArrayList DynamicApiMap::methodParameterNames(int index) const
641{
642 const int objectIndex = m_methods.at(i: index);
643 checkCache(objectIndex);
644 return m_cachedMetamethod.parameterNames();
645}
646
647QRemoteObjectSourceBase::Private::Private(QRemoteObjectSourceIo *io, QRemoteObjectRootSource *root)
648 : m_sourceIo(io), codec(io->m_codec.data()), isDynamic(false), root(root)
649{
650}
651
652QT_END_NAMESPACE
653

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