| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusinterface.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 "qdbusinterface.h" | - | ||||||||||||
| 35 | #include "qdbusinterface_p.h" | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | #include "qdbus_symbols_p.h" | - | ||||||||||||
| 38 | #include <QtCore/qpointer.h> | - | ||||||||||||
| 39 | #include <QtCore/qstringlist.h> | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include "qdbusmetatype_p.h" | - | ||||||||||||
| 42 | #include "qdbusconnection_p.h" | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | #ifndef QT_NO_DBUS | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | static void copyArgument(void *to, int id, const QVariant &arg) | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | if (id == arg.userType()) {
| 4-12 | ||||||||||||
| 51 | switch (id) { | - | ||||||||||||
| 52 | case QVariant::Bool: never executed: case QVariant::Bool: | 0 | ||||||||||||
| 53 | *reinterpret_cast<bool *>(to) = arg.toBool(); | - | ||||||||||||
| 54 | return; never executed: return; | 0 | ||||||||||||
| 55 | - | |||||||||||||
| 56 | case QMetaType::UChar: never executed: case QMetaType::UChar: | 0 | ||||||||||||
| 57 | *reinterpret_cast<uchar *>(to) = arg.value<uchar>(); | - | ||||||||||||
| 58 | return; never executed: return; | 0 | ||||||||||||
| 59 | - | |||||||||||||
| 60 | case QMetaType::Short: never executed: case QMetaType::Short: | 0 | ||||||||||||
| 61 | *reinterpret_cast<short *>(to) = arg.value<short>(); | - | ||||||||||||
| 62 | return; never executed: return; | 0 | ||||||||||||
| 63 | - | |||||||||||||
| 64 | case QMetaType::UShort: never executed: case QMetaType::UShort: | 0 | ||||||||||||
| 65 | *reinterpret_cast<ushort *>(to) = arg.value<ushort>(); | - | ||||||||||||
| 66 | return; never executed: return; | 0 | ||||||||||||
| 67 | - | |||||||||||||
| 68 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||
| 69 | *reinterpret_cast<int *>(to) = arg.toInt(); | - | ||||||||||||
| 70 | return; never executed: return; | 0 | ||||||||||||
| 71 | - | |||||||||||||
| 72 | case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||||||||
| 73 | *reinterpret_cast<uint *>(to) = arg.toUInt(); | - | ||||||||||||
| 74 | return; never executed: return; | 0 | ||||||||||||
| 75 | - | |||||||||||||
| 76 | case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||
| 77 | *reinterpret_cast<qlonglong *>(to) = arg.toLongLong(); | - | ||||||||||||
| 78 | return; never executed: return; | 0 | ||||||||||||
| 79 | - | |||||||||||||
| 80 | case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||
| 81 | *reinterpret_cast<qulonglong *>(to) = arg.toULongLong(); | - | ||||||||||||
| 82 | return; never executed: return; | 0 | ||||||||||||
| 83 | - | |||||||||||||
| 84 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||
| 85 | *reinterpret_cast<double *>(to) = arg.toDouble(); | - | ||||||||||||
| 86 | return; never executed: return; | 0 | ||||||||||||
| 87 | - | |||||||||||||
| 88 | case QVariant::String: never executed: case QVariant::String: | 0 | ||||||||||||
| 89 | *reinterpret_cast<QString *>(to) = arg.toString(); | - | ||||||||||||
| 90 | return; never executed: return; | 0 | ||||||||||||
| 91 | - | |||||||||||||
| 92 | case QVariant::ByteArray: never executed: case QVariant::ByteArray: | 0 | ||||||||||||
| 93 | *reinterpret_cast<QByteArray *>(to) = arg.toByteArray(); | - | ||||||||||||
| 94 | return; never executed: return; | 0 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | case QVariant::StringList: never executed: case QVariant::StringList: | 0 | ||||||||||||
| 97 | *reinterpret_cast<QStringList *>(to) = arg.toStringList(); | - | ||||||||||||
| 98 | return; never executed: return; | 0 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | if (id == QDBusMetaTypeId::variant()) {
| 0-12 | ||||||||||||
| 102 | *reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>(); | - | ||||||||||||
| 103 | return; executed 12 times by 1 test: return;Executed by:
| 12 | ||||||||||||
| 104 | } else if (id == QDBusMetaTypeId::objectpath()) {
| 0 | ||||||||||||
| 105 | *reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>(); | - | ||||||||||||
| 106 | return; never executed: return; | 0 | ||||||||||||
| 107 | } else if (id == QDBusMetaTypeId::signature()) {
| 0 | ||||||||||||
| 108 | *reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>(); | - | ||||||||||||
| 109 | return; never executed: return; | 0 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | // those above are the only types possible | - | ||||||||||||
| 113 | // the demarshaller code doesn't demarshall anything else | - | ||||||||||||
| 114 | qFatal("Found a decoded basic type in a D-Bus reply that shouldn't be there"); | - | ||||||||||||
| 115 | } never executed: end of block | 0 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | // if we got here, it's either an un-dermarshalled type or a mismatch | - | ||||||||||||
| 118 | if (arg.userType() != QDBusMetaTypeId::argument()) {
| 0-4 | ||||||||||||
| 119 | // it's a mismatch | - | ||||||||||||
| 120 | //qWarning? | - | ||||||||||||
| 121 | return; never executed: return; | 0 | ||||||||||||
| 122 | } | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | // is this type registered? | - | ||||||||||||
| 125 | const char *userSignature = QDBusMetaType::typeToSignature(id); | - | ||||||||||||
| 126 | if (!userSignature || !*userSignature) {
| 0-4 | ||||||||||||
| 127 | // type not registered | - | ||||||||||||
| 128 | //qWarning? | - | ||||||||||||
| 129 | return; never executed: return; | 0 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | // is it the same signature? | - | ||||||||||||
| 133 | QDBusArgument dbarg = arg.value<QDBusArgument>(); | - | ||||||||||||
| 134 | if (dbarg.currentSignature() != QLatin1String(userSignature)) {
| 0-4 | ||||||||||||
| 135 | // not the same signature, another mismatch | - | ||||||||||||
| 136 | //qWarning? | - | ||||||||||||
| 137 | return; never executed: return; | 0 | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | // we can demarshall | - | ||||||||||||
| 141 | QDBusMetaType::demarshall(dbarg, id, to); | - | ||||||||||||
| 142 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | QDBusInterfacePrivate::QDBusInterfacePrivate(const QString &serv, const QString &p, | - | ||||||||||||
| 145 | const QString &iface, const QDBusConnection &con) | - | ||||||||||||
| 146 | : QDBusAbstractInterfacePrivate(serv, p, iface, con, true), metaObject(0) | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | // QDBusAbstractInterfacePrivate's constructor checked the parameters for us | - | ||||||||||||
| 149 | if (connection.isConnected()) {
| 4-131 | ||||||||||||
| 150 | metaObject = connectionPrivate()->findMetaObject(service, path, interface, lastError); | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | if (!metaObject) {
| 41-90 | ||||||||||||
| 153 | // creation failed, somehow | - | ||||||||||||
| 154 | // most common causes are that the service doesn't exist or doesn't support introspection | - | ||||||||||||
| 155 | // those are not fatal errors, so we continue working | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | if (!lastError.isValid())
| 0-41 | ||||||||||||
| 158 | lastError = QDBusError(QDBusError::InternalError, QLatin1String("Unknown error")); never executed: lastError = QDBusError(QDBusError::InternalError, QLatin1String("Unknown error")); | 0 | ||||||||||||
| 159 | } executed 41 times by 3 tests: end of blockExecuted by:
| 41 | ||||||||||||
| 160 | } executed 131 times by 12 tests: end of blockExecuted by:
| 131 | ||||||||||||
| 161 | } executed 135 times by 12 tests: end of blockExecuted by:
| 135 | ||||||||||||
| 162 | - | |||||||||||||
| 163 | QDBusInterfacePrivate::~QDBusInterfacePrivate() | - | ||||||||||||
| 164 | { | - | ||||||||||||
| 165 | if (metaObject && !metaObject->cached)
| 42-90 | ||||||||||||
| 166 | delete metaObject; executed 42 times by 7 tests: delete metaObject;Executed by:
| 42 | ||||||||||||
| 167 | } executed 135 times by 12 tests: end of blockExecuted by:
| 135 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | - | |||||||||||||
| 170 | /*! | - | ||||||||||||
| 171 | \class QDBusInterface | - | ||||||||||||
| 172 | \inmodule QtDBus | - | ||||||||||||
| 173 | \since 4.2 | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | \brief The QDBusInterface class is a proxy for interfaces on remote objects. | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | QDBusInterface is a generic accessor class that is used to place calls to remote objects, | - | ||||||||||||
| 178 | connect to signals exported by remote objects and get/set the value of remote properties. This | - | ||||||||||||
| 179 | class is useful for dynamic access to remote objects: that is, when you do not have a generated | - | ||||||||||||
| 180 | code that represents the remote interface. | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | Calls are usually placed by using the call() function, which constructs the message, sends it | - | ||||||||||||
| 183 | over the bus, waits for the reply and decodes the reply. Signals are connected to by using the | - | ||||||||||||
| 184 | normal QObject::connect() function. Finally, properties are accessed using the | - | ||||||||||||
| 185 | QObject::property() and QObject::setProperty() functions. | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | The following code snippet demonstrates how to perform a | - | ||||||||||||
| 188 | mathematical operation of \tt{"2 + 2"} in a remote application | - | ||||||||||||
| 189 | called \c com.example.Calculator, accessed via the session bus. | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | \snippet code/src_qdbus_qdbusinterface.cpp 0 | - | ||||||||||||
| 192 | - | |||||||||||||
| 193 | \sa {Qt D-Bus XML compiler (qdbusxml2cpp)} | - | ||||||||||||
| 194 | */ | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | /*! | - | ||||||||||||
| 197 | Creates a dynamic QDBusInterface object associated with the | - | ||||||||||||
| 198 | interface \a interface on object at path \a path on service \a | - | ||||||||||||
| 199 | service, using the given \a connection. If \a interface is an | - | ||||||||||||
| 200 | empty string, the object created will refer to the merging of all | - | ||||||||||||
| 201 | interfaces found in that object. | - | ||||||||||||
| 202 | - | |||||||||||||
| 203 | \a parent is passed to the base class constructor. | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | If the remote service \a service is not present or if an error | - | ||||||||||||
| 206 | occurs trying to obtain the description of the remote interface | - | ||||||||||||
| 207 | \a interface, the object created will not be valid (see | - | ||||||||||||
| 208 | isValid()). | - | ||||||||||||
| 209 | */ | - | ||||||||||||
| 210 | QDBusInterface::QDBusInterface(const QString &service, const QString &path, const QString &interface, | - | ||||||||||||
| 211 | const QDBusConnection &connection, QObject *parent) | - | ||||||||||||
| 212 | : QDBusAbstractInterface(*new QDBusInterfacePrivate(service, path, interface, connection), | - | ||||||||||||
| 213 | parent) | - | ||||||||||||
| 214 | { | - | ||||||||||||
| 215 | } executed 135 times by 12 tests: end of blockExecuted by:
| 135 | ||||||||||||
| 216 | - | |||||||||||||
| 217 | /*! | - | ||||||||||||
| 218 | Destroy the object interface and frees up any resource used. | - | ||||||||||||
| 219 | */ | - | ||||||||||||
| 220 | QDBusInterface::~QDBusInterface() | - | ||||||||||||
| 221 | { | - | ||||||||||||
| 222 | // resources are freed in QDBusInterfacePrivate::~QDBusInterfacePrivate() | - | ||||||||||||
| 223 | } | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | /*! | - | ||||||||||||
| 226 | \internal | - | ||||||||||||
| 227 | Overrides QObject::metaObject to return our own copy. | - | ||||||||||||
| 228 | */ | - | ||||||||||||
| 229 | const QMetaObject *QDBusInterface::metaObject() const | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 | return d_func()->metaObject ? d_func()->metaObject : &QDBusAbstractInterface::staticMetaObject; | - | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | /*! | - | ||||||||||||
| 235 | \internal | - | ||||||||||||
| 236 | Override QObject::qt_metacast to catch the interface name too. | - | ||||||||||||
| 237 | */ | - | ||||||||||||
| 238 | void *QDBusInterface::qt_metacast(const char *_clname) | - | ||||||||||||
| 239 | { | - | ||||||||||||
| 240 | if (!_clname) return 0; | - | ||||||||||||
| 241 | if (!strcmp(_clname, "QDBusInterface")) | - | ||||||||||||
| 242 | return static_cast<void*>(const_cast<QDBusInterface*>(this)); | - | ||||||||||||
| 243 | if (d_func()->interface.toLatin1() == _clname) | - | ||||||||||||
| 244 | return static_cast<void*>(const_cast<QDBusInterface*>(this)); | - | ||||||||||||
| 245 | return QDBusAbstractInterface::qt_metacast(_clname); | - | ||||||||||||
| 246 | } | - | ||||||||||||
| 247 | - | |||||||||||||
| 248 | /*! | - | ||||||||||||
| 249 | \internal | - | ||||||||||||
| 250 | Dispatch the call through the private. | - | ||||||||||||
| 251 | */ | - | ||||||||||||
| 252 | int QDBusInterface::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||
| 253 | { | - | ||||||||||||
| 254 | _id = QDBusAbstractInterface::qt_metacall(_c, _id, _a); | - | ||||||||||||
| 255 | if (_id < 0 || !d_func()->isValid || !d_func()->metaObject) | - | ||||||||||||
| 256 | return _id; | - | ||||||||||||
| 257 | return d_func()->metacall(_c, _id, _a); | - | ||||||||||||
| 258 | } | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv) | - | ||||||||||||
| 261 | { | - | ||||||||||||
| 262 | Q_Q(QDBusInterface); | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | if (c == QMetaObject::InvokeMetaMethod) {
| 0-28 | ||||||||||||
| 265 | int offset = metaObject->methodOffset(); | - | ||||||||||||
| 266 | QMetaMethod mm = metaObject->method(id + offset); | - | ||||||||||||
| 267 | - | |||||||||||||
| 268 | if (mm.methodType() == QMetaMethod::Signal) {
| 12-16 | ||||||||||||
| 269 | // signal relay from D-Bus world to Qt world | - | ||||||||||||
| 270 | QMetaObject::activate(q, metaObject, id, argv); | - | ||||||||||||
| 271 | - | |||||||||||||
| 272 | } else if (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method) { executed 12 times by 2 tests: end of blockExecuted by:
| 0-16 | ||||||||||||
| 273 | // method call relay from Qt world to D-Bus world | - | ||||||||||||
| 274 | // get D-Bus equivalent signature | - | ||||||||||||
| 275 | QString methodName = QString::fromLatin1(mm.name()); | - | ||||||||||||
| 276 | const int *inputTypes = metaObject->inputTypesForMethod(id); | - | ||||||||||||
| 277 | int inputTypesCount = *inputTypes; | - | ||||||||||||
| 278 | - | |||||||||||||
| 279 | // we will assume that the input arguments were passed correctly | - | ||||||||||||
| 280 | QVariantList args; | - | ||||||||||||
| 281 | args.reserve(inputTypesCount); | - | ||||||||||||
| 282 | int i = 1; | - | ||||||||||||
| 283 | for ( ; i <= inputTypesCount; ++i)
| 16-20 | ||||||||||||
| 284 | args << QVariant(inputTypes[i], argv[i]); executed 20 times by 1 test: args << QVariant(inputTypes[i], argv[i]);Executed by:
| 20 | ||||||||||||
| 285 | - | |||||||||||||
| 286 | // make the call | - | ||||||||||||
| 287 | QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args); | - | ||||||||||||
| 288 | - | |||||||||||||
| 289 | if (reply.type() == QDBusMessage::ReplyMessage) {
| 0-16 | ||||||||||||
| 290 | // attempt to demarshall the return values | - | ||||||||||||
| 291 | args = reply.arguments(); | - | ||||||||||||
| 292 | QVariantList::ConstIterator it = args.constBegin(); | - | ||||||||||||
| 293 | const int *outputTypes = metaObject->outputTypesForMethod(id); | - | ||||||||||||
| 294 | int outputTypesCount = *outputTypes++; | - | ||||||||||||
| 295 | - | |||||||||||||
| 296 | if (mm.returnType() != QMetaType::UnknownType && mm.returnType() != QMetaType::Void) {
| 0-16 | ||||||||||||
| 297 | // this method has a return type | - | ||||||||||||
| 298 | if (argv[0] && it != args.constEnd())
| 0-12 | ||||||||||||
| 299 | copyArgument(argv[0], *outputTypes++, *it); executed 12 times by 1 test: copyArgument(argv[0], *outputTypes++, *it);Executed by:
| 12 | ||||||||||||
| 300 | - | |||||||||||||
| 301 | // skip this argument even if we didn't copy it | - | ||||||||||||
| 302 | --outputTypesCount; | - | ||||||||||||
| 303 | ++it; | - | ||||||||||||
| 304 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||
| 305 | - | |||||||||||||
| 306 | for (int j = 0; j < outputTypesCount && it != args.constEnd(); ++i, ++j, ++it) {
| 0-16 | ||||||||||||
| 307 | copyArgument(argv[i], outputTypes[j], *it); | - | ||||||||||||
| 308 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 309 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||
| 310 | - | |||||||||||||
| 311 | // done | - | ||||||||||||
| 312 | lastError = QDBusError(reply); | - | ||||||||||||
| 313 | return -1; executed 16 times by 1 test: return -1;Executed by:
| 16 | ||||||||||||
| 314 | } | - | ||||||||||||
| 315 | } executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||
| 316 | return id; executed 12 times by 2 tests: return id;Executed by:
| 12 | ||||||||||||
| 317 | } | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | QT_END_NAMESPACE | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | #endif // QT_NO_DBUS | - | ||||||||||||
| Source code | Switch to Preprocessed file |