获取已拥有的总线名称的GDBusConnection

问题描述:

我想为已经拥有的总线名称注册一个对象。以下是我将如何在新总线上注册一个对象,但如果总线已经存在,则own_name将失败。我能否以其他方式检索DBusConnection对象,因此我可以拨打register_object获取已拥有的总线名称的GDBusConnection

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")); 
+3

名称一次只能由一个程序拥有......您是否有更广泛的背景知道您想要做什么? – ptomato

由于上Gio docs描述的,如果总线名称是通过使用BusNameOwnerFlags.ALLOW_REPLACEMENT你可以使用BusNameOwnerFlags.REPLACE和其他连接取名字的消息总线连接所有。否则,own_name函数将无法获取该名称。

通过我可以在Diodon git history找到的承诺,看起来"net.launchpad.Diodon"是使用标记NONE获得的。