Search code examples
linuxdbus

A tool to pass struct to dbus method?


I've created a daemon. The daemon provides a dbus interface, with one of its methods having a signature like this (uu) -- that is a struct of two uint32 fields.

Is there a ready-to-use tool for me to invoke the method, to pass the struct in? dbus-send and d-feet doesn't seem to help.

Any pointers?


Solution

  • gdbus should do the trick. Try the equivalent of:

    gdbus call --session --dest com.example.MyTest  --object-path /com/example/MyTest --method com.example.MyTest.Test "(1,2)"
    

    ... with the correct parameters for your situation of course.

    I've tested the call above using a Python D-Bus service like this:

    import gobject
    import dbus
    import dbus.service
    
    from dbus.mainloop.glib import DBusGMainLoop
    DBusGMainLoop(set_as_default=True)
    
    
    OPATH = "/com/example/MyTest"
    IFACE = "com.example.MyTest"
    BUS_NAME = "com.example.MyTest"
    
    
    class Example(dbus.service.Object):
        def __init__(self):
            bus = dbus.SessionBus()
            bus.request_name(BUS_NAME)
            bus_name = dbus.service.BusName(BUS_NAME, bus=bus)
            dbus.service.Object.__init__(self, bus_name, OPATH)
    
        @dbus.service.method(dbus_interface=IFACE,
                             in_signature="(uu)", out_signature="")
        def Test(self, payload):
            print "Got this from client:", payload
    
    
    if __name__ == "__main__":
        service = Example()
        loop = gobject.MainLoop()
        loop.run()
    

    On the Ubuntu 15.10 machine I'm on gdbus is provided by the libglib2.0-bin package:

    $ dpkg -L libglib2.0-bin | grep gdbus
    /usr/bin/gdbus
    /usr/share/bash-completion/completions/gdbus
    /usr/share/man/man1/gdbus.1.gz
    

    Hope this helps.