1// Copyright (C) 2016 The Qt Company Ltd.
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 QDBUSMETATYPE_H
6#define QDBUSMETATYPE_H
7
8#include <QtDBus/qtdbusglobal.h>
9#include "QtCore/qmetatype.h"
10#include <QtDBus/qdbusargument.h>
11
12#ifndef QT_NO_DBUS
13
14QT_BEGIN_NAMESPACE
15
16
17class Q_DBUS_EXPORT QDBusMetaType
18{
19public:
20 typedef void (*MarshallFunction)(QDBusArgument &, const void *);
21 typedef void (*DemarshallFunction)(const QDBusArgument &, void *);
22
23 static void registerMarshallOperators(QMetaType typeId, MarshallFunction, DemarshallFunction);
24 static bool marshall(QDBusArgument &, QMetaType id, const void *data);
25 static bool demarshall(const QDBusArgument &, QMetaType id, void *data);
26
27 static void registerCustomType(QMetaType type, const QByteArray &signature);
28
29 static QMetaType signatureToMetaType(const char *signature);
30 static const char *typeToSignature(QMetaType type);
31};
32
33template<typename T>
34QMetaType qDBusRegisterMetaType()
35{
36 auto mf = [](QDBusArgument &arg, const void *t) { arg << *static_cast<const T *>(t); };
37 auto df = [](const QDBusArgument &arg, void *t) { arg >> *static_cast<T *>(t); };
38
39 QMetaType metaType = QMetaType::fromType<T>();
40 QDBusMetaType::registerMarshallOperators(typeId: metaType, mf, df);
41 return metaType;
42}
43
44QT_END_NAMESPACE
45
46#endif // QT_NO_DBUS
47#endif
48

source code of qtbase/src/dbus/qdbusmetatype.h