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#include "qdbusextratypes.h"
5#include "qdbusutil_p.h"
6
7#ifndef QT_NO_DBUS
8
9QT_BEGIN_NAMESPACE
10
11QT_IMPL_METATYPE_EXTERN(QDBusVariant)
12QT_IMPL_METATYPE_EXTERN(QDBusObjectPath)
13QT_IMPL_METATYPE_EXTERN(QDBusSignature)
14
15#ifndef QT_NO_DEBUG_STREAM
16/*!
17 \fn QDebug QDBusObjectPath::operator<<(QDebug dbg, const QDBusObjectPath &path)
18 \since 6.8
19 Writes the contents of \a path to \a dbg.
20*/
21QDebug operator<<(QDebug dbg, const QDBusObjectPath &path)
22{
23 QDebugStateSaver saver(dbg);
24 dbg.nospace() << "QDBusObjectPath(" << path.path() << ')';
25 return dbg;
26}
27#endif
28
29void QDBusObjectPath::doCheck()
30{
31 if (!QDBusUtil::isValidObjectPath(path: m_path)) {
32 qWarning(msg: "QDBusObjectPath: invalid path \"%s\"", qPrintable(m_path));
33 m_path.clear();
34 }
35}
36
37QDBusSignature::QDBusSignature() noexcept
38 : m_signature(QLatin1StringView("")) // mark non-null (empty signatures are valid)
39{}
40
41void QDBusSignature::doCheck()
42{
43 if (!QDBusUtil::isValidSignature(signature: m_signature)) {
44 qWarning(msg: "QDBusSignature: invalid signature \"%s\"", qPrintable(m_signature));
45 m_signature.clear();
46 } else if (m_signature.isEmpty()) {
47 m_signature.detach(); // we need it to not be null
48 }
49}
50
51/*!
52 \class QDBusVariant
53 \inmodule QtDBus
54 \since 4.2
55
56 \brief The QDBusVariant class enables the programmer to identify
57 the variant type provided by the D-Bus typesystem.
58
59 A D-Bus function that takes an integer, a D-Bus variant and a string as parameters
60 can be called with the following argument list (see QDBusMessage::setArguments()):
61
62 \snippet qdbusextratypes/qdbusextratypes.cpp 0
63
64 When a D-Bus function returns a D-Bus variant, it can be retrieved as follows:
65
66 \snippet qdbusextratypes/qdbusextratypes.cpp 1
67
68 The QVariant within a QDBusVariant is required to distinguish between a normal
69 D-Bus value and a value within a D-Bus variant.
70
71 \sa {The Qt D-Bus Type System}
72*/
73
74/*!
75 \fn QDBusVariant::QDBusVariant()
76
77 Constructs a new D-Bus variant.
78*/
79
80/*!
81 \fn QDBusVariant::QDBusVariant(const QVariant &variant)
82
83 Constructs a new D-Bus variant from the given Qt \a variant.
84
85 \sa setVariant()
86*/
87
88/*!
89 \fn QVariant QDBusVariant::variant() const
90
91 Returns this D-Bus variant as a QVariant object.
92
93 \sa setVariant()
94*/
95
96/*!
97 \fn void QDBusVariant::setVariant(const QVariant &variant)
98
99 Assigns the value of the given Qt \a variant to this D-Bus variant.
100
101 \sa variant()
102*/
103
104/*!
105 \class QDBusObjectPath
106 \inmodule QtDBus
107 \since 4.2
108
109 \brief The QDBusObjectPath class enables the programmer to
110 identify the OBJECT_PATH type provided by the D-Bus typesystem.
111
112 \sa {The Qt D-Bus Type System}
113*/
114
115/*!
116 \fn QDBusObjectPath::QDBusObjectPath()
117
118 Constructs a new object path.
119*/
120
121/*!
122 \fn QDBusObjectPath::QDBusObjectPath(const char *path)
123
124 Constructs a new object path from the given \a path.
125
126 \sa setPath()
127*/
128
129/*!
130 \fn QDBusObjectPath::QDBusObjectPath(QLatin1StringView path)
131
132 Constructs a new object path from the Latin-1 string viewed by \a path.
133*/
134
135/*!
136 \fn QDBusObjectPath::QDBusObjectPath(const QString &path)
137
138 Constructs a new object path from the given \a path.
139*/
140
141/*!
142 \fn QString QDBusObjectPath::path() const
143
144 Returns this object path.
145
146 \sa setPath()
147*/
148
149/*!
150 \fn void QDBusObjectPath::setPath(const QString &path)
151
152 Assigns the value of the given \a path to this object path.
153
154 \sa path()
155*/
156
157/*!
158 \since 5.14
159
160 Implicit cast to QVariant. Equivalent to calling
161 QVariant::fromValue() with this object as argument.
162*/
163QDBusObjectPath::operator QVariant() const { return QVariant::fromValue(value: *this); }
164
165/*!
166 \class QDBusSignature
167 \inmodule QtDBus
168 \since 4.2
169
170 \brief The QDBusSignature class enables the programmer to
171 identify the SIGNATURE type provided by the D-Bus typesystem.
172
173 \sa {The Qt D-Bus Type System}
174*/
175
176/*!
177 \fn QDBusSignature::QDBusSignature()
178
179 Constructs a new signature.
180
181 \sa setSignature()
182*/
183
184/*!
185 \fn QDBusSignature::QDBusSignature(const char *signature)
186
187 Constructs a new signature from the given \a signature.
188*/
189
190/*!
191 \fn QDBusSignature::QDBusSignature(QLatin1StringView signature)
192
193 Constructs a new signature from the Latin-1 string viewed by \a signature.
194*/
195
196/*!
197 \fn QDBusSignature::QDBusSignature(const QString &signature)
198
199 Constructs a new signature from the given \a signature.
200*/
201
202/*!
203 \fn QString QDBusSignature::signature() const
204
205 Returns this signature.
206
207 \sa setSignature()
208*/
209
210/*!
211 \fn void QDBusSignature::setSignature(const QString &signature)
212
213 Assigns the value of the given \a signature to this signature.
214 \sa signature()
215*/
216
217/*!
218 \fn void QDBusObjectPath::swap(QDBusObjectPath &other)
219
220 Swaps this QDBusObjectPath instance with \a other.
221*/
222
223/*!
224 \fn void QDBusSignature::swap(QDBusSignature &other)
225
226 Swaps this QDBusSignature instance with \a other.
227*/
228
229/*!
230 \fn void QDBusVariant::swap(QDBusVariant &other)
231
232 Swaps this QDBusVariant instance with \a other.
233*/
234
235QT_END_NAMESPACE
236
237#endif // QT_NO_DBUS
238

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/dbus/qdbusextratypes.cpp