qdbusabstractinterface.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9static QDBusError checkIfValid(const QString &service, const QString &path, -
10 const QString &interface, bool isDynamic, bool isPeer) -
11{ -
12 -
13 QDBusError error; -
14 -
15 -
16 -
17 if (!isDynamic) {
-
18 -
19 qt_noop(); -
20 }
-
21 if (!QDBusUtil::checkBusName(service, (isDynamic && !isPeer) ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
-
22 return error;
-
23 if (!QDBusUtil::checkObjectPath(path, isDynamic ? QDBusUtil::EmptyNotAllowed : QDBusUtil::EmptyAllowed, &error))
-
24 return error;
-
25 if (!QDBusUtil::checkInterfaceName(interface, QDBusUtil::EmptyAllowed, &error))
-
26 return error;
-
27 -
28 -
29 return QDBusError();
-
30} -
31 -
32QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv, -
33 const QString &p, -
34 const QString &iface, -
35 const QDBusConnection& con, -
36 bool isDynamic) -
37 : connection(con), service(serv), path(p), interface(iface), -
38 lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() && -
39 connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))), -
40 timeout(-1), -
41 isValid(!lastError.isValid()) -
42{ -
43 if (!isValid)
-
44 return;
-
45 -
46 if (!connection.isConnected()) {
-
47 lastError = QDBusError(QDBusError::Disconnected, -
48 QLatin1String("Not connected to D-Bus server")); -
49 } else if (!service.isEmpty()) {
-
50 currentOwner = connectionPrivate()->getNameOwner(service); -
51 if (currentOwner.isEmpty()) {
-
52 lastError = connectionPrivate()->lastError; -
53 }
-
54 }
-
55} -
56 -
57bool QDBusAbstractInterfacePrivate::canMakeCalls() const -
58{ -
59 -
60 -
61 if (service.isEmpty() && connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
-
62 return QDBusUtil::checkBusName(service, QDBusUtil::EmptyNotAllowed, &lastError);
-
63 if (path.isEmpty())
-
64 return QDBusUtil::checkObjectPath(path, QDBusUtil::EmptyNotAllowed, &lastError);
-
65 return true;
-
66} -
67 -
68void QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, QVariant &where) const -
69{ -
70 if (!isValid || !canMakeCalls()) {
evaluated: !isValid
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:25
evaluated: !canMakeCalls()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:17
6-25
71 where.clear(); -
72 return;
executed: return;
Execution Count:14
14
73 } -
74 -
75 -
76 const char *expectedSignature = ""; -
77 if (int(mp.type()) != QMetaType::QVariant) {
partially evaluated: int(mp.type()) != QMetaType::QVariant
TRUEFALSE
yes
Evaluation Count:17
no
Evaluation Count:0
0-17
78 expectedSignature = QDBusMetaType::typeToSignature(where.userType()); -
79 if (expectedSignature == 0) {
partially evaluated: expectedSignature == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17
0-17
80 QMessageLogger("qdbusabstractinterface.cpp", 131, __PRETTY_FUNCTION__).warning("QDBusAbstractInterface: type %s must be registered with QtDBusQt D-Bus before it can be " -
81 "used to read property %s.%s", -
82 mp.typeName(), QString(interface).toLocal8Bit().constData(), mp.name()); -
83 lastError = QDBusError(QDBusError::Failed, -
84 QString::fromLatin1("Unregistered type %1 cannot be handled") -
85 .arg(QLatin1String(mp.typeName()))); -
86 where.clear(); -
87 return;
never executed: return;
0
88 } -
89 }
executed: }
Execution Count:17
17
90 -
91 -
92 QDBusMessage msg = QDBusMessage::createMethodCall(service, path, -
93 QLatin1String("org.freedesktop.DBus.Properties"), -
94 QLatin1String("Get")); -
95 QDBusMessagePrivate::setParametersValidated(msg, true); -
96 msg << interface << QString::fromUtf8(mp.name()); -
97 QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); -
98 -
99 if (reply.type() != QDBusMessage::ReplyMessage) {
evaluated: reply.type() != QDBusMessage::ReplyMessage
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:16
1-16
100 lastError = QDBusError(reply); -
101 where.clear(); -
102 return;
executed: return;
Execution Count:1
1
103 } -
104 if (reply.signature() != QLatin1String("v")) {
partially evaluated: reply.signature() != QLatin1String("v")
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
105 QString errmsg = QLatin1String("Invalid signature `%1' in return from call to " -
106 "org.freedesktop.DBus.Properties"); -
107 lastError = QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature())); -
108 where.clear(); -
109 return;
never executed: return;
0
110 } -
111 -
112 QByteArray foundSignature; -
113 const char *foundType = 0; -
114 QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant(); -
115 -
116 if (value.userType() == where.userType() || mp.userType() == QMetaType::QVariant
evaluated: value.userType() == where.userType()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:6
partially evaluated: mp.userType() == QMetaType::QVariant
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-10
117 || (expectedSignature[0] == 'v' && expectedSignature[1] == '\0')) {
partially evaluated: expectedSignature[0] == 'v'
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
never evaluated: expectedSignature[1] == '\0'
0-6
118 -
119 where = value; -
120 return;
executed: return;
Execution Count:10
10
121 } -
122 -
123 if (value.userType() == qMetaTypeId<QDBusArgument>()) {
partially evaluated: value.userType() == qMetaTypeId<QDBusArgument>()
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
124 QDBusArgument arg = qvariant_cast<QDBusArgument>(value); -
125 -
126 foundType = "user type"; -
127 foundSignature = arg.currentSignature().toLatin1(); -
128 if (foundSignature == expectedSignature) {
partially evaluated: foundSignature == expectedSignature
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
129 -
130 QDBusMetaType::demarshall(arg, where.userType(), where.data()); -
131 return;
executed: return;
Execution Count:6
6
132 } -
133 } else {
never executed: }
0
134 foundType = value.typeName(); -
135 foundSignature = QDBusMetaType::typeToSignature(value.userType()); -
136 }
never executed: }
0
137 -
138 -
139 QString errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' " -
140 "(expected type `%5' (%6))"); -
141 lastError = QDBusError(QDBusError::InvalidSignature, -
142 errmsg.arg(QString::fromLatin1(foundType), -
143 QString::fromLatin1(foundSignature), -
144 interface, -
145 QString::fromUtf8(mp.name()), -
146 QString::fromLatin1(mp.typeName()), -
147 QString::fromLatin1(expectedSignature))); -
148 where.clear(); -
149 return;
never executed: return;
0
150} -
151 -
152bool QDBusAbstractInterfacePrivate::setProperty(const QMetaProperty &mp, const QVariant &value) -
153{ -
154 if (!isValid || !canMakeCalls())
-
155 return false;
-
156 -
157 -
158 QDBusMessage msg = QDBusMessage::createMethodCall(service, path, -
159 QLatin1String("org.freedesktop.DBus.Properties"), -
160 QLatin1String("Set")); -
161 QDBusMessagePrivate::setParametersValidated(msg, true); -
162 msg << interface << QString::fromUtf8(mp.name()) << QVariant::fromValue(QDBusVariant(value)); -
163 QDBusMessage reply = connection.call(msg, QDBus::Block, timeout); -
164 -
165 if (reply.type() != QDBusMessage::ReplyMessage) {
-
166 lastError = QDBusError(reply); -
167 return false;
-
168 } -
169 return true;
-
170} -
171 -
172void QDBusAbstractInterfacePrivate::_q_serviceOwnerChanged(const QString &name, -
173 const QString &oldOwner, -
174 const QString &newOwner) -
175{ -
176 (void)oldOwner;; -
177 -
178 if (name == service) {
-
179 currentOwner = newOwner; -
180 }
-
181}
-
182 -
183QDBusAbstractInterfaceBase::QDBusAbstractInterfaceBase(QDBusAbstractInterfacePrivate &d, QObject *parent) -
184 : QObject(d, parent) -
185{ -
186}
-
187 -
188int QDBusAbstractInterfaceBase::qt_metacall(QMetaObject::Call _c, int _id, void **_a) -
189{ -
190 int saved_id = _id; -
191 _id = QObject::qt_metacall(_c, _id, _a); -
192 if (_id < 0) -
193 return _id; -
194 -
195 if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty) { -
196 QMetaProperty mp = metaObject()->property(saved_id); -
197 int &status = *reinterpret_cast<int *>(_a[2]); -
198 QVariant &variant = *reinterpret_cast<QVariant *>(_a[1]); -
199 -
200 if (_c == QMetaObject::WriteProperty) { -
201 status = d_func()->setProperty(mp, variant) ? 1 : 0; -
202 } else { -
203 d_func()->property(mp, variant); -
204 status = variant.isValid() ? 1 : 0; -
205 } -
206 _id = -1; -
207 } -
208 return _id; -
209} -
210QDBusAbstractInterface::QDBusAbstractInterface(QDBusAbstractInterfacePrivate &d, QObject *parent) -
211 : QDBusAbstractInterfaceBase(d, parent) -
212{ -
213 -
214 if (d.isValid &&
-
215 d.connection.isConnected()
-
216 && !d.service.isEmpty()
-
217 && !d.service.startsWith(QLatin1Char(':')))
-
218 d_func()->connection.connect(QLatin1String("org.freedesktop.DBus"), -
219 QString(), -
220 QLatin1String("org.freedesktop.DBus"), -
221 QLatin1String("NameOwnerChanged"), -
222 QStringList() << d.service, -
223 QString(), -
224 this, "1""_q_serviceOwnerChanged(QString,QString,QString)");
-
225}
-
226 -
227 -
228 -
229 -
230 -
231 -
232QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QString &path, -
233 const char *interface, const QDBusConnection &con, -
234 QObject *parent) -
235 : QDBusAbstractInterfaceBase(*new QDBusAbstractInterfacePrivate(service, path, QString::fromLatin1(interface), -
236 con, false), parent) -
237{ -
238 -
239 if (d_func()->isValid &&
-
240 d_func()->connection.isConnected()
-
241 && !service.isEmpty()
-
242 && !service.startsWith(QLatin1Char(':')))
-
243 d_func()->connection.connect(QLatin1String("org.freedesktop.DBus"), -
244 QString(), -
245 QLatin1String("org.freedesktop.DBus"), -
246 QLatin1String("NameOwnerChanged"), -
247 QStringList() << service, -
248 QString(), -
249 this, "1""_q_serviceOwnerChanged(QString,QString,QString)");
-
250}
-
251 -
252 -
253 -
254 -
255QDBusAbstractInterface::~QDBusAbstractInterface() -
256{ -
257} -
258bool QDBusAbstractInterface::isValid() const -
259{ -
260 return !d_func()->currentOwner.isEmpty();
-
261} -
262 -
263 -
264 -
265 -
266QDBusConnection QDBusAbstractInterface::connection() const -
267{ -
268 return d_func()->connection;
-
269} -
270 -
271 -
272 -
273 -
274QString QDBusAbstractInterface::service() const -
275{ -
276 return d_func()->service;
-
277} -
278 -
279 -
280 -
281 -
282QString QDBusAbstractInterface::path() const -
283{ -
284 return d_func()->path;
-
285} -
286 -
287 -
288 -
289 -
290QString QDBusAbstractInterface::interface() const -
291{ -
292 return d_func()->interface;
-
293} -
294 -
295 -
296 -
297 -
298 -
299QDBusError QDBusAbstractInterface::lastError() const -
300{ -
301 return d_func()->lastError;
-
302} -
303 -
304 -
305 -
306 -
307 -
308 -
309 -
310void QDBusAbstractInterface::setTimeout(int timeout) -
311{ -
312 d_func()->timeout = timeout; -
313}
-
314 -
315 -
316 -
317 -
318 -
319 -
320 -
321int QDBusAbstractInterface::timeout() const -
322{ -
323 return d_func()->timeout;
-
324} -
325QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode, -
326 const QString& method, -
327 const QList<QVariant>& args) -
328{ -
329 QDBusAbstractInterfacePrivate * const d = d_func(); -
330 -
331 if (!d->isValid || !d->canMakeCalls())
-
332 return QDBusMessage::createError(d->lastError);
-
333 -
334 QString m = method; -
335 -
336 int pos = method.indexOf(QLatin1Char('.')); -
337 if (pos != -1)
-
338 m.truncate(pos);
-
339 -
340 if (mode == QDBus::AutoDetect) {
-
341 -
342 mode = QDBus::Block; -
343 const QMetaObject *mo = metaObject(); -
344 QByteArray match = m.toLatin1(); -
345 -
346 for (int i = staticMetaObject.methodCount(); i < mo->methodCount(); ++i) {
-
347 QMetaMethod mm = mo->method(i); -
348 if (mm.name() == match) {
-
349 -
350 -
351 -
352 -
353 QList<QByteArray> tags = QByteArray(mm.tag()).split(' '); -
354 if (tags.contains("Q_NOREPLY"))
-
355 mode = QDBus::NoBlock;
-
356 -
357 break;
-
358 } -
359 }
-
360 }
-
361 -
362 -
363 QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), m); -
364 QDBusMessagePrivate::setParametersValidated(msg, true); -
365 msg.setArguments(args); -
366 -
367 QDBusMessage reply = d->connection.call(msg, mode, d->timeout); -
368 if (thread() == QThread::currentThread())
-
369 d->lastError = QDBusError(reply);
-
370 -
371 -
372 if (reply.arguments().isEmpty())
-
373 reply << QVariant();
-
374 -
375 return reply;
-
376} -
377QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString& method, -
378 const QList<QVariant>& args) -
379{ -
380 QDBusAbstractInterfacePrivate * const d = d_func(); -
381 -
382 if (!d->isValid || !d->canMakeCalls())
-
383 return QDBusPendingCall::fromError(d->lastError);
-
384 -
385 QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method); -
386 QDBusMessagePrivate::setParametersValidated(msg, true); -
387 msg.setArguments(args); -
388 return d->connection.asyncCall(msg, d->timeout);
-
389} -
390bool QDBusAbstractInterface::callWithCallback(const QString &method, -
391 const QList<QVariant> &args, -
392 QObject *receiver, -
393 const char *returnMethod, -
394 const char *errorMethod) -
395{ -
396 QDBusAbstractInterfacePrivate * const d = d_func(); -
397 -
398 if (!d->isValid || !d->canMakeCalls())
-
399 return false;
-
400 -
401 QDBusMessage msg = QDBusMessage::createMethodCall(service(), -
402 path(), -
403 interface(), -
404 method); -
405 QDBusMessagePrivate::setParametersValidated(msg, true); -
406 msg.setArguments(args); -
407 -
408 d->lastError = QDBusError(); -
409 return d->connection.callWithCallback(msg, -
410 receiver, -
411 returnMethod, -
412 errorMethod, -
413 d->timeout);
-
414} -
415bool QDBusAbstractInterface::callWithCallback(const QString &method, -
416 const QList<QVariant> &args, -
417 QObject *receiver, -
418 const char *slot) -
419{ -
420 return callWithCallback(method, args, receiver, slot, 0);
-
421} -
422 -
423 -
424 -
425 -
426 -
427void QDBusAbstractInterface::connectNotify(const QMetaMethod &signal) -
428{ -
429 -
430 QDBusAbstractInterfacePrivate * const d = d_func(); -
431 if (!d->isValid)
-
432 return;
-
433 -
434 -
435 static const QMetaMethod destroyedSignal = QMetaMethod::fromSignal(&QDBusAbstractInterface::destroyed); -
436 if (signal == destroyedSignal)
-
437 return;
-
438 -
439 QDBusConnectionPrivate *conn = d->connectionPrivate(); -
440 if (conn) {
-
441 conn->connectRelay(d->service, d->path, d->interface, -
442 this, signal); -
443 }
-
444}
-
445 -
446 -
447 -
448 -
449 -
450void QDBusAbstractInterface::disconnectNotify(const QMetaMethod &signal) -
451{ -
452 -
453 QDBusAbstractInterfacePrivate * const d = d_func(); -
454 if (!d->isValid)
-
455 return;
-
456 -
457 QDBusConnectionPrivate *conn = d->connectionPrivate(); -
458 if (conn)
-
459 conn->disconnectRelay(d->service, d->path, d->interface, -
460 this, signal);
-
461}
-
462 -
463 -
464 -
465 -
466 -
467QVariant QDBusAbstractInterface::internalPropGet(const char *propname) const -
468{ -
469 -
470 -
471 -
472 return property(propname);
-
473} -
474 -
475 -
476 -
477 -
478 -
479void QDBusAbstractInterface::internalPropSet(const char *propname, const QVariant &value) -
480{ -
481 setProperty(propname, value); -
482}
-
483QDBusMessage QDBusAbstractInterface::call(const QString &method, const QVariant &arg1, -
484 const QVariant &arg2, -
485 const QVariant &arg3, -
486 const QVariant &arg4, -
487 const QVariant &arg5, -
488 const QVariant &arg6, -
489 const QVariant &arg7, -
490 const QVariant &arg8) -
491{ -
492 return call(QDBus::AutoDetect, method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
-
493} -
494QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method, -
495 const QVariant &arg1, -
496 const QVariant &arg2, -
497 const QVariant &arg3, -
498 const QVariant &arg4, -
499 const QVariant &arg5, -
500 const QVariant &arg6, -
501 const QVariant &arg7, -
502 const QVariant &arg8) -
503{ -
504 QList<QVariant> argList; -
505 int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() + -
506 arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid(); -
507 -
508 switch (count) { -
509 case 8: -
510 argList.prepend(arg8); -
511 case 7:
-
512 argList.prepend(arg7); -
513 case 6:
-
514 argList.prepend(arg6); -
515 case 5:
-
516 argList.prepend(arg5); -
517 case 4:
-
518 argList.prepend(arg4); -
519 case 3:
-
520 argList.prepend(arg3); -
521 case 2:
-
522 argList.prepend(arg2); -
523 case 1:
-
524 argList.prepend(arg1); -
525 }
-
526 -
527 return callWithArgumentList(mode, method, argList);
-
528} -
529QDBusPendingCall QDBusAbstractInterface::asyncCall(const QString &method, const QVariant &arg1, -
530 const QVariant &arg2, -
531 const QVariant &arg3, -
532 const QVariant &arg4, -
533 const QVariant &arg5, -
534 const QVariant &arg6, -
535 const QVariant &arg7, -
536 const QVariant &arg8) -
537{ -
538 QList<QVariant> argList; -
539 int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() + -
540 arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid(); -
541 -
542 switch (count) { -
543 case 8: -
544 argList.prepend(arg8); -
545 case 7:
-
546 argList.prepend(arg7); -
547 case 6:
-
548 argList.prepend(arg6); -
549 case 5:
-
550 argList.prepend(arg5); -
551 case 4:
-
552 argList.prepend(arg4); -
553 case 3:
-
554 argList.prepend(arg3); -
555 case 2:
-
556 argList.prepend(arg2); -
557 case 1:
-
558 argList.prepend(arg1); -
559 }
-
560 -
561 return asyncCallWithArgumentList(method, argList);
-
562} -
563 -
564 -
565 -
566 -
567QDBusMessage QDBusAbstractInterface::internalConstCall(QDBus::CallMode mode, -
568 const QString &method, -
569 const QList<QVariant> &args) const -
570{ -
571 -
572 return const_cast<QDBusAbstractInterface*>(this)->callWithArgumentList(mode, method, args);
-
573} -
574 -
575 -
576 -
577 -
578 -
579 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial