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