| 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 | #include "qtremoteobjectglobal.h" |
| 6 | #include "qremoteobjectpacket_p.h" |
| 7 | |
| 8 | #include <QtCore/qdatastream.h> |
| 9 | #include <QtCore/qmetaobject.h> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | Q_LOGGING_CATEGORY(QT_REMOTEOBJECT, "qt.remoteobjects" , QtWarningMsg) |
| 14 | Q_LOGGING_CATEGORY(QT_REMOTEOBJECT_MODELS, "qt.remoteobjects.models" , QtWarningMsg) |
| 15 | Q_LOGGING_CATEGORY(QT_REMOTEOBJECT_IO, "qt.remoteobjects.io" , QtWarningMsg) |
| 16 | |
| 17 | QT_IMPL_METATYPE_EXTERN(QRemoteObjectSourceLocation) |
| 18 | QT_IMPL_METATYPE_EXTERN(QRemoteObjectSourceLocations) |
| 19 | QT_IMPL_METATYPE_EXTERN(QIntHash) |
| 20 | |
| 21 | /*! |
| 22 | \namespace QtRemoteObjects |
| 23 | \inmodule QtRemoteObjects |
| 24 | |
| 25 | \brief The QtRemoteObjects namespace contains identifiers used in the |
| 26 | Remote Objects module, as well as some functions used from code generated |
| 27 | by the \l{Qt Remote Objects Compiler}{Replica Compiler (repc)}. |
| 28 | */ |
| 29 | |
| 30 | /*! |
| 31 | \enum QtRemoteObjects::InitialAction |
| 32 | |
| 33 | This enum type specifies the initial action when acquiring a \l Replica derived |
| 34 | from QAbstractItemModel. |
| 35 | |
| 36 | \value FetchRootSize Only the size of the model is requested before the |
| 37 | \l {QRemoteObjectReplica::}{initialized} signal is emitted, |
| 38 | no data will be prefetched before that. |
| 39 | \value PrefetchData Some data can be prefetched before the |
| 40 | \l {QRemoteObjectReplica::}{initialized} signal is emitted. |
| 41 | |
| 42 | \sa QRemoteObjectNode::acquireModel(), QRemoteObjectReplica::initialized() |
| 43 | */ |
| 44 | |
| 45 | namespace QtRemoteObjects { |
| 46 | |
| 47 | void copyStoredProperties(const QMetaObject *mo, const void *src, void *dst) |
| 48 | { |
| 49 | if (!src) { |
| 50 | qCWarning(QT_REMOTEOBJECT) << Q_FUNC_INFO << ": trying to copy from a null source" ; |
| 51 | return; |
| 52 | } |
| 53 | if (!dst) { |
| 54 | qCWarning(QT_REMOTEOBJECT) << Q_FUNC_INFO << ": trying to copy to a null destination" ; |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | for (int i = 0, end = mo->propertyCount(); i != end; ++i) { |
| 59 | const QMetaProperty mp = mo->property(index: i); |
| 60 | mp.writeOnGadget(gadget: dst, value: mp.readOnGadget(gadget: src)); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void copyStoredProperties(const QMetaObject *mo, const void *src, QDataStream &dst) |
| 65 | { |
| 66 | if (!src) { |
| 67 | qCWarning(QT_REMOTEOBJECT) << Q_FUNC_INFO << ": trying to copy from a null source" ; |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | for (int i = 0, end = mo->propertyCount(); i != end; ++i) { |
| 72 | const QMetaProperty mp = mo->property(index: i); |
| 73 | dst << QRemoteObjectPackets::encodeVariant(value: mp.readOnGadget(gadget: src)); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void copyStoredProperties(const QMetaObject *mo, QDataStream &src, void *dst) |
| 78 | { |
| 79 | if (!dst) { |
| 80 | qCWarning(QT_REMOTEOBJECT) << Q_FUNC_INFO << ": trying to copy to a null destination" ; |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | for (int i = 0, end = mo->propertyCount(); i != end; ++i) { |
| 85 | const QMetaProperty mp = mo->property(index: i); |
| 86 | QVariant v; |
| 87 | src >> v; |
| 88 | mp.writeOnGadget(gadget: dst, value: QRemoteObjectPackets::decodeVariant(value: std::move(v), metaType: mp.metaType())); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | } // namespace QtRemoteObjects |
| 93 | |
| 94 | QT_END_NAMESPACE |
| 95 | |