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