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 QDBUSARGUMENT_P_H |
5 | #define QDBUSARGUMENT_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of the QLibrary class. This header file may change from |
13 | // version to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtDBus/private/qtdbusglobal_p.h> |
19 | #include <qdbusargument.h> |
20 | #include "qdbusconnection.h" |
21 | #include "qdbusunixfiledescriptor.h" |
22 | #include "qdbus_symbols_p.h" |
23 | |
24 | #ifndef QT_NO_DBUS |
25 | |
26 | #ifndef DBUS_TYPE_UNIX_FD |
27 | # define DBUS_TYPE_UNIX_FD int('h') |
28 | # define DBUS_TYPE_UNIX_FD_AS_STRING "h" |
29 | #endif |
30 | |
31 | QT_BEGIN_NAMESPACE |
32 | |
33 | class QDBusMarshaller; |
34 | class QDBusDemarshaller; |
35 | class QDBusArgumentPrivate |
36 | { |
37 | Q_DISABLE_COPY_MOVE(QDBusArgumentPrivate) |
38 | public: |
39 | enum class Direction { Marshalling, Demarshalling }; |
40 | |
41 | virtual ~QDBusArgumentPrivate(); |
42 | |
43 | static bool checkRead(QDBusArgumentPrivate *d); |
44 | static bool checkReadAndDetach(QDBusArgumentPrivate *&d); |
45 | static bool checkWrite(QDBusArgumentPrivate *&d); |
46 | |
47 | QDBusMarshaller *marshaller(); |
48 | QDBusDemarshaller *demarshaller(); |
49 | |
50 | static QByteArray createSignature(QMetaType type); |
51 | static inline QDBusArgument create(QDBusArgumentPrivate *d) |
52 | { |
53 | QDBusArgument q(d); |
54 | return q; |
55 | } |
56 | static inline QDBusArgumentPrivate *d(QDBusArgument &q) |
57 | { return q.d; } |
58 | |
59 | DBusMessage *message = nullptr; |
60 | QAtomicInt ref = 1; |
61 | QDBusConnection::ConnectionCapabilities capabilities; |
62 | Direction direction; |
63 | |
64 | protected: |
65 | explicit QDBusArgumentPrivate(Direction direction, |
66 | QDBusConnection::ConnectionCapabilities flags = {}) |
67 | : capabilities(flags), direction(direction) |
68 | { |
69 | } |
70 | }; |
71 | |
72 | class QDBusMarshaller final : public QDBusArgumentPrivate |
73 | { |
74 | public: |
75 | explicit QDBusMarshaller(QDBusConnection::ConnectionCapabilities flags = {}) |
76 | : QDBusArgumentPrivate(Direction::Marshalling, flags) |
77 | { |
78 | } |
79 | ~QDBusMarshaller(); |
80 | |
81 | QString currentSignature(); |
82 | |
83 | void append(uchar arg); |
84 | void append(bool arg); |
85 | void append(short arg); |
86 | void append(ushort arg); |
87 | void append(int arg); |
88 | void append(uint arg); |
89 | void append(qlonglong arg); |
90 | void append(qulonglong arg); |
91 | void append(double arg); |
92 | void append(const QString &arg); |
93 | void append(const QDBusObjectPath &arg); |
94 | void append(const QDBusSignature &arg); |
95 | void append(const QDBusUnixFileDescriptor &arg); |
96 | void append(const QStringList &arg); |
97 | void append(const QByteArray &arg); |
98 | bool append(const QDBusVariant &arg); // this one can fail |
99 | |
100 | QDBusMarshaller *beginStructure(); |
101 | QDBusMarshaller *endStructure(); |
102 | QDBusMarshaller *beginArray(QMetaType id); |
103 | QDBusMarshaller *endArray(); |
104 | QDBusMarshaller *beginMap(QMetaType kid, QMetaType vid); |
105 | QDBusMarshaller *endMap(); |
106 | QDBusMarshaller *beginMapEntry(); |
107 | QDBusMarshaller *endMapEntry(); |
108 | QDBusMarshaller *beginCommon(int code, const char *signature); |
109 | QDBusMarshaller *endCommon(); |
110 | void open(QDBusMarshaller &sub, int code, const char *signature); |
111 | void close(); |
112 | void error(const QString &message); |
113 | |
114 | bool appendVariantInternal(const QVariant &arg); |
115 | bool appendRegisteredType(const QVariant &arg); |
116 | bool appendCrossMarshalling(QDBusDemarshaller *arg); |
117 | |
118 | DBusMessageIter iterator; |
119 | QDBusMarshaller *parent = nullptr; |
120 | QByteArray *ba = nullptr; |
121 | QString errorString; |
122 | char closeCode = 0; |
123 | bool ok = true; |
124 | bool skipSignature = false; |
125 | |
126 | private: |
127 | Q_DECL_COLD_FUNCTION void unregisteredTypeError(QMetaType t); |
128 | Q_DISABLE_COPY_MOVE(QDBusMarshaller) |
129 | }; |
130 | |
131 | class QDBusDemarshaller final : public QDBusArgumentPrivate |
132 | { |
133 | public: |
134 | explicit QDBusDemarshaller(QDBusConnection::ConnectionCapabilities flags = {}) |
135 | : QDBusArgumentPrivate(Direction::Demarshalling, flags) |
136 | { |
137 | } |
138 | ~QDBusDemarshaller(); |
139 | |
140 | QString currentSignature(); |
141 | |
142 | uchar toByte(); |
143 | bool toBool(); |
144 | ushort toUShort(); |
145 | short toShort(); |
146 | int toInt(); |
147 | uint toUInt(); |
148 | qlonglong toLongLong(); |
149 | qulonglong toULongLong(); |
150 | double toDouble(); |
151 | QString toString(); |
152 | QDBusObjectPath toObjectPath(); |
153 | QDBusSignature toSignature(); |
154 | QDBusUnixFileDescriptor toUnixFileDescriptor(); |
155 | QDBusVariant toVariant(); |
156 | QStringList toStringList(); |
157 | QByteArray toByteArray(); |
158 | |
159 | QDBusDemarshaller *beginStructure(); |
160 | QDBusDemarshaller *endStructure(); |
161 | QDBusDemarshaller *beginArray(); |
162 | QDBusDemarshaller *endArray(); |
163 | QDBusDemarshaller *beginMap(); |
164 | QDBusDemarshaller *endMap(); |
165 | QDBusDemarshaller *beginMapEntry(); |
166 | QDBusDemarshaller *endMapEntry(); |
167 | QDBusDemarshaller *beginCommon(); |
168 | QDBusDemarshaller *endCommon(); |
169 | QDBusArgument duplicate(); |
170 | inline void close() { } |
171 | |
172 | bool atEnd(); |
173 | |
174 | QVariant toVariantInternal(); |
175 | QDBusArgument::ElementType currentType(); |
176 | bool isCurrentTypeStringLike(); |
177 | |
178 | DBusMessageIter iterator; |
179 | QDBusDemarshaller *parent = nullptr; |
180 | |
181 | private: |
182 | Q_DISABLE_COPY_MOVE(QDBusDemarshaller) |
183 | QString toStringUnchecked(); |
184 | QDBusObjectPath toObjectPathUnchecked(); |
185 | QDBusSignature toSignatureUnchecked(); |
186 | QStringList toStringListUnchecked(); |
187 | QByteArray toByteArrayUnchecked(); |
188 | }; |
189 | |
190 | inline QDBusMarshaller *QDBusArgumentPrivate::marshaller() |
191 | { return static_cast<QDBusMarshaller *>(this); } |
192 | |
193 | inline QDBusDemarshaller *QDBusArgumentPrivate::demarshaller() |
194 | { return static_cast<QDBusDemarshaller *>(this); } |
195 | |
196 | QT_END_NAMESPACE |
197 | |
198 | #endif // QT_NO_DBUS |
199 | #endif |
200 | |