Search code examples
c++linuxdbus

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


I've created a custom d-bus service which seems to be registered and can be activated by a dbus call, however it has no interface definition and can not be introspected by tools like d-feet.

I'm trying to figure out how to do this, I've created the following interface file:

<!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>

I've named the file this:

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

However I still do not see any object on the session bus when I search for "com.me.test" using d-feet browser. How does this interface actually get registered by dbus, does dbus monitor this directory? I've tried restarting dbus but that didn't help


Solution

  • your service need to call org.freedesktop.DBus.RequestName to be visible under ceertain name and after that respond to org.freedesktop.DBus.Introspectable.Introspect requests

    Here is example how I implemented it in my dbus library - https://github.com/sidorares/node-dbus/blob/master/lib/stdifaces.js#L24-L92