| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusabstractinterface.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||
| 7 | ** This file is part of the QtDBus module of the Qt Toolkit. | - | ||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 36 | ** | - | ||||||||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 38 | ** | - | ||||||||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | #include "qdbusabstractinterface.h" | - | ||||||||||||||||||
| 42 | #include "qdbusabstractinterface_p.h" | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | #include <qcoreapplication.h> | - | ||||||||||||||||||
| 45 | #include <qthread.h> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | #include "qdbusargument.h" | - | ||||||||||||||||||
| 48 | #include "qdbuspendingcall.h" | - | ||||||||||||||||||
| 49 | #include "qdbusmessage_p.h" | - | ||||||||||||||||||
| 50 | #include "qdbusmetaobject_p.h" | - | ||||||||||||||||||
| 51 | #include "qdbusmetatype_p.h" | - | ||||||||||||||||||
| 52 | #include "qdbusservicewatcher.h" | - | ||||||||||||||||||
| 53 | #include "qdbusutil_p.h" | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | #include <qdebug.h> | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | #ifndef QT_NO_DBUS | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | namespace { | - | ||||||||||||||||||
| 62 | // ### Qt6: change to a regular QEvent (customEvent) | - | ||||||||||||||||||
| 63 | // We need to use a QMetaCallEvent here because we can't override customEvent() in | - | ||||||||||||||||||
| 64 | // Qt 5. Since QDBusAbstractInterface is meant to be derived from, the vtables of | - | ||||||||||||||||||
| 65 | // classes in generated code will have a pointer to QObject::customEvent instead | - | ||||||||||||||||||
| 66 | // of to QDBusAbstractInterface::customEvent. | - | ||||||||||||||||||
| 67 | // See solution in Patch Set 1 of this change in the Qt Gerrit servers. | - | ||||||||||||||||||
| 68 | // (https://codereview.qt-project.org/#/c/126384/1) | - | ||||||||||||||||||
| 69 | class DisconnectRelayEvent : public QMetaCallEvent | - | ||||||||||||||||||
| 70 | { | - | ||||||||||||||||||
| 71 | public: | - | ||||||||||||||||||
| 72 | DisconnectRelayEvent(QObject *sender, const QMetaMethod &m) | - | ||||||||||||||||||
| 73 | : QMetaCallEvent(0, 0, Q_NULLPTR, sender, m.methodIndex()) | - | ||||||||||||||||||
| 74 | {} executed 102 times by 21 tests: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | void placeMetaCall(QObject *object) Q_DECL_OVERRIDE | - | ||||||||||||||||||
| 77 | { | - | ||||||||||||||||||
| 78 | QDBusAbstractInterface *iface = static_cast<QDBusAbstractInterface *>(object); | - | ||||||||||||||||||
| 79 | QDBusAbstractInterfacePrivate::finishDisconnectNotify(iface, signalId()); | - | ||||||||||||||||||
| 80 | } executed 15 times by 2 tests: end of blockExecuted by:
| 15 | ||||||||||||||||||
| 81 | }; | - | ||||||||||||||||||
| 82 | } | - | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | static QDBusError checkIfValid(const QString &service, const QString &path, | - | ||||||||||||||||||
| 85 | const QString &interface, bool isDynamic, bool isPeer) | - | ||||||||||||||||||
| 86 | { | - | ||||||||||||||||||
| 87 | // We should be throwing exceptions here... oh well | - | ||||||||||||||||||
| 88 | QDBusError error; | - | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | // dynamic interfaces (QDBusInterface) can have empty interfaces, but not service and object paths | - | ||||||||||||||||||
| 91 | // non-dynamic is the opposite: service and object paths can be empty, but not the interface | - | ||||||||||||||||||
| 92 | if (!isDynamic) {
| 135-914 | ||||||||||||||||||
| 93 | // use assertion here because this should never happen, at all | - | ||||||||||||||||||
| 94 | Q_ASSERT_X(!interface.isEmpty(), "QDBusAbstractInterface", "Interface name cannot be empty"); | - | ||||||||||||||||||
| 95 | } executed 914 times by 160 tests: end of blockExecuted by:
| 914 | ||||||||||||||||||
| 96 | if (!QDBusUtil::checkBusName(service, (isDynamic && !isPeer) ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
| 7-1042 | ||||||||||||||||||
| 97 | return error; executed 7 times by 1 test: return error;Executed by:
| 7 | ||||||||||||||||||
| 98 | if (!QDBusUtil::checkObjectPath(path, isDynamic ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
| 15-1027 | ||||||||||||||||||
| 99 | return error; executed 15 times by 2 tests: return error;Executed by:
| 15 | ||||||||||||||||||
| 100 | if (!QDBusUtil::checkInterfaceName(interface, QDBusUtil::EmptyAllowed, &error))
| 0-1027 | ||||||||||||||||||
| 101 | return error; never executed: return error; | 0 | ||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | // no error | - | ||||||||||||||||||
| 104 | return QDBusError(); executed 1027 times by 160 tests: return QDBusError();Executed by:
| 1027 | ||||||||||||||||||
| 105 | } | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv, | - | ||||||||||||||||||
| 108 | const QString &p, | - | ||||||||||||||||||
| 109 | const QString &iface, | - | ||||||||||||||||||
| 110 | const QDBusConnection& con, | - | ||||||||||||||||||
| 111 | bool isDynamic) | - | ||||||||||||||||||
| 112 | : connection(con), service(serv), path(p), interface(iface), | - | ||||||||||||||||||
| 113 | lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() && | - | ||||||||||||||||||
| 114 | connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))), | - | ||||||||||||||||||
| 115 | timeout(-1), | - | ||||||||||||||||||
| 116 | isValid(!lastError.isValid()) | - | ||||||||||||||||||
| 117 | { | - | ||||||||||||||||||
| 118 | if (!isValid)
| 22-1027 | ||||||||||||||||||
| 119 | return; executed 22 times by 2 tests: return;Executed by:
| 22 | ||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | if (!connection.isConnected()) {
| 8-1019 | ||||||||||||||||||
| 122 | lastError = QDBusError(QDBusError::Disconnected, | - | ||||||||||||||||||
| 123 | QDBusUtil::disconnectedErrorMessage()); | - | ||||||||||||||||||
| 124 | } else if (!service.isEmpty()) { executed 8 times by 8 tests: end of blockExecuted by:
| 8-914 | ||||||||||||||||||
| 125 | currentOwner = connectionPrivate()->getNameOwner(service); // verify the name owner | - | ||||||||||||||||||
| 126 | if (currentOwner.isEmpty()) {
| 41-873 | ||||||||||||||||||
| 127 | lastError = connectionPrivate()->lastError; | - | ||||||||||||||||||
| 128 | } executed 41 times by 19 tests: end of blockExecuted by:
| 41 | ||||||||||||||||||
| 129 | } executed 914 times by 158 tests: end of blockExecuted by:
| 914 | ||||||||||||||||||
| 130 | } executed 1027 times by 160 tests: end of blockExecuted by:
| 1027 | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | void QDBusAbstractInterfacePrivate::initOwnerTracking() | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | if (!isValid || !connection.isConnected() || !connectionPrivate()->shouldWatchService(service))
| 8-1027 | ||||||||||||||||||
| 135 | return; executed 457 times by 160 tests: return;Executed by:
| 457 | ||||||||||||||||||
| 136 | QObject::connect(new QDBusServiceWatcher(service, connection, QDBusServiceWatcher::WatchForOwnerChange, q_func()), | - | ||||||||||||||||||
| 137 | SIGNAL(serviceOwnerChanged(QString,QString,QString)), | - | ||||||||||||||||||
| 138 | q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString))); | - | ||||||||||||||||||
| 139 | } executed 592 times by 154 tests: end of blockExecuted by:
| 592 | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | bool QDBusAbstractInterfacePrivate::canMakeCalls() const | - | ||||||||||||||||||
| 142 | { | - | ||||||||||||||||||
| 143 | // recheck only if we have a wildcard (i.e. empty) service or path | - | ||||||||||||||||||
| 144 | // if any are empty, set the error message according to QDBusUtil | - | ||||||||||||||||||
| 145 | if (service.isEmpty() && connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
| 12-916 | ||||||||||||||||||
| 146 | return QDBusUtil::checkBusName(service, QDBusUtil::EmptyNotAllowed, &lastError); executed 12 times by 1 test: return QDBusUtil::checkBusName(service, QDBusUtil::EmptyNotAllowed, &lastError);Executed by:
| 12 | ||||||||||||||||||
| 147 | if (path.isEmpty())
| 12-1006 | ||||||||||||||||||
| 148 | return QDBusUtil::checkObjectPath(path, QDBusUtil::EmptyNotAllowed, &lastError); executed 12 times by 1 test: return QDBusUtil::checkObjectPath(path, QDBusUtil::EmptyNotAllowed, &lastError);Executed by:
| 12 | ||||||||||||||||||
| 149 | return true; executed 1006 times by 157 tests: return true;Executed by:
| 1006 | ||||||||||||||||||
| 150 | } | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *returnValuePtr) const | - | ||||||||||||||||||
| 153 | { | - | ||||||||||||||||||
| 154 | if (!isValid || !canMakeCalls()) // can't make calls
| 6-204 | ||||||||||||||||||
| 155 | return false; executed 14 times by 1 test: return false;Executed by:
| 14 | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | const int type = mp.userType(); | - | ||||||||||||||||||
| 158 | // is this metatype registered? | - | ||||||||||||||||||
| 159 | const char *expectedSignature = ""; | - | ||||||||||||||||||
| 160 | if (int(mp.type()) != QMetaType::QVariant) {
| 0-196 | ||||||||||||||||||
| 161 | expectedSignature = QDBusMetaType::typeToSignature(type); | - | ||||||||||||||||||
| 162 | if (expectedSignature == 0) {
| 0-196 | ||||||||||||||||||
| 163 | qWarning("QDBusAbstractInterface: type %s must be registered with Qt D-Bus before it can be " | - | ||||||||||||||||||
| 164 | "used to read property %s.%s", | - | ||||||||||||||||||
| 165 | mp.typeName(), qPrintable(interface), mp.name()); | - | ||||||||||||||||||
| 166 | lastError = QDBusError(QDBusError::Failed, | - | ||||||||||||||||||
| 167 | QString::fromLatin1("Unregistered type %1 cannot be handled") | - | ||||||||||||||||||
| 168 | .arg(QLatin1String(mp.typeName()))); | - | ||||||||||||||||||
| 169 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 170 | } | - | ||||||||||||||||||
| 171 | } executed 196 times by 130 tests: end of blockExecuted by:
| 196 | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | // try to read this property | - | ||||||||||||||||||
| 174 | QDBusMessage msg = QDBusMessage::createMethodCall(service, path, | - | ||||||||||||||||||
| 175 | QDBusUtil::dbusInterfaceProperties(), | - | ||||||||||||||||||
| 176 | QStringLiteral("Get")); executed 196 times by 130 tests: return qstring_literal_temp;Executed by:
| 196 | ||||||||||||||||||
| 177 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
| 178 | msg << interface << QString::fromUtf8(mp.name()); | - | ||||||||||||||||||
| 179 | QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | if (reply.type() != QDBusMessage::ReplyMessage) {
| 0-196 | ||||||||||||||||||
| 182 | lastError = QDBusError(reply); | - | ||||||||||||||||||
| 183 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | if (reply.signature() != QLatin1String("v")) {
| 0-196 | ||||||||||||||||||
| 186 | QString errmsg = QLatin1String("Invalid signature `%1' in return from call to " | - | ||||||||||||||||||
| 187 | DBUS_INTERFACE_PROPERTIES); | - | ||||||||||||||||||
| 188 | lastError = QDBusError(QDBusError::InvalidSignature, qMove(errmsg).arg(reply.signature())); | - | ||||||||||||||||||
| 189 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 190 | } | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | QByteArray foundSignature; | - | ||||||||||||||||||
| 193 | const char *foundType = 0; | - | ||||||||||||||||||
| 194 | QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant(); | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | if (value.userType() == type || type == QMetaType::QVariant
| 0-190 | ||||||||||||||||||
| 197 | || (expectedSignature[0] == 'v' && expectedSignature[1] == '\0')) {
| 0-6 | ||||||||||||||||||
| 198 | // simple match | - | ||||||||||||||||||
| 199 | if (type == QMetaType::QVariant) {
| 0-190 | ||||||||||||||||||
| 200 | *reinterpret_cast<QVariant*>(returnValuePtr) = value; | - | ||||||||||||||||||
| 201 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 202 | QMetaType::destruct(type, returnValuePtr); | - | ||||||||||||||||||
| 203 | QMetaType::construct(type, returnValuePtr, value.constData()); | - | ||||||||||||||||||
| 204 | } executed 190 times by 130 tests: end of blockExecuted by:
| 190 | ||||||||||||||||||
| 205 | return true; executed 190 times by 130 tests: return true;Executed by:
| 190 | ||||||||||||||||||
| 206 | } | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | if (value.userType() == qMetaTypeId<QDBusArgument>()) {
| 0-6 | ||||||||||||||||||
| 209 | QDBusArgument arg = qvariant_cast<QDBusArgument>(value); | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | foundType = "user type"; | - | ||||||||||||||||||
| 212 | foundSignature = arg.currentSignature().toLatin1(); | - | ||||||||||||||||||
| 213 | if (foundSignature == expectedSignature) {
| 0-6 | ||||||||||||||||||
| 214 | // signatures match, we can demarshall | - | ||||||||||||||||||
| 215 | return QDBusMetaType::demarshall(arg, type, returnValuePtr); executed 6 times by 2 tests: return QDBusMetaType::demarshall(arg, type, returnValuePtr);Executed by:
| 6 | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 218 | foundType = value.typeName(); | - | ||||||||||||||||||
| 219 | foundSignature = QDBusMetaType::typeToSignature(value.userType()); | - | ||||||||||||||||||
| 220 | } never executed: end of block | 0 | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | // there was an error... | - | ||||||||||||||||||
| 223 | QString errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' " | - | ||||||||||||||||||
| 224 | "(expected type `%5' (%6))"); | - | ||||||||||||||||||
| 225 | lastError = QDBusError(QDBusError::InvalidSignature, | - | ||||||||||||||||||
| 226 | errmsg.arg(QString::fromLatin1(foundType), | - | ||||||||||||||||||
| 227 | QString::fromLatin1(foundSignature), | - | ||||||||||||||||||
| 228 | interface, | - | ||||||||||||||||||
| 229 | QString::fromUtf8(mp.name()), | - | ||||||||||||||||||
| 230 | QString::fromLatin1(mp.typeName()), | - | ||||||||||||||||||
| 231 | QString::fromLatin1(expectedSignature))); | - | ||||||||||||||||||
| 232 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 233 | } | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | bool QDBusAbstractInterfacePrivate::setProperty(const QMetaProperty &mp, const QVariant &value) | - | ||||||||||||||||||
| 236 | { | - | ||||||||||||||||||
| 237 | if (!isValid || !canMakeCalls()) // can't make calls
| 6-24 | ||||||||||||||||||
| 238 | return false; executed 14 times by 1 test: return false;Executed by:
| 14 | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | // send the value | - | ||||||||||||||||||
| 241 | QDBusMessage msg = QDBusMessage::createMethodCall(service, path, | - | ||||||||||||||||||
| 242 | QDBusUtil::dbusInterfaceProperties(), | - | ||||||||||||||||||
| 243 | QStringLiteral("Set")); executed 16 times by 2 tests: return qstring_literal_temp;Executed by:
| 16 | ||||||||||||||||||
| 244 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
| 245 | msg << interface << QString::fromUtf8(mp.name()) << QVariant::fromValue(QDBusVariant(value)); | - | ||||||||||||||||||
| 246 | QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); | - | ||||||||||||||||||
| 247 | - | |||||||||||||||||||
| 248 | if (reply.type() != QDBusMessage::ReplyMessage) {
| 0-16 | ||||||||||||||||||
| 249 | lastError = QDBusError(reply); | - | ||||||||||||||||||
| 250 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 251 | } | - | ||||||||||||||||||
| 252 | return true; executed 16 times by 2 tests: return true;Executed by:
| 16 | ||||||||||||||||||
| 253 | } | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | void QDBusAbstractInterfacePrivate::_q_serviceOwnerChanged(const QString &name, | - | ||||||||||||||||||
| 256 | const QString &oldOwner, | - | ||||||||||||||||||
| 257 | const QString &newOwner) | - | ||||||||||||||||||
| 258 | { | - | ||||||||||||||||||
| 259 | Q_UNUSED(oldOwner); | - | ||||||||||||||||||
| 260 | Q_UNUSED(name); | - | ||||||||||||||||||
| 261 | //qDebug() << "QDBusAbstractInterfacePrivate serviceOwnerChanged" << name << oldOwner << newOwner; | - | ||||||||||||||||||
| 262 | Q_ASSERT(name == service); | - | ||||||||||||||||||
| 263 | currentOwner = newOwner; | - | ||||||||||||||||||
| 264 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | QDBusAbstractInterfaceBase::QDBusAbstractInterfaceBase(QDBusAbstractInterfacePrivate &d, QObject *parent) | - | ||||||||||||||||||
| 267 | : QObject(d, parent) | - | ||||||||||||||||||
| 268 | { | - | ||||||||||||||||||
| 269 | } executed 1049 times by 160 tests: end of blockExecuted by:
| 1049 | ||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | int QDBusAbstractInterfaceBase::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | - | ||||||||||||||||||
| 272 | { | - | ||||||||||||||||||
| 273 | int saved_id = _id; | - | ||||||||||||||||||
| 274 | _id = QObject::qt_metacall(_c, _id, _a); | - | ||||||||||||||||||
| 275 | if (_id < 0) | - | ||||||||||||||||||
| 276 | return _id; | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty) { | - | ||||||||||||||||||
| 279 | QMetaProperty mp = metaObject()->property(saved_id); | - | ||||||||||||||||||
| 280 | int &status = *reinterpret_cast<int *>(_a[2]); | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | if (_c == QMetaObject::WriteProperty) { | - | ||||||||||||||||||
| 283 | QVariant value; | - | ||||||||||||||||||
| 284 | if (mp.userType() == qMetaTypeId<QDBusVariant>()) | - | ||||||||||||||||||
| 285 | value = reinterpret_cast<const QDBusVariant*>(_a[0])->variant(); | - | ||||||||||||||||||
| 286 | else | - | ||||||||||||||||||
| 287 | value = QVariant(mp.userType(), _a[0]); | - | ||||||||||||||||||
| 288 | status = d_func()->setProperty(mp, value) ? 1 : 0; | - | ||||||||||||||||||
| 289 | } else { | - | ||||||||||||||||||
| 290 | bool readStatus = d_func()->property(mp, _a[0]); | - | ||||||||||||||||||
| 291 | // Caller supports QVariant returns? Then we can also report errors | - | ||||||||||||||||||
| 292 | // by storing an invalid variant. | - | ||||||||||||||||||
| 293 | if (!readStatus && _a[1]) { | - | ||||||||||||||||||
| 294 | status = 0; | - | ||||||||||||||||||
| 295 | reinterpret_cast<QVariant*>(_a[1])->clear(); | - | ||||||||||||||||||
| 296 | } | - | ||||||||||||||||||
| 297 | } | - | ||||||||||||||||||
| 298 | _id = -1; | - | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | return _id; | - | ||||||||||||||||||
| 301 | } | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | /*! | - | ||||||||||||||||||
| 304 | \class QDBusAbstractInterface | - | ||||||||||||||||||
| 305 | \inmodule QtDBus | - | ||||||||||||||||||
| 306 | \since 4.2 | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | \brief The QDBusAbstractInterface class is the base class for all D-Bus interfaces in the Qt D-Bus binding, allowing access to remote interfaces | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | Generated-code classes also derive from QDBusAbstractInterface, | - | ||||||||||||||||||
| 311 | all methods described here are also valid for generated-code | - | ||||||||||||||||||
| 312 | classes. In addition to those described here, generated-code | - | ||||||||||||||||||
| 313 | classes provide member functions for the remote methods, which | - | ||||||||||||||||||
| 314 | allow for compile-time checking of the correct parameters and | - | ||||||||||||||||||
| 315 | return values, as well as property type-matching and signal | - | ||||||||||||||||||
| 316 | parameter-matching. | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | \sa {qdbusxml2cpp.html}{The QDBus compiler}, QDBusInterface | - | ||||||||||||||||||
| 319 | */ | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | /*! | - | ||||||||||||||||||
| 322 | \internal | - | ||||||||||||||||||
| 323 | This is the constructor called from QDBusInterface::QDBusInterface. | - | ||||||||||||||||||
| 324 | */ | - | ||||||||||||||||||
| 325 | QDBusAbstractInterface::QDBusAbstractInterface(QDBusAbstractInterfacePrivate &d, QObject *parent) | - | ||||||||||||||||||
| 326 | : QDBusAbstractInterfaceBase(d, parent) | - | ||||||||||||||||||
| 327 | { | - | ||||||||||||||||||
| 328 | d.initOwnerTracking(); | - | ||||||||||||||||||
| 329 | } executed 135 times by 12 tests: end of blockExecuted by:
| 135 | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | /*! | - | ||||||||||||||||||
| 332 | \internal | - | ||||||||||||||||||
| 333 | This is the constructor called from static classes derived from | - | ||||||||||||||||||
| 334 | QDBusAbstractInterface (i.e., those generated by dbusxml2cpp). | - | ||||||||||||||||||
| 335 | */ | - | ||||||||||||||||||
| 336 | QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QString &path, | - | ||||||||||||||||||
| 337 | const char *interface, const QDBusConnection &con, | - | ||||||||||||||||||
| 338 | QObject *parent) | - | ||||||||||||||||||
| 339 | : QDBusAbstractInterfaceBase(*new QDBusAbstractInterfacePrivate(service, path, QString::fromLatin1(interface), | - | ||||||||||||||||||
| 340 | con, false), parent) | - | ||||||||||||||||||
| 341 | { | - | ||||||||||||||||||
| 342 | // keep track of the service owner | - | ||||||||||||||||||
| 343 | d_func()->initOwnerTracking(); | - | ||||||||||||||||||
| 344 | } executed 914 times by 160 tests: end of blockExecuted by:
| 914 | ||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | /*! | - | ||||||||||||||||||
| 347 | Releases this object's resources. | - | ||||||||||||||||||
| 348 | */ | - | ||||||||||||||||||
| 349 | QDBusAbstractInterface::~QDBusAbstractInterface() | - | ||||||||||||||||||
| 350 | { | - | ||||||||||||||||||
| 351 | } | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | /*! | - | ||||||||||||||||||
| 354 | Returns \c true if this is a valid reference to a remote object. It returns \c false if | - | ||||||||||||||||||
| 355 | there was an error during the creation of this interface (for instance, if the remote | - | ||||||||||||||||||
| 356 | application does not exist). | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | Note: when dealing with remote objects, it is not always possible to determine if it | - | ||||||||||||||||||
| 359 | exists when creating a QDBusInterface. | - | ||||||||||||||||||
| 360 | */ | - | ||||||||||||||||||
| 361 | bool QDBusAbstractInterface::isValid() const | - | ||||||||||||||||||
| 362 | { | - | ||||||||||||||||||
| 363 | Q_D(const QDBusAbstractInterface); | - | ||||||||||||||||||
| 364 | /* We don't retrieve the owner name for peer connections */ | - | ||||||||||||||||||
| 365 | if (d->connectionPrivate() && d->connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode) {
| 4-243 | ||||||||||||||||||
| 366 | return d->isValid; executed 7 times by 1 test: return d->isValid;Executed by:
| 7 | ||||||||||||||||||
| 367 | } else { | - | ||||||||||||||||||
| 368 | return !d->currentOwner.isEmpty(); executed 240 times by 27 tests: return !d->currentOwner.isEmpty();Executed by:
| 240 | ||||||||||||||||||
| 369 | } | - | ||||||||||||||||||
| 370 | } | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | /*! | - | ||||||||||||||||||
| 373 | Returns the connection this interface is associated with. | - | ||||||||||||||||||
| 374 | */ | - | ||||||||||||||||||
| 375 | QDBusConnection QDBusAbstractInterface::connection() const | - | ||||||||||||||||||
| 376 | { | - | ||||||||||||||||||
| 377 | return d_func()->connection; executed 1 time by 1 test: return d_func()->connection;Executed by:
| 1 | ||||||||||||||||||
| 378 | } | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | /*! | - | ||||||||||||||||||
| 381 | Returns the name of the service this interface is associated with. | - | ||||||||||||||||||
| 382 | */ | - | ||||||||||||||||||
| 383 | QString QDBusAbstractInterface::service() const | - | ||||||||||||||||||
| 384 | { | - | ||||||||||||||||||
| 385 | return d_func()->service; executed 888 times by 175 tests: return d_func()->service;Executed by:
| 888 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | /*! | - | ||||||||||||||||||
| 389 | Returns the object path that this interface is associated with. | - | ||||||||||||||||||
| 390 | */ | - | ||||||||||||||||||
| 391 | QString QDBusAbstractInterface::path() const | - | ||||||||||||||||||
| 392 | { | - | ||||||||||||||||||
| 393 | return d_func()->path; executed 1050 times by 178 tests: return d_func()->path;Executed by:
| 1050 | ||||||||||||||||||
| 394 | } | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | /*! | - | ||||||||||||||||||
| 397 | Returns the name of this interface. | - | ||||||||||||||||||
| 398 | */ | - | ||||||||||||||||||
| 399 | QString QDBusAbstractInterface::interface() const | - | ||||||||||||||||||
| 400 | { | - | ||||||||||||||||||
| 401 | return d_func()->interface; executed 794 times by 157 tests: return d_func()->interface;Executed by:
| 794 | ||||||||||||||||||
| 402 | } | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | /*! | - | ||||||||||||||||||
| 405 | Returns the error the last operation produced, or an invalid error if the last operation did not | - | ||||||||||||||||||
| 406 | produce an error. | - | ||||||||||||||||||
| 407 | */ | - | ||||||||||||||||||
| 408 | QDBusError QDBusAbstractInterface::lastError() const | - | ||||||||||||||||||
| 409 | { | - | ||||||||||||||||||
| 410 | return d_func()->lastError; executed 49 times by 1 test: return d_func()->lastError;Executed by:
| 49 | ||||||||||||||||||
| 411 | } | - | ||||||||||||||||||
| 412 | - | |||||||||||||||||||
| 413 | /*! | - | ||||||||||||||||||
| 414 | Sets the timeout in milliseconds for all future DBus calls to \a timeout. | - | ||||||||||||||||||
| 415 | -1 means the default DBus timeout (usually 25 seconds). | - | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | \since 4.8 | - | ||||||||||||||||||
| 418 | */ | - | ||||||||||||||||||
| 419 | void QDBusAbstractInterface::setTimeout(int timeout) | - | ||||||||||||||||||
| 420 | { | - | ||||||||||||||||||
| 421 | d_func()->timeout = timeout; | - | ||||||||||||||||||
| 422 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 423 | - | |||||||||||||||||||
| 424 | /*! | - | ||||||||||||||||||
| 425 | Returns the current value of the timeout in milliseconds. | - | ||||||||||||||||||
| 426 | -1 means the default DBus timeout (usually 25 seconds). | - | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | \since 4.8 | - | ||||||||||||||||||
| 429 | */ | - | ||||||||||||||||||
| 430 | int QDBusAbstractInterface::timeout() const | - | ||||||||||||||||||
| 431 | { | - | ||||||||||||||||||
| 432 | return d_func()->timeout; never executed: return d_func()->timeout; | 0 | ||||||||||||||||||
| 433 | } | - | ||||||||||||||||||
| 434 | - | |||||||||||||||||||
| 435 | /*! | - | ||||||||||||||||||
| 436 | Places a call to the remote method specified by \a method on this interface, using \a args as | - | ||||||||||||||||||
| 437 | arguments. This function returns the message that was received as a reply, which can be a normal | - | ||||||||||||||||||
| 438 | QDBusMessage::ReplyMessage (indicating success) or QDBusMessage::ErrorMessage (if the call | - | ||||||||||||||||||
| 439 | failed). The \a mode parameter specifies how this call should be placed. | - | ||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | If the call succeeds, lastError() will be cleared; otherwise, it will contain the error this | - | ||||||||||||||||||
| 442 | call produced. | - | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | Normally, you should place calls using call(). | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | \warning If you use \c UseEventLoop, your code must be prepared to deal with any reentrancy: | - | ||||||||||||||||||
| 447 | other method calls and signals may be delivered before this function returns, as well | - | ||||||||||||||||||
| 448 | as other Qt queued signals and events. | - | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | \threadsafe | - | ||||||||||||||||||
| 451 | */ | - | ||||||||||||||||||
| 452 | QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode, | - | ||||||||||||||||||
| 453 | const QString& method, | - | ||||||||||||||||||
| 454 | const QList<QVariant>& args) | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | Q_D(QDBusAbstractInterface); | - | ||||||||||||||||||
| 457 | - | |||||||||||||||||||
| 458 | if (!d->isValid || !d->canMakeCalls())
| 0-697 | ||||||||||||||||||
| 459 | return QDBusMessage::createError(d->lastError); never executed: return QDBusMessage::createError(d->lastError); | 0 | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | QString m = method; | - | ||||||||||||||||||
| 462 | // split out the signature from the method | - | ||||||||||||||||||
| 463 | int pos = method.indexOf(QLatin1Char('.')); | - | ||||||||||||||||||
| 464 | if (pos != -1)
| 4-693 | ||||||||||||||||||
| 465 | m.truncate(pos); executed 4 times by 1 test: m.truncate(pos);Executed by:
| 4 | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | if (mode == QDBus::AutoDetect) {
| 328-369 | ||||||||||||||||||
| 468 | // determine if this a sync or async call | - | ||||||||||||||||||
| 469 | mode = QDBus::Block; | - | ||||||||||||||||||
| 470 | const QMetaObject *mo = metaObject(); | - | ||||||||||||||||||
| 471 | QByteArray match = m.toLatin1(); | - | ||||||||||||||||||
| 472 | - | |||||||||||||||||||
| 473 | for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) {
| 340-5318 | ||||||||||||||||||
| 474 | QMetaMethod mm = mo->method(i); | - | ||||||||||||||||||
| 475 | if (mm.name() == match) {
| 29-5289 | ||||||||||||||||||
| 476 | // found a method with the same name as what we're looking for | - | ||||||||||||||||||
| 477 | // hopefully, nobody is overloading asynchronous and synchronous methods with | - | ||||||||||||||||||
| 478 | // the same name | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | QList<QByteArray> tags = QByteArray(mm.tag()).split(' '); | - | ||||||||||||||||||
| 481 | if (tags.contains("Q_NOREPLY"))
| 0-29 | ||||||||||||||||||
| 482 | mode = QDBus::NoBlock; never executed: mode = QDBus::NoBlock; | 0 | ||||||||||||||||||
| 483 | - | |||||||||||||||||||
| 484 | break; executed 29 times by 5 tests: break;Executed by:
| 29 | ||||||||||||||||||
| 485 | } | - | ||||||||||||||||||
| 486 | } executed 5289 times by 155 tests: end of blockExecuted by:
| 5289 | ||||||||||||||||||
| 487 | } executed 369 times by 155 tests: end of blockExecuted by:
| 369 | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | // qDebug() << "QDBusAbstractInterface" << "Service" << service() << "Path:" << path(); | - | ||||||||||||||||||
| 490 | QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), m); | - | ||||||||||||||||||
| 491 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
| 492 | msg.setArguments(args); | - | ||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | QDBusMessage reply = d->connection.call(msg, mode, d->timeout); | - | ||||||||||||||||||
| 495 | if (thread() == QThread::currentThread())
| 286-411 | ||||||||||||||||||
| 496 | d->lastError = QDBusError(reply); // will clear if reply isn't an error executed 411 times by 26 tests: d->lastError = QDBusError(reply);Executed by:
| 411 | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | // ensure that there is at least one element | - | ||||||||||||||||||
| 499 | if (reply.arguments().isEmpty())
| 93-604 | ||||||||||||||||||
| 500 | reply << QVariant(); executed 93 times by 7 tests: reply << QVariant();Executed by:
| 93 | ||||||||||||||||||
| 501 | - | |||||||||||||||||||
| 502 | return reply; executed 697 times by 156 tests: return reply;Executed by:
| 697 | ||||||||||||||||||
| 503 | } | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | /*! | - | ||||||||||||||||||
| 506 | \since 4.5 | - | ||||||||||||||||||
| 507 | Places a call to the remote method specified by \a method on this | - | ||||||||||||||||||
| 508 | interface, using \a args as arguments. This function returns a | - | ||||||||||||||||||
| 509 | QDBusPendingCall object that can be used to track the status of the | - | ||||||||||||||||||
| 510 | reply and access its contents once it has arrived. | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | Normally, you should place calls using asyncCall(). | - | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | \threadsafe | - | ||||||||||||||||||
| 515 | */ | - | ||||||||||||||||||
| 516 | QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString& method, | - | ||||||||||||||||||
| 517 | const QList<QVariant>& args) | - | ||||||||||||||||||
| 518 | { | - | ||||||||||||||||||
| 519 | Q_D(QDBusAbstractInterface); | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | if (!d->isValid || !d->canMakeCalls())
| 6-99 | ||||||||||||||||||
| 522 | return QDBusPendingCall::fromError(d->lastError); executed 14 times by 1 test: return QDBusPendingCall::fromError(d->lastError);Executed by:
| 14 | ||||||||||||||||||
| 523 | - | |||||||||||||||||||
| 524 | QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); | - | ||||||||||||||||||
| 525 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
| 526 | msg.setArguments(args); | - | ||||||||||||||||||
| 527 | return d->connection.asyncCall(msg, d->timeout); executed 91 times by 19 tests: return d->connection.asyncCall(msg, d->timeout);Executed by:
| 91 | ||||||||||||||||||
| 528 | } | - | ||||||||||||||||||
| 529 | - | |||||||||||||||||||
| 530 | /*! | - | ||||||||||||||||||
| 531 | Places a call to the remote method specified by \a method | - | ||||||||||||||||||
| 532 | on this interface, using \a args as arguments. This function | - | ||||||||||||||||||
| 533 | returns immediately after queueing the call. The reply from | - | ||||||||||||||||||
| 534 | the remote function is delivered to the \a returnMethod on | - | ||||||||||||||||||
| 535 | object \a receiver. If an error occurs, the \a errorMethod | - | ||||||||||||||||||
| 536 | on object \a receiver is called instead. | - | ||||||||||||||||||
| 537 | - | |||||||||||||||||||
| 538 | This function returns \c true if the queueing succeeds. It does | - | ||||||||||||||||||
| 539 | not indicate that the executed call succeeded. If it fails, | - | ||||||||||||||||||
| 540 | the \a errorMethod is called. If the queueing failed, this | - | ||||||||||||||||||
| 541 | function returns \c false and no slot will be called. | - | ||||||||||||||||||
| 542 | - | |||||||||||||||||||
| 543 | The \a returnMethod must have as its parameters the types returned | - | ||||||||||||||||||
| 544 | by the function call. Optionally, it may have a QDBusMessage | - | ||||||||||||||||||
| 545 | parameter as its last or only parameter. The \a errorMethod must | - | ||||||||||||||||||
| 546 | have a QDBusError as its only parameter. | - | ||||||||||||||||||
| 547 | - | |||||||||||||||||||
| 548 | \since 4.3 | - | ||||||||||||||||||
| 549 | \sa QDBusError, QDBusMessage | - | ||||||||||||||||||
| 550 | */ | - | ||||||||||||||||||
| 551 | bool QDBusAbstractInterface::callWithCallback(const QString &method, | - | ||||||||||||||||||
| 552 | const QList<QVariant> &args, | - | ||||||||||||||||||
| 553 | QObject *receiver, | - | ||||||||||||||||||
| 554 | const char *returnMethod, | - | ||||||||||||||||||
| 555 | const char *errorMethod) | - | ||||||||||||||||||
| 556 | { | - | ||||||||||||||||||
| 557 | Q_D(QDBusAbstractInterface); | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | if (!d->isValid || !d->canMakeCalls())
| 0-6 | ||||||||||||||||||
| 560 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 561 | - | |||||||||||||||||||
| 562 | QDBusMessage msg = QDBusMessage::createMethodCall(service(), | - | ||||||||||||||||||
| 563 | path(), | - | ||||||||||||||||||
| 564 | interface(), | - | ||||||||||||||||||
| 565 | method); | - | ||||||||||||||||||
| 566 | QDBusMessagePrivate::setParametersValidated(msg, true); | - | ||||||||||||||||||
| 567 | msg.setArguments(args); | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | d->lastError = QDBusError(); | - | ||||||||||||||||||
| 570 | return d->connection.callWithCallback(msg, executed 6 times by 2 tests: return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod, d->timeout);Executed by:
| 6 | ||||||||||||||||||
| 571 | receiver, executed 6 times by 2 tests: return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod, d->timeout);Executed by:
| 6 | ||||||||||||||||||
| 572 | returnMethod, executed 6 times by 2 tests: return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod, d->timeout);Executed by:
| 6 | ||||||||||||||||||
| 573 | errorMethod, executed 6 times by 2 tests: return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod, d->timeout);Executed by:
| 6 | ||||||||||||||||||
| 574 | d->timeout); executed 6 times by 2 tests: return d->connection.callWithCallback(msg, receiver, returnMethod, errorMethod, d->timeout);Executed by:
| 6 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | /*! | - | ||||||||||||||||||
| 578 | \overload | - | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | This function is deprecated. Please use the overloaded version. | - | ||||||||||||||||||
| 581 | - | |||||||||||||||||||
| 582 | Places a call to the remote method specified by \a method | - | ||||||||||||||||||
| 583 | on this interface, using \a args as arguments. This function | - | ||||||||||||||||||
| 584 | returns immediately after queueing the call. The reply from | - | ||||||||||||||||||
| 585 | the remote function or any errors emitted by it are delivered | - | ||||||||||||||||||
| 586 | to the \a slot slot on object \a receiver. | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | This function returns \c true if the queueing succeeded: it does | - | ||||||||||||||||||
| 589 | not indicate that the call succeeded. If it failed, the slot | - | ||||||||||||||||||
| 590 | will be called with an error message. lastError() will not be | - | ||||||||||||||||||
| 591 | set under those circumstances. | - | ||||||||||||||||||
| 592 | - | |||||||||||||||||||
| 593 | \sa QDBusError, QDBusMessage | - | ||||||||||||||||||
| 594 | */ | - | ||||||||||||||||||
| 595 | bool QDBusAbstractInterface::callWithCallback(const QString &method, | - | ||||||||||||||||||
| 596 | const QList<QVariant> &args, | - | ||||||||||||||||||
| 597 | QObject *receiver, | - | ||||||||||||||||||
| 598 | const char *slot) | - | ||||||||||||||||||
| 599 | { | - | ||||||||||||||||||
| 600 | return callWithCallback(method, args, receiver, slot, 0); executed 5 times by 2 tests: return callWithCallback(method, args, receiver, slot, 0);Executed by:
| 5 | ||||||||||||||||||
| 601 | } | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | /*! | - | ||||||||||||||||||
| 604 | \internal | - | ||||||||||||||||||
| 605 | Catch signal connections. | - | ||||||||||||||||||
| 606 | */ | - | ||||||||||||||||||
| 607 | void QDBusAbstractInterface::connectNotify(const QMetaMethod &signal) | - | ||||||||||||||||||
| 608 | { | - | ||||||||||||||||||
| 609 | // someone connecting to one of our signals | - | ||||||||||||||||||
| 610 | Q_D(QDBusAbstractInterface); | - | ||||||||||||||||||
| 611 | if (!d->isValid)
| 0-387 | ||||||||||||||||||
| 612 | return; never executed: return; | 0 | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | // we end up recursing here, so optimize away | - | ||||||||||||||||||
| 615 | static const QMetaMethod destroyedSignal = QMetaMethod::fromSignal(&QDBusAbstractInterface::destroyed); | - | ||||||||||||||||||
| 616 | if (signal == destroyedSignal)
| 187-200 | ||||||||||||||||||
| 617 | return; executed 200 times by 19 tests: return;Executed by:
| 200 | ||||||||||||||||||
| 618 | - | |||||||||||||||||||
| 619 | QDBusConnectionPrivate *conn = d->connectionPrivate(); | - | ||||||||||||||||||
| 620 | if (conn) {
| 0-187 | ||||||||||||||||||
| 621 | conn->connectRelay(d->service, d->path, d->interface, | - | ||||||||||||||||||
| 622 | this, signal); | - | ||||||||||||||||||
| 623 | } executed 187 times by 19 tests: end of blockExecuted by:
| 187 | ||||||||||||||||||
| 624 | } executed 187 times by 19 tests: end of blockExecuted by:
| 187 | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | /*! | - | ||||||||||||||||||
| 627 | \internal | - | ||||||||||||||||||
| 628 | Catch signal disconnections. | - | ||||||||||||||||||
| 629 | */ | - | ||||||||||||||||||
| 630 | void QDBusAbstractInterface::disconnectNotify(const QMetaMethod &signal) | - | ||||||||||||||||||
| 631 | { | - | ||||||||||||||||||
| 632 | // someone disconnecting from one of our signals | - | ||||||||||||||||||
| 633 | Q_D(QDBusAbstractInterface); | - | ||||||||||||||||||
| 634 | if (!d->isValid)
| 0-102 | ||||||||||||||||||
| 635 | return; never executed: return; | 0 | ||||||||||||||||||
| 636 | - | |||||||||||||||||||
| 637 | // disconnection is just resource freeing, so it can be delayed; | - | ||||||||||||||||||
| 638 | // let's do that later, after all the QObject mutexes have been unlocked. | - | ||||||||||||||||||
| 639 | QCoreApplication::postEvent(this, new DisconnectRelayEvent(this, signal)); | - | ||||||||||||||||||
| 640 | } executed 102 times by 21 tests: end of blockExecuted by:
| 102 | ||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | /*! | - | ||||||||||||||||||
| 643 | \internal | - | ||||||||||||||||||
| 644 | Continues the disconnect notification from above. | - | ||||||||||||||||||
| 645 | */ | - | ||||||||||||||||||
| 646 | void QDBusAbstractInterfacePrivate::finishDisconnectNotify(QDBusAbstractInterface *ptr, int signalId) | - | ||||||||||||||||||
| 647 | { | - | ||||||||||||||||||
| 648 | QDBusAbstractInterfacePrivate *d = ptr->d_func(); | - | ||||||||||||||||||
| 649 | QDBusConnectionPrivate *conn = d->connectionPrivate(); | - | ||||||||||||||||||
| 650 | if (!conn)
| 0-15 | ||||||||||||||||||
| 651 | return; never executed: return; | 0 | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | const QMetaObject *mo = ptr->metaObject(); | - | ||||||||||||||||||
| 654 | QMetaMethod signal = signalId >= 0 ? mo->method(signalId) : QMetaMethod();
| 4-11 | ||||||||||||||||||
| 655 | if (signal.isValid()) {
| 4-11 | ||||||||||||||||||
| 656 | if (!ptr->isSignalConnected(signal))
| 0-11 | ||||||||||||||||||
| 657 | return conn->disconnectRelay(d->service, d->path, d->interface, never executed: return conn->disconnectRelay(d->service, d->path, d->interface, ptr, signal); | 0 | ||||||||||||||||||
| 658 | ptr, signal); never executed: return conn->disconnectRelay(d->service, d->path, d->interface, ptr, signal); | 0 | ||||||||||||||||||
| 659 | } else { executed 11 times by 2 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||
| 660 | // wildcard disconnecting, we need to figure out which of our signals are | - | ||||||||||||||||||
| 661 | // no longer connected to anything | - | ||||||||||||||||||
| 662 | int midx = QObject::staticMetaObject.methodCount(); | - | ||||||||||||||||||
| 663 | const int end = mo->methodCount(); | - | ||||||||||||||||||
| 664 | for ( ; midx < end; ++midx) {
| 4-40 | ||||||||||||||||||
| 665 | QMetaMethod mm = mo->method(midx); | - | ||||||||||||||||||
| 666 | if (mm.methodType() == QMetaMethod::Signal && !ptr->isSignalConnected(mm))
| 4-28 | ||||||||||||||||||
| 667 | conn->disconnectRelay(d->service, d->path, d->interface, ptr, mm); executed 8 times by 1 test: conn->disconnectRelay(d->service, d->path, d->interface, ptr, mm);Executed by:
| 8 | ||||||||||||||||||
| 668 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 669 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 670 | } | - | ||||||||||||||||||
| 671 | - | |||||||||||||||||||
| 672 | /*! | - | ||||||||||||||||||
| 673 | \internal | - | ||||||||||||||||||
| 674 | Get the value of the property \a propname. | - | ||||||||||||||||||
| 675 | */ | - | ||||||||||||||||||
| 676 | QVariant QDBusAbstractInterface::internalPropGet(const char *propname) const | - | ||||||||||||||||||
| 677 | { | - | ||||||||||||||||||
| 678 | // assume this property exists and is readable | - | ||||||||||||||||||
| 679 | // we're only called from generated code anyways | - | ||||||||||||||||||
| 680 | - | |||||||||||||||||||
| 681 | return property(propname); never executed: return property(propname); | 0 | ||||||||||||||||||
| 682 | } | - | ||||||||||||||||||
| 683 | - | |||||||||||||||||||
| 684 | /*! | - | ||||||||||||||||||
| 685 | \internal | - | ||||||||||||||||||
| 686 | Set the value of the property \a propname to \a value. | - | ||||||||||||||||||
| 687 | */ | - | ||||||||||||||||||
| 688 | void QDBusAbstractInterface::internalPropSet(const char *propname, const QVariant &value) | - | ||||||||||||||||||
| 689 | { | - | ||||||||||||||||||
| 690 | setProperty(propname, value); | - | ||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | /*! | - | ||||||||||||||||||
| 694 | Calls the method \a method on this interface and passes the parameters to this function to the | - | ||||||||||||||||||
| 695 | method. | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | The parameters to \c call are passed on to the remote function via D-Bus as input | - | ||||||||||||||||||
| 698 | arguments. Output arguments are returned in the QDBusMessage reply. If the reply is an error | - | ||||||||||||||||||
| 699 | reply, lastError() will also be set to the contents of the error message. | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | This function can be used with up to 8 parameters, passed in arguments \a arg1, \a arg2, | - | ||||||||||||||||||
| 702 | \a arg3, \a arg4, \a arg5, \a arg6, \a arg7 and \a arg8. If you need more than 8 | - | ||||||||||||||||||
| 703 | parameters or if you have a variable number of parameters to be passed, use | - | ||||||||||||||||||
| 704 | callWithArgumentList(). | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | It can be used the following way: | - | ||||||||||||||||||
| 707 | - | |||||||||||||||||||
| 708 | \snippet code/src_qdbus_qdbusabstractinterface.cpp 0 | - | ||||||||||||||||||
| 709 | - | |||||||||||||||||||
| 710 | This example illustrates function calling with 0, 1 and 2 parameters and illustrates different | - | ||||||||||||||||||
| 711 | parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one | - | ||||||||||||||||||
| 712 | Unicode string, the second call to \c "ProcessWork" will contain one string and one byte array). | - | ||||||||||||||||||
| 713 | */ | - | ||||||||||||||||||
| 714 | QDBusMessage QDBusAbstractInterface::call(const QString &method, const QVariant &arg1, | - | ||||||||||||||||||
| 715 | const QVariant &arg2, | - | ||||||||||||||||||
| 716 | const QVariant &arg3, | - | ||||||||||||||||||
| 717 | const QVariant &arg4, | - | ||||||||||||||||||
| 718 | const QVariant &arg5, | - | ||||||||||||||||||
| 719 | const QVariant &arg6, | - | ||||||||||||||||||
| 720 | const QVariant &arg7, | - | ||||||||||||||||||
| 721 | const QVariant &arg8) | - | ||||||||||||||||||
| 722 | { | - | ||||||||||||||||||
| 723 | return call(QDBus::AutoDetect, method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); executed 127 times by 28 tests: return call(QDBus::AutoDetect, method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);Executed by:
| 127 | ||||||||||||||||||
| 724 | } | - | ||||||||||||||||||
| 725 | - | |||||||||||||||||||
| 726 | /*! | - | ||||||||||||||||||
| 727 | \overload | - | ||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | Calls the method \a method on this interface and passes the | - | ||||||||||||||||||
| 730 | parameters to this function to the method. If \a mode is \c | - | ||||||||||||||||||
| 731 | NoWaitForReply, then this function will return immediately after | - | ||||||||||||||||||
| 732 | placing the call, without waiting for a reply from the remote | - | ||||||||||||||||||
| 733 | method. Otherwise, \a mode indicates whether this function should | - | ||||||||||||||||||
| 734 | activate the Qt Event Loop while waiting for the reply to arrive. | - | ||||||||||||||||||
| 735 | - | |||||||||||||||||||
| 736 | This function can be used with up to 8 parameters, passed in arguments \a arg1, \a arg2, | - | ||||||||||||||||||
| 737 | \a arg3, \a arg4, \a arg5, \a arg6, \a arg7 and \a arg8. If you need more than 8 | - | ||||||||||||||||||
| 738 | parameters or if you have a variable number of parameters to be passed, use | - | ||||||||||||||||||
| 739 | callWithArgumentList(). | - | ||||||||||||||||||
| 740 | - | |||||||||||||||||||
| 741 | If this function reenters the Qt event loop in order to wait for the | - | ||||||||||||||||||
| 742 | reply, it will exclude user input. During the wait, it may deliver | - | ||||||||||||||||||
| 743 | signals and other method calls to your application. Therefore, it | - | ||||||||||||||||||
| 744 | must be prepared to handle a reentrancy whenever a call is placed | - | ||||||||||||||||||
| 745 | with call(). | - | ||||||||||||||||||
| 746 | */ | - | ||||||||||||||||||
| 747 | QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method, | - | ||||||||||||||||||
| 748 | const QVariant &arg1, | - | ||||||||||||||||||
| 749 | const QVariant &arg2, | - | ||||||||||||||||||
| 750 | const QVariant &arg3, | - | ||||||||||||||||||
| 751 | const QVariant &arg4, | - | ||||||||||||||||||
| 752 | const QVariant &arg5, | - | ||||||||||||||||||
| 753 | const QVariant &arg6, | - | ||||||||||||||||||
| 754 | const QVariant &arg7, | - | ||||||||||||||||||
| 755 | const QVariant &arg8) | - | ||||||||||||||||||
| 756 | { | - | ||||||||||||||||||
| 757 | QList<QVariant> argList; | - | ||||||||||||||||||
| 758 | int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() + | - | ||||||||||||||||||
| 759 | arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid(); | - | ||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | switch (count) { | - | ||||||||||||||||||
| 762 | case 8: never executed: case 8: | 0 | ||||||||||||||||||
| 763 | argList.prepend(arg8); | - | ||||||||||||||||||
| 764 | // fall through | - | ||||||||||||||||||
| 765 | case 7: code before this statement never executed: case 7:never executed: case 7: | 0 | ||||||||||||||||||
| 766 | argList.prepend(arg7); | - | ||||||||||||||||||
| 767 | // fall through | - | ||||||||||||||||||
| 768 | case 6: code before this statement never executed: case 6:never executed: case 6: | 0 | ||||||||||||||||||
| 769 | argList.prepend(arg6); | - | ||||||||||||||||||
| 770 | // fall through | - | ||||||||||||||||||
| 771 | case 5: code before this statement never executed: case 5:never executed: case 5: | 0 | ||||||||||||||||||
| 772 | argList.prepend(arg5); | - | ||||||||||||||||||
| 773 | // fall through | - | ||||||||||||||||||
| 774 | case 4: code before this statement never executed: case 4:never executed: case 4: | 0 | ||||||||||||||||||
| 775 | argList.prepend(arg4); | - | ||||||||||||||||||
| 776 | // fall through | - | ||||||||||||||||||
| 777 | case 3: code before this statement never executed: case 3:executed 12 times by 1 test: case 3:Executed by:
| 0-12 | ||||||||||||||||||
| 778 | argList.prepend(arg3); | - | ||||||||||||||||||
| 779 | // fall through | - | ||||||||||||||||||
| 780 | case 2: code before this statement executed 12 times by 1 test: case 2:Executed by:
executed 59 times by 9 tests: case 2:Executed by:
| 12-59 | ||||||||||||||||||
| 781 | argList.prepend(arg2); | - | ||||||||||||||||||
| 782 | // fall through | - | ||||||||||||||||||
| 783 | case 1: code before this statement executed 71 times by 9 tests: case 1:Executed by:
executed 118 times by 9 tests: case 1:Executed by:
| 71-118 | ||||||||||||||||||
| 784 | argList.prepend(arg1); | - | ||||||||||||||||||
| 785 | } executed 118 times by 9 tests: end of blockExecuted by:
| 118 | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | return callWithArgumentList(mode, method, argList); executed 311 times by 29 tests: return callWithArgumentList(mode, method, argList);Executed by:
| 311 | ||||||||||||||||||
| 788 | } | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | - | |||||||||||||||||||
| 791 | /*! | - | ||||||||||||||||||
| 792 | \since 4.5 | - | ||||||||||||||||||
| 793 | Calls the method \a method on this interface and passes the parameters to this function to the | - | ||||||||||||||||||
| 794 | method. | - | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | The parameters to \c call are passed on to the remote function via D-Bus as input | - | ||||||||||||||||||
| 797 | arguments. The returned QDBusPendingCall object can be used to find out information about | - | ||||||||||||||||||
| 798 | the reply. | - | ||||||||||||||||||
| 799 | - | |||||||||||||||||||
| 800 | This function can be used with up to 8 parameters, passed in arguments \a arg1, \a arg2, | - | ||||||||||||||||||
| 801 | \a arg3, \a arg4, \a arg5, \a arg6, \a arg7 and \a arg8. If you need more than 8 | - | ||||||||||||||||||
| 802 | parameters or if you have a variable number of parameters to be passed, use | - | ||||||||||||||||||
| 803 | asyncCallWithArgumentList(). | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | It can be used the following way: | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | \snippet code/src_qdbus_qdbusabstractinterface.cpp 1 | - | ||||||||||||||||||
| 808 | - | |||||||||||||||||||
| 809 | This example illustrates function calling with 0, 1 and 2 parameters and illustrates different | - | ||||||||||||||||||
| 810 | parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one | - | ||||||||||||||||||
| 811 | Unicode string, the second call to \c "ProcessWork" will contain one string and one byte array). | - | ||||||||||||||||||
| 812 | */ | - | ||||||||||||||||||
| 813 | QDBusPendingCall QDBusAbstractInterface::asyncCall(const QString &method, const QVariant &arg1, | - | ||||||||||||||||||
| 814 | const QVariant &arg2, | - | ||||||||||||||||||
| 815 | const QVariant &arg3, | - | ||||||||||||||||||
| 816 | const QVariant &arg4, | - | ||||||||||||||||||
| 817 | const QVariant &arg5, | - | ||||||||||||||||||
| 818 | const QVariant &arg6, | - | ||||||||||||||||||
| 819 | const QVariant &arg7, | - | ||||||||||||||||||
| 820 | const QVariant &arg8) | - | ||||||||||||||||||
| 821 | { | - | ||||||||||||||||||
| 822 | QList<QVariant> argList; | - | ||||||||||||||||||
| 823 | int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() + | - | ||||||||||||||||||
| 824 | arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid(); | - | ||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | switch (count) { | - | ||||||||||||||||||
| 827 | case 8: never executed: case 8: | 0 | ||||||||||||||||||
| 828 | argList.prepend(arg8); | - | ||||||||||||||||||
| 829 | // fall through | - | ||||||||||||||||||
| 830 | case 7: code before this statement never executed: case 7:never executed: case 7: | 0 | ||||||||||||||||||
| 831 | argList.prepend(arg7); | - | ||||||||||||||||||
| 832 | // fall through | - | ||||||||||||||||||
| 833 | case 6: code before this statement never executed: case 6:never executed: case 6: | 0 | ||||||||||||||||||
| 834 | argList.prepend(arg6); | - | ||||||||||||||||||
| 835 | // fall through | - | ||||||||||||||||||
| 836 | case 5: code before this statement never executed: case 5:never executed: case 5: | 0 | ||||||||||||||||||
| 837 | argList.prepend(arg5); | - | ||||||||||||||||||
| 838 | // fall through | - | ||||||||||||||||||
| 839 | case 4: code before this statement never executed: case 4:never executed: case 4: | 0 | ||||||||||||||||||
| 840 | argList.prepend(arg4); | - | ||||||||||||||||||
| 841 | // fall through | - | ||||||||||||||||||
| 842 | case 3: code before this statement never executed: case 3:never executed: case 3: | 0 | ||||||||||||||||||
| 843 | argList.prepend(arg3); | - | ||||||||||||||||||
| 844 | // fall through | - | ||||||||||||||||||
| 845 | case 2: code before this statement never executed: case 2:never executed: case 2: | 0 | ||||||||||||||||||
| 846 | argList.prepend(arg2); | - | ||||||||||||||||||
| 847 | // fall through | - | ||||||||||||||||||
| 848 | case 1: code before this statement never executed: case 1:never executed: case 1: | 0 | ||||||||||||||||||
| 849 | argList.prepend(arg1); | - | ||||||||||||||||||
| 850 | } never executed: end of block | 0 | ||||||||||||||||||
| 851 | - | |||||||||||||||||||
| 852 | return asyncCallWithArgumentList(method, argList); executed 39 times by 2 tests: return asyncCallWithArgumentList(method, argList);Executed by:
| 39 | ||||||||||||||||||
| 853 | } | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | /*! | - | ||||||||||||||||||
| 856 | \internal | - | ||||||||||||||||||
| 857 | */ | - | ||||||||||||||||||
| 858 | QDBusMessage QDBusAbstractInterface::internalConstCall(QDBus::CallMode mode, | - | ||||||||||||||||||
| 859 | const QString &method, | - | ||||||||||||||||||
| 860 | const QList<QVariant> &args) const | - | ||||||||||||||||||
| 861 | { | - | ||||||||||||||||||
| 862 | // ### move the code here, and make the other functions call this | - | ||||||||||||||||||
| 863 | return const_cast<QDBusAbstractInterface*>(this)->callWithArgumentList(mode, method, args); executed 242 times by 150 tests: return const_cast<QDBusAbstractInterface*>(this)->callWithArgumentList(mode, method, args);Executed by:
| 242 | ||||||||||||||||||
| 864 | } | - | ||||||||||||||||||
| 865 | - | |||||||||||||||||||
| 866 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 867 | - | |||||||||||||||||||
| 868 | #endif // QT_NO_DBUS | - | ||||||||||||||||||
| 869 | - | |||||||||||||||||||
| 870 | #include "moc_qdbusabstractinterface.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |