如何定义一个可以自省的新 d-bus 接口?

How to define a new d-bus interface that can be introspected?

我已经创建了一个自定义的 d-bus 服务,它似乎已注册并且可以通过 dbus 调用激活,但是它没有接口定义并且不能通过 d-feet 等工具进行自省。

我正在尝试弄清楚如何做到这一点,我创建了以下接口文件:

<!DOCTYPE node PUBLIC
    "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
    "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
<node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
  <interface name="com.me.test.Manager">
    <method name="Start">
      <arg name="name" direction="in" type="s">
        <doc:doc><doc:summary>Name of new contact</doc:summary></doc:doc>
      </arg>
      <arg name="email" direction="in" type="s">
        <doc:doc><doc:summary>E-mail address of new contact</doc:summary></doc:doc>
      </arg>
      <arg name="id" direction="out" type="u">
        <doc:doc><doc:summary>ID of newly added contact</doc:summary></doc:doc>
      </arg>
      <doc:doc>
        <doc:description>
          <doc:para>
            Adds a new contact to the address book with their name and
            e-mail address.
          </doc:para>
        </doc:description>
      </doc:doc>
    </method>
  </interface>
</node>

我将文件命名为:

/usr/share/dbus-1/interfaces/com.me.test.Manager.xml

然而,当我使用 d-feet 浏览器搜索 "com.me.test" 时,我仍然没有在会话总线上看到任何对象。这个接口实际上是如何被dbus注册的,dbus是否监控这个目录?我试过重新启动 dbus,但没有帮助

您的服务需要调用 org.freedesktop.DBus.RequestName to be visible under ceertain name and after that respond to org.freedesktop.DBus.Introspectable.Introspect 个请求

这是我如何在我的 dbus 库中实现它的示例 - https://github.com/sidorares/node-dbus/blob/master/lib/stdifaces.js#L24-L92