1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QDBUSARGUMENT_P_H |
43 | #define QDBUSARGUMENT_P_H |
44 | |
45 | // |
46 | // W A R N I N G |
47 | // ------------- |
48 | // |
49 | // This file is not part of the Qt API. It exists for the convenience |
50 | // of the QLibrary class. This header file may change from |
51 | // version to version without notice, or even be removed. |
52 | // |
53 | // We mean it. |
54 | // |
55 | |
56 | #include <qdbusargument.h> |
57 | #include "qdbusunixfiledescriptor.h" |
58 | #include "qdbus_symbols_p.h" |
59 | |
60 | #ifndef QT_NO_DBUS |
61 | |
62 | #ifndef DBUS_TYPE_UNIX_FD |
63 | # define DBUS_TYPE_UNIX_FD int('h') |
64 | # define DBUS_TYPE_UNIX_FD_AS_STRING "h" |
65 | #endif |
66 | |
67 | QT_BEGIN_NAMESPACE |
68 | |
69 | class QDBusMarshaller; |
70 | class QDBusDemarshaller; |
71 | class QDBusArgumentPrivate |
72 | { |
73 | public: |
74 | inline QDBusArgumentPrivate(int flags = 0) |
75 | : message(0), ref(1), capabilities(flags) |
76 | { } |
77 | ~QDBusArgumentPrivate(); |
78 | |
79 | static bool checkRead(QDBusArgumentPrivate *d); |
80 | static bool checkReadAndDetach(QDBusArgumentPrivate *&d); |
81 | static bool checkWrite(QDBusArgumentPrivate *&d); |
82 | |
83 | QDBusMarshaller *marshaller(); |
84 | QDBusDemarshaller *demarshaller(); |
85 | |
86 | static QByteArray createSignature(int id); |
87 | static inline QDBusArgument create(QDBusArgumentPrivate *d) |
88 | { |
89 | QDBusArgument q(d); |
90 | return q; |
91 | } |
92 | static inline QDBusArgumentPrivate *d(QDBusArgument &q) |
93 | { return q.d; } |
94 | |
95 | public: |
96 | DBusMessage *message; |
97 | QAtomicInt ref; |
98 | int capabilities; |
99 | enum Direction { |
100 | Marshalling, |
101 | Demarshalling |
102 | } direction; |
103 | }; |
104 | |
105 | class QDBusMarshaller: public QDBusArgumentPrivate |
106 | { |
107 | public: |
108 | QDBusMarshaller(int flags) : QDBusArgumentPrivate(flags), parent(0), ba(0), closeCode(0), ok(true) |
109 | { direction = Marshalling; } |
110 | ~QDBusMarshaller(); |
111 | |
112 | QString currentSignature(); |
113 | |
114 | void append(uchar arg); |
115 | void append(bool arg); |
116 | void append(short arg); |
117 | void append(ushort arg); |
118 | void append(int arg); |
119 | void append(uint arg); |
120 | void append(qlonglong arg); |
121 | void append(qulonglong arg); |
122 | void append(double arg); |
123 | void append(const QString &arg); |
124 | void append(const QDBusObjectPath &arg); |
125 | void append(const QDBusSignature &arg); |
126 | void append(const QDBusUnixFileDescriptor &arg); |
127 | void append(const QStringList &arg); |
128 | void append(const QByteArray &arg); |
129 | bool append(const QDBusVariant &arg); // this one can fail |
130 | |
131 | QDBusMarshaller *beginStructure(); |
132 | QDBusMarshaller *endStructure(); |
133 | QDBusMarshaller *beginArray(int id); |
134 | QDBusMarshaller *endArray(); |
135 | QDBusMarshaller *beginMap(int kid, int vid); |
136 | QDBusMarshaller *endMap(); |
137 | QDBusMarshaller *beginMapEntry(); |
138 | QDBusMarshaller *endMapEntry(); |
139 | QDBusMarshaller *beginCommon(int code, const char *signature); |
140 | QDBusMarshaller *endCommon(); |
141 | void open(QDBusMarshaller &sub, int code, const char *signature); |
142 | void close(); |
143 | void error(const QString &message); |
144 | |
145 | bool appendVariantInternal(const QVariant &arg); |
146 | bool appendRegisteredType(const QVariant &arg); |
147 | bool appendCrossMarshalling(QDBusDemarshaller *arg); |
148 | |
149 | public: |
150 | DBusMessageIter iterator; |
151 | QDBusMarshaller *parent; |
152 | QByteArray *ba; |
153 | QString errorString; |
154 | char closeCode; |
155 | bool ok; |
156 | |
157 | private: |
158 | Q_DISABLE_COPY(QDBusMarshaller) |
159 | }; |
160 | |
161 | class QDBusDemarshaller: public QDBusArgumentPrivate |
162 | { |
163 | public: |
164 | inline QDBusDemarshaller(int flags) : QDBusArgumentPrivate(flags), parent(0) |
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 | |
206 | public: |
207 | DBusMessageIter iterator; |
208 | QDBusDemarshaller *parent; |
209 | |
210 | private: |
211 | Q_DISABLE_COPY(QDBusDemarshaller) |
212 | QString toStringUnchecked(); |
213 | QDBusObjectPath toObjectPathUnchecked(); |
214 | QDBusSignature toSignatureUnchecked(); |
215 | QStringList toStringListUnchecked(); |
216 | QByteArray toByteArrayUnchecked(); |
217 | }; |
218 | |
219 | inline QDBusMarshaller *QDBusArgumentPrivate::marshaller() |
220 | { return static_cast<QDBusMarshaller *>(this); } |
221 | |
222 | inline QDBusDemarshaller *QDBusArgumentPrivate::demarshaller() |
223 | { return static_cast<QDBusDemarshaller *>(this); } |
224 | |
225 | QT_END_NAMESPACE |
226 | |
227 | #endif // QT_NO_DBUS |
228 | #endif |
229 | |