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