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

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