Igor S.K. Igor S.K. - 1 year ago 143
Linux Question

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

-- that is a struct of two

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

Any pointers?

Answer Source

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

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_name = dbus.service.BusName(BUS_NAME, bus=bus)
        dbus.service.Object.__init__(self, bus_name, OPATH)

                         in_signature="(uu)", out_signature="")
    def Test(self, payload):
        print "Got this from client:", payload

if __name__ == "__main__":
    service = Example()
    loop = gobject.MainLoop()

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

Hope this helps.