Auto-Introspection In DBussy/Ravel

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Thu May 11 06:32:28 UTC 2017


I previously mentioned DBussy <https://gitlab.com/ldo/dbussy>,
<https://github.com/ldo/dbussy>, my pure-Python wrapper around libdbus
that uses the coroutine feature added in Python 3.5.

This consists of two modules: “dbussy”, which implements the core
libdbus support and various related definitions mentioned in the D-Bus
spec; and “ravel”, which adds a higher-level layer of Python interface
classes that represent D-Bus interfaces.

I have also published a repo of examples for the use of this library
<https://github.com/ldo/dbussy_examples>,
<https://gitlab.com/ldo/dbussy_examples>. I will probably add more
elaborate examples as I get more features working.

I have been working on an auto-introspection feature in the ravel
layer. A simple instance of this is currently included in the
“bigben_server_ravelled” example script. The main services provided by
this script are defined by this interface class:

    @ravel.interface(ravel.INTERFACE.SERVER, name = my_iface_name)
    class BigBen :

        @ravel.method \
          (
            name = "whats_the_time",
            in_signature = "",
            out_signature = "s"
          )
        async def handle_whats_the_time(self) :
            ...

        @ravel.signal(name = "chime", in_signature = "as")
        def chime_dummy(self) : pass

        @ravel.method \
          (
            name = "stop",
            in_signature = "",
            out_signature = "",
            connection_keyword = "conn",
            message_keyword = "message",
          )
        def handle_stop(self, conn, message) :
            ...

    #end BigBen

and registered on the bus connection with

    bus.register \
      (
        path = "/",
        fallback = True,
        interface = BigBen
      )

When you send an Introspect request to this server, the following XML
is automatically generated and returned:

    <node name="/">
        <interface name="com.example.bigben">
            <method name="stop"/>
            <method name="whats_the_time">
                <arg type="s" direction="out"/>
            </method>
            <signal name="chime">
                <arg type="as"/>
            </signal>
        </interface>
        <interface name="org.freedesktop.DBus.Introspectable">
            <method name="Introspect">
                <arg type="s" direction="out"/>
            </method>
        </interface>
    </node>


More information about the dbus mailing list