How to know when D-Bus interfaces and methods are available

Thiago Macieira thiago at kde.org
Wed Aug 5 19:22:46 BST 2009


Kevin Krammer wrote:
>On Wednesday, 2009-08-05, Thiago Macieira wrote:
>> You can't create a QDBusInterface without object path. QDBusInterface
>> requires a running and existing object when it's created so that it
>> may introspect.
>>
>> You must use an interface generated by qdbusxml2cpp to use it without
>> object paths. You can also use it without service names. This kind of
>> interface cannot be used for calling, but it can be used to connecting
>> to signals.
>
>Ah, good to know.
>I guess it does that through QDBusConnection::connect()?

Yes, behind the scenes. When you connect a slot, QObject calls 
connectNotify() (protected virtual), so we just catch all connects and do 
the QDBusConnection::connect() to the signal.

>Was there a specific reason why QDBusInterface was limited to
> introspectable objects?

Because it needs to create the meta object. You can make calls without 
knowing the target, but to use QObject::connect(), QObject::property() or 
QObject::setProperty() you need the meta object. If you have the meta 
object, you can connect to remote methods (they are exposed as slots) as 
well as call them with QMetaObject::invokeMethod.

>> So your object could emit a signal when it's ready to be used. The
>> target application would then receive it and create the
>> QDBusAbstractInterface with service and object path.
>
>Right, or create the generate object. Main point is that the caller
>application would listen for a given signal which would indicate that
> some object now has that interface available.
>
>A bit like connting to nameOwnerChanged but a lot more precise.

Yes. The more precise you can get, the less spurious signals you will get. 
That means the number of wakeups to deliver the signals is much smaller.

>> If you already know the service and object path though, you can use
>> QDBusAbstractInterface directly, even if the object doesn't exist yet.
>> You just have to be careful about making calls.
>
>Also a good tip!

If you make calls and the object doesn't exist, you'll get an error as a 
reply. That's it. So you don't have to make a call to find out if you can 
make a call. Just make your call.

It's like sending a "test" email to a mailing list: never do that. If you 
have something to ask, ask it. If you don't have something to say, you 
don't need to know whether you can post.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090805/8f424d52/attachment.sig>


More information about the kde-core-devel mailing list