Search code examples
c++qtdbusqdbus

How to add objects to DBus service from another process / program


I create a DBus service and add objects to it.

QDBusConnection connection = QDBusConnection::sessionBus();
connection.registerService(serviceName); // name, e.g. "foo"
QDBusConnection::sessionBus().registerObject(path, object, myoptions);

Fine, I can see my objects under "service" in the DBus monitor. Now I want to add more objects, but from another program (which is related, but independent).

There connection.registerService(serviceName); fails, as the service already exists. How would I be able to register more objects under the same service name?

Background: I have clients consuming the services. They do not know who provides the services, but just the service name. So they always refer to the same service name. But several providers shall provide the service.

I have tried to use no service name (empty string, just relying on the object path). But the proxies based on

QDBusAbstractInterface(serviceName, path, interfaceName.toUtf8().constData(), connection, parent)

do not seem to work with an empty ("") serviceName (correct?).


Solution

  • you can't, one connection to dbus == one name. Connections are usually unix sockets or abstract sockets (on linux). You'll need to proxy calls from first connection using some kind or RPC ( or dbus call ) to other services and respond back results from first connection as well.