Ava
Ava

Reputation: 2132

Get GDBusConnection for Bus name that's already owned

I would like to register an object for a Bus name that's already owned. Below is how I would register an object on a new Bus, but own_name fails if the Bus already exists. Can I retrieve the DBusConnection object some other way so I can call register_object?

Bus.own_name (BusType.SESSION, "net.launchpad.Diodon", BusNameOwnerFlags.NONE,
    conn => {
        try {
            conn.register_object ("/net/launchpad/Diodon", new DBusController (controller));
        } catch (IOError e) {
            stderr.printf ("Could not register service\n");
        }
    },
    () => {},
    () => stderr.printf ("Could not aquire name\n"));

Upvotes: 0

Views: 418

Answers (1)

Perazzo
Perazzo

Reputation: 1147

As described on Gio docs, if the bus name was owned by a message bus connection using BusNameOwnerFlags.ALLOW_REPLACEMENT you could use BusNameOwnerFlags.REPLACE and take the name from the other connection. Otherwise, the own_name function will fail to acquire the name.

By the commits I could find on Diodon git history, it seems "net.launchpad.Diodon" was acquired using flag NONE.

Upvotes: 0

Related Questions