I have the following setup:
- I have two applications, belonging to the same logical group (logical group = product of our company)
- These two applications need to connect to DBus to the same interface (we have more products, all of them should use their own DBus interface) and expose some functionality (and all this with QtDBus).
So I tried to (the arrows are NOT C++ pointer operations 🙂 ):
App1 -> get QDBusConnection::sessionBus();
App1 -> registerService("com.una-frog.ddm")
App1 -> registerObject ("/DDM-gui")
then
App2 -> get QDBusConnection::sessionBus();
App2 -> registerService("com.una-frog.ddm")
App2 -> registerObject ("/DDM-cli")
and start App1 and App2.
At this point the App2 complains that it cannot register the service because App1 already registered it. That’s correct.
I easily could register App1 to “com.una-frog.ddm.gui” and App2 to “com.una-frog.ddm.cli” but I’d rather try to have one common interface and two objects there taking all the required actions.
Anyone knows how to achieve two QtDBus applications connecting to the same interface?
The two apps can share the DBus interface
com.una-frog.ddm. But registerService does not work with interfaces, it works with DBus services. Service names cannot be shared between applications because they are used to route method calls (which are unicast).If you redesign your API so that the two apps listen for (broadcast) signals instead, then you don’t even need to register service names.
Alternatively, the bus has a concept of queued owners of a service name (see
DBUS_NAME_FLAG_*in the specification). That is useful if two apps provide the same service and you don’t care whichever handles it. Qt seems to have this: http://doc.qt.digia.com/stable/qdbusconnectioninterface.html#registerService