Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 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 | #include "qdbusintrospection_p.h" | - |
43 | #include "qdbusxmlparser_p.h" | - |
44 | | - |
45 | #ifndef QT_NO_DBUS | - |
46 | | - |
47 | QT_BEGIN_NAMESPACE | - |
48 | | - |
49 | /*! | - |
50 | \class QDBusIntrospection | - |
51 | \inmodule QtDBus | - |
52 | \brief Information about introspected objects and interfaces on D-Bus. | - |
53 | \internal | - |
54 | | - |
55 | This class provides structures and methods for parsing the XML introspection data for D-Bus. | - |
56 | Normally, you don't have to use the methods provided here: QDBusInterface and QDBusObject will | - |
57 | do that for you. | - |
58 | | - |
59 | But they may prove useful if the XML data was obtained through other means (like parsing a file). | - |
60 | */ | - |
61 | | - |
62 | /*! | - |
63 | \class QDBusIntrospection::Argument | - |
64 | \inmodule QtDBus | - |
65 | \brief One argument to a D-Bus method or signal. | - |
66 | | - |
67 | This struct represents one argument passed to a method or received from a method or signal in | - |
68 | D-Bus. The struct does not contain information on the direction (input or output). | - |
69 | */ | - |
70 | | - |
71 | /*! | - |
72 | \variable QDBusIntrospection::Argument::type | - |
73 | The argument type. | - |
74 | */ | - |
75 | | - |
76 | /*! | - |
77 | \variable QDBusIntrospection::Argument::name | - |
78 | The argument name. The argument name is optional, so this may be a null QString. | - |
79 | */ | - |
80 | | - |
81 | /*! | - |
82 | \fn QDBusIntrospection::Argument::operator==(const Argument &other) const | - |
83 | Compares this object against \a other and return true if they are the same. | - |
84 | */ | - |
85 | | - |
86 | /*! | - |
87 | \class QDBusIntrospection::Method | - |
88 | \inmodule QtDBus | - |
89 | \brief Information about one method. | - |
90 | | - |
91 | This struct represents one method discovered through introspection. A method is composed of | - |
92 | its \a name, its input arguments, its output arguments, and, optionally, annotations. There are no | - |
93 | "in-out" arguments. | - |
94 | */ | - |
95 | | - |
96 | /*! | - |
97 | \variable QDBusIntrospection::Method::name | - |
98 | The method's name. | - |
99 | */ | - |
100 | | - |
101 | /*! | - |
102 | \variable QDBusIntrospection::Method::inputArgs | - |
103 | A list of the method's input arguments. | - |
104 | */ | - |
105 | | - |
106 | /*! | - |
107 | \variable QDBusIntrospection::Method::outputArgs | - |
108 | A list of the method's output arguments (i.e., return values). | - |
109 | */ | - |
110 | | - |
111 | /*! | - |
112 | \variable QDBusIntrospection::Method::annotations | - |
113 | The annotations associated with the method. Each annotation is a pair of strings, where the key | - |
114 | is of the same format as a D-Bus interface name. The value is arbitrary. | - |
115 | */ | - |
116 | | - |
117 | /*! | - |
118 | \fn QDBusIntrospection::Method::operator==(const Method &other) const | - |
119 | Compares this object against \a other and return true if they are the same. | - |
120 | */ | - |
121 | | - |
122 | /*! | - |
123 | \class QDBusIntrospection::Signal | - |
124 | \inmodule QtDBus | - |
125 | \brief Information about one signal. | - |
126 | | - |
127 | This struct represents one signal discovered through introspection. A signal is composed of | - |
128 | its \a name, its output arguments, and, optionally, annotations. | - |
129 | */ | - |
130 | | - |
131 | /*! | - |
132 | \variable QDBusIntrospection::Signal::name | - |
133 | The signal's name. | - |
134 | */ | - |
135 | | - |
136 | /*! | - |
137 | \variable QDBusIntrospection::Signal::outputArgs | - |
138 | A list of the signal's arguments. | - |
139 | */ | - |
140 | | - |
141 | /*! | - |
142 | \variable QDBusIntrospection::Signal::annotations | - |
143 | The annotations associated with the signal. Each annotation is a pair of strings, where the key | - |
144 | is of the same format as a D-Bus interface name. The value is arbitrary. | - |
145 | */ | - |
146 | | - |
147 | /*! | - |
148 | \fn QDBusIntrospection::Signal::operator==(const Signal& other) const | - |
149 | Compares this object against \a other and return true if they are the same. | - |
150 | */ | - |
151 | | - |
152 | /*! | - |
153 | \class QDBusIntrospection::Property | - |
154 | \inmodule QtDBus | - |
155 | \brief Information about one property. | - |
156 | | - |
157 | This struct represents one property discovered through introspection. A property is composed of | - |
158 | its \a name, its \a type, its \a access rights, and, optionally, annotations. | - |
159 | */ | - |
160 | | - |
161 | /*! | - |
162 | \variable QDBusIntrospection::Property::name | - |
163 | The property's name. | - |
164 | */ | - |
165 | | - |
166 | /*! | - |
167 | \variable QDBusIntrospection::Property::type | - |
168 | The property's type. | - |
169 | */ | - |
170 | | - |
171 | /*! | - |
172 | \enum QDBusIntrospection::Property::Access | - |
173 | The possible access rights for a property: | - |
174 | \value Read | - |
175 | \value Write | - |
176 | \value ReadWrite | - |
177 | */ | - |
178 | | - |
179 | /*! | - |
180 | \variable QDBusIntrospection::Property::access | - |
181 | The property's access rights. | - |
182 | */ | - |
183 | | - |
184 | /*! | - |
185 | \variable QDBusIntrospection::Property::annotations | - |
186 | The annotations associated with the property. Each annotation is a pair of strings, where the key | - |
187 | is of the same format as a D-Bus interface name. The value is arbitrary. | - |
188 | */ | - |
189 | | - |
190 | /*! | - |
191 | \fn QDBusIntrospection::Property::operator==(const Property &other) const | - |
192 | Compares this object against \a other and return true if they are the same. | - |
193 | */ | - |
194 | | - |
195 | /*! | - |
196 | \class QDBusIntrospection::Interface | - |
197 | \inmodule QtDBus | - |
198 | \brief Information about one interface on the bus. | - |
199 | | - |
200 | Each interface on D-Bus has an unique \a name, identifying where that interface was defined. | - |
201 | Interfaces may have annotations, methods, signals and properties, but none are mandatory. | - |
202 | */ | - |
203 | | - |
204 | /*! | - |
205 | \variable QDBusIntrospection::Interface::name | - |
206 | The interface's name. | - |
207 | */ | - |
208 | | - |
209 | /*! | - |
210 | \variable QDBusIntrospection::Interface::introspection | - |
211 | The XML document fragment describing this interface. | - |
212 | | - |
213 | If parsed again through parseInterface, the object returned should have the same contents as | - |
214 | this object. | - |
215 | */ | - |
216 | | - |
217 | /*! | - |
218 | \variable QDBusIntrospection::Interface::annotations | - |
219 | The annotations associated with the interface. Each annotation is a pair of strings, where the key | - |
220 | is of the same format as a D-Bus interface name. The value is arbitrary. | - |
221 | */ | - |
222 | | - |
223 | /*! | - |
224 | \variable QDBusIntrospection::Interface::methods | - |
225 | The methods available in this interface. Note that method names are not unique (i.e., methods | - |
226 | can be overloaded with multiple arguments types). | - |
227 | */ | - |
228 | | - |
229 | /*! | - |
230 | \variable QDBusIntrospection::Interface::signals_ | - |
231 | The signals available in this interface. Note that signal names are not unique (i.e., signals | - |
232 | can be overloaded with multiple argument types). | - |
233 | | - |
234 | This member is called "signals_" because "signals" is a reserved keyword in Qt. | - |
235 | */ | - |
236 | | - |
237 | /*! | - |
238 | \variable QDBusIntrospection::Interface::properties | - |
239 | The properties available in this interface. Property names are unique. | - |
240 | */ | - |
241 | | - |
242 | /*! | - |
243 | \fn QDBusIntrospection::Interface::operator==(const Interface &other) const | - |
244 | Compares this object against \a other and return true if they are the same. | - |
245 | | - |
246 | Note that two interfaces are considered to be the same if they have the same name. The internal | - |
247 | structures in the objects are not compared. | - |
248 | */ | - |
249 | | - |
250 | /*! | - |
251 | \class QDBusIntrospection::Object | - |
252 | \inmodule QtDBus | - |
253 | \brief Information about one object on the bus. | - |
254 | | - |
255 | An object on the D-Bus bus is represented by its service and path on the service but, unlike | - |
256 | interfaces, objects are mutable. That is, their contents can change with time. Therefore, | - |
257 | while the (service, path) pair uniquely identifies an object, the information contained in | - |
258 | this struct may no longer represent the object. | - |
259 | | - |
260 | An object can contain interfaces and child (sub) objects. | - |
261 | */ | - |
262 | | - |
263 | /*! | - |
264 | \variable QDBusIntrospection::Object::service | - |
265 | The object's service name. | - |
266 | | - |
267 | \sa parseObject() | - |
268 | */ | - |
269 | | - |
270 | /*! | - |
271 | \variable QDBusIntrospection::Object::path | - |
272 | The object's path on the service. This is an absolute path. | - |
273 | | - |
274 | \sa parseObject() | - |
275 | */ | - |
276 | | - |
277 | /*! | - |
278 | \variable QDBusIntrospection::Object::introspection | - |
279 | The XML document fragment describing this object, its interfaces and sub-objects at the time | - |
280 | of the parsing. | - |
281 | | - |
282 | The result of parseObject with this XML data should be the same as the Object struct. | - |
283 | */ | - |
284 | | - |
285 | /*! | - |
286 | \variable QDBusIntrospection::Object::interfaces | - |
287 | The list of interface names in this object. | - |
288 | */ | - |
289 | | - |
290 | /*! | - |
291 | \variable QDBusIntrospection::Object::childObjects | - |
292 | The list of child object names in this object. Note that this is a relative name, not an | - |
293 | absolute path. To obtain the absolute path, concatenate with \l | - |
294 | {QDBusIntrospection::Object::path}{path}. | - |
295 | */ | - |
296 | | - |
297 | /*! | - |
298 | \typedef QDBusIntrospection::Annotations | - |
299 | Contains a QMap of an annotation pair. The annotation's name is stored in the QMap key and | - |
300 | must be unique. The annotation's value is stored in the QMap's value and is arbitrary. | - |
301 | */ | - |
302 | | - |
303 | /*! | - |
304 | \typedef QDBusIntrospection::Arguments | - |
305 | Contains a list of arguments to either a Method or a Signal. The arguments' order is important. | - |
306 | */ | - |
307 | | - |
308 | /*! | - |
309 | \typedef QDBusIntrospection::Methods | - |
310 | Contains a QMap of methods and their names. The method's name is stored in the map's key and | - |
311 | is not necessarily unique. The order in which multiple methods with the same name are stored | - |
312 | in this map is undefined. | - |
313 | */ | - |
314 | | - |
315 | /*! | - |
316 | \typedef QDBusIntrospection::Signals | - |
317 | Contains a QMap of signals and their names. The signal's name is stored in the map's key and | - |
318 | is not necessarily unique. The order in which multiple signals with the same name are stored | - |
319 | in this map is undefined. | - |
320 | */ | - |
321 | | - |
322 | /*! | - |
323 | \typedef QDBusIntrospection::Properties | - |
324 | Contains a QMap of properties and their names. Each property must have a unique name. | - |
325 | */ | - |
326 | | - |
327 | /*! | - |
328 | \typedef QDBusIntrospection::Interfaces | - |
329 | Contains a QMap of interfaces and their names. Each interface has a unique name. | - |
330 | */ | - |
331 | | - |
332 | /*! | - |
333 | \typedef QDBusIntrospection::Objects | - |
334 | Contains a QMap of objects and their paths relative to their immediate parent. | - |
335 | */ | - |
336 | | - |
337 | /*! | - |
338 | Parses the XML document fragment (given by \a xml) containing one interface. | - |
339 | | - |
340 | The first element tag in this XML data must be either \<node\> or \<interface\>. If it is | - |
341 | \<node\>, then the \<interface\> tag must be a child tag of the \<node\> one. | - |
342 | | - |
343 | If there are multiple interfaces in this XML data, it is undefined which one will be | - |
344 | returned. | - |
345 | */ | - |
346 | QDBusIntrospection::Interface | - |
347 | QDBusIntrospection::parseInterface(const QString &xml) | - |
348 | { | - |
349 | // be lazy | - |
350 | Interfaces ifs = parseInterfaces(xml); executed (the execution status of this line is deduced): Interfaces ifs = parseInterfaces(xml); | - |
351 | if (ifs.isEmpty()) evaluated: ifs.isEmpty() yes Evaluation Count:16 | yes Evaluation Count:40 |
| 16-40 |
352 | return Interface(); executed: return Interface(); Execution Count:16 | 16 |
353 | | - |
354 | // return the first in map order (probably alphabetical order) | - |
355 | return *ifs.constBegin().value(); executed: return *ifs.constBegin().value(); Execution Count:40 | 40 |
356 | } | - |
357 | | - |
358 | /*! | - |
359 | Parses the XML document fragment (given by \a xml) containing several interfaces. | - |
360 | | - |
361 | If the first element tag in this document fragment is \<node\>, the interfaces parsed will | - |
362 | be those found as child elements of the \<node\> tag. | - |
363 | */ | - |
364 | QDBusIntrospection::Interfaces | - |
365 | QDBusIntrospection::parseInterfaces(const QString &xml) | - |
366 | { | - |
367 | QString null; executed (the execution status of this line is deduced): QString null; | - |
368 | QDBusXmlParser parser(null, null, xml); executed (the execution status of this line is deduced): QDBusXmlParser parser(null, null, xml); | - |
369 | return parser.interfaces(); executed: return parser.interfaces(); Execution Count:219 | 219 |
370 | } | - |
371 | | - |
372 | /*! | - |
373 | Parses the XML document fragment (given by \a xml) containing one object, found at the service | - |
374 | \a service and path \a path. | - |
375 | | - |
376 | The first element tag in this document must be \<node\>. If that tag does not contain | - |
377 | a name attribute, the \a path argument will be used to determine the path of this | - |
378 | object node. | - |
379 | | - |
380 | This function does not parse the interfaces contained in the node, nor sub-object's contents. | - |
381 | It will only list their names. | - |
382 | */ | - |
383 | QDBusIntrospection::Object | - |
384 | QDBusIntrospection::parseObject(const QString &xml, const QString &service, const QString &path) | - |
385 | { | - |
386 | QDBusXmlParser parser(service, path, xml); executed (the execution status of this line is deduced): QDBusXmlParser parser(service, path, xml); | - |
387 | QSharedDataPointer<QDBusIntrospection::Object> retval = parser.object(); executed (the execution status of this line is deduced): QSharedDataPointer<QDBusIntrospection::Object> retval = parser.object(); | - |
388 | if (!retval) partially evaluated: !retval no Evaluation Count:0 | yes Evaluation Count:26 |
| 0-26 |
389 | return QDBusIntrospection::Object(); never executed: return QDBusIntrospection::Object(); | 0 |
390 | return *retval; executed: return *retval; Execution Count:26 | 26 |
391 | } | - |
392 | | - |
393 | QT_END_NAMESPACE | - |
394 | | - |
395 | #endif // QT_NO_DBUS | - |
396 | | - |
| | |