1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtDBus module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDBUSARGUMENT_P_H
41#define QDBUSARGUMENT_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the QLibrary class. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtDBus/private/qtdbusglobal_p.h>
55#include <qdbusargument.h>
56#include "qdbusunixfiledescriptor.h"
57#include "qdbus_symbols_p.h"
58
59#ifndef QT_NO_DBUS
60
61#ifndef DBUS_TYPE_UNIX_FD
62# define DBUS_TYPE_UNIX_FD int('h')
63# define DBUS_TYPE_UNIX_FD_AS_STRING "h"
64#endif
65
66QT_BEGIN_NAMESPACE
67
68class QDBusMarshaller;
69class QDBusDemarshaller;
70class QDBusArgumentPrivate
71{
72public:
73 inline QDBusArgumentPrivate(int flags = 0)
74 : message(nullptr), ref(1), capabilities(flags)
75 { }
76 virtual ~QDBusArgumentPrivate();
77
78 static bool checkRead(QDBusArgumentPrivate *d);
79 static bool checkReadAndDetach(QDBusArgumentPrivate *&d);
80 static bool checkWrite(QDBusArgumentPrivate *&d);
81
82 QDBusMarshaller *marshaller();
83 QDBusDemarshaller *demarshaller();
84
85 static QByteArray createSignature(int id);
86 static inline QDBusArgument create(QDBusArgumentPrivate *d)
87 {
88 QDBusArgument q(d);
89 return q;
90 }
91 static inline QDBusArgumentPrivate *d(QDBusArgument &q)
92 { return q.d; }
93
94public:
95 DBusMessage *message;
96 QAtomicInt ref;
97 int capabilities;
98 enum Direction {
99 Marshalling,
100 Demarshalling
101 } direction;
102};
103
104class QDBusMarshaller: public QDBusArgumentPrivate
105{
106public:
107 QDBusMarshaller(int flags) : QDBusArgumentPrivate(flags), parent(nullptr), ba(nullptr), closeCode(0), ok(true), skipSignature(false)
108 { direction = Marshalling; }
109 ~QDBusMarshaller();
110
111 QString currentSignature();
112
113 void append(uchar arg);
114 void append(bool arg);
115 void append(short arg);
116 void append(ushort arg);
117 void append(int arg);
118 void append(uint arg);
119 void append(qlonglong arg);
120 void append(qulonglong arg);
121 void append(double arg);
122 void append(const QString &arg);
123 void append(const QDBusObjectPath &arg);
124 void append(const QDBusSignature &arg);
125 void append(const QDBusUnixFileDescriptor &arg);
126 void append(const QStringList &arg);
127 void append(const QByteArray &arg);
128 bool append(const QDBusVariant &arg); // this one can fail
129
130 QDBusMarshaller *beginStructure();
131 QDBusMarshaller *endStructure();
132 QDBusMarshaller *beginArray(QMetaType id);
133 QDBusMarshaller *endArray();
134 QDBusMarshaller *beginMap(QMetaType kid, QMetaType vid);
135 QDBusMarshaller *endMap();
136 QDBusMarshaller *beginMapEntry();
137 QDBusMarshaller *endMapEntry();
138 QDBusMarshaller *beginCommon(int code, const char *signature);
139 QDBusMarshaller *endCommon();
140 void open(QDBusMarshaller &sub, int code, const char *signature);
141 void close();
142 void error(const QString &message);
143
144 bool appendVariantInternal(const QVariant &arg);
145 bool appendRegisteredType(const QVariant &arg);
146 bool appendCrossMarshalling(QDBusDemarshaller *arg);
147
148public:
149 DBusMessageIter iterator;
150 QDBusMarshaller *parent;
151 QByteArray *ba;
152 QString errorString;
153 char closeCode;
154 bool ok;
155 bool skipSignature;
156
157private:
158 Q_DISABLE_COPY_MOVE(QDBusMarshaller)
159};
160
161class QDBusDemarshaller: public QDBusArgumentPrivate
162{
163public:
164 inline QDBusDemarshaller(int flags) : QDBusArgumentPrivate(flags), parent(nullptr)
165 { direction = Demarshalling; }
166 ~QDBusDemarshaller();
167
168 QString currentSignature();
169
170 uchar toByte();
171 bool toBool();
172 ushort toUShort();
173 short toShort();
174 int toInt();
175 uint toUInt();
176 qlonglong toLongLong();
177 qulonglong toULongLong();
178 double toDouble();
179 QString toString();
180 QDBusObjectPath toObjectPath();
181 QDBusSignature toSignature();
182 QDBusUnixFileDescriptor toUnixFileDescriptor();
183 QDBusVariant toVariant();
184 QStringList toStringList();
185 QByteArray toByteArray();
186
187 QDBusDemarshaller *beginStructure();
188 QDBusDemarshaller *endStructure();
189 QDBusDemarshaller *beginArray();
190 QDBusDemarshaller *endArray();
191 QDBusDemarshaller *beginMap();
192 QDBusDemarshaller *endMap();
193 QDBusDemarshaller *beginMapEntry();
194 QDBusDemarshaller *endMapEntry();
195 QDBusDemarshaller *beginCommon();
196 QDBusDemarshaller *endCommon();
197 QDBusArgument duplicate();
198 inline void close() { }
199
200 bool atEnd();
201
202 QVariant toVariantInternal();
203 QDBusArgument::ElementType currentType();
204 bool isCurrentTypeStringLike();
205
206public:
207 DBusMessageIter iterator;
208 QDBusDemarshaller *parent;
209
210private:
211 Q_DISABLE_COPY_MOVE(QDBusDemarshaller)
212 QString toStringUnchecked();
213 QDBusObjectPath toObjectPathUnchecked();
214 QDBusSignature toSignatureUnchecked();
215 QStringList toStringListUnchecked();
216 QByteArray toByteArrayUnchecked();
217};
218
219inline QDBusMarshaller *QDBusArgumentPrivate::marshaller()
220{ return static_cast<QDBusMarshaller *>(this); }
221
222inline QDBusDemarshaller *QDBusArgumentPrivate::demarshaller()
223{ return static_cast<QDBusDemarshaller *>(this); }
224
225QT_END_NAMESPACE
226
227#endif // QT_NO_DBUS
228#endif
229