c++ - 如何定义一个可以自省(introspection)的新 d-bus 接口(interface)?

标签 c++ linux dbus

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

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

<!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”时,我仍然没有在 session 总线上看到任何对象。这个接口(interface)实际上是如何被dbus注册的,dbus是否监控这个目录?我试过重新启动 dbus,但没有帮助

最佳答案

您的服务需要调用org.freedesktop.DBus.RequestName在特定名称下可见,然后回复 org.freedesktop.DBus.Introspectable.Introspect要求

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

关于c++ - 如何定义一个可以自省(introspection)的新 d-bus 接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815101/

相关文章:

c++ - 自定义流缓冲区能否在程序退出时和请求输入时自动刷新?

c++ - 如何在树莓派上使用c++/libao/alsa通过USB声卡播放音频?

dbus - 使用 dbus-send 调用 GetAll

使用 D-Bus (qdbus) Send With org.bluez.MediaTransport1 发送 AVRCP 音量更改的蓝牙问题

c++ - 为什么将增量运算符应用于常量变量时​​会出现编译器错误

c++ - 内部类的不可见运算符<<重载

linux - 使用命令行使用 "editable text"创建多层 psd 文件

ubuntu - 如何从 systemd 用户服务访问 session D-Bus?

c++ - 功能工作定时器

linux - 如何修改Buildroot包的来源进行包开发?