dbus-native icon indicating copy to clipboard operation
dbus-native copied to clipboard

How do I call a method with signature a{sv}

Open jalfd opened this issue 8 years ago • 3 comments

I have a separate application which exposes a DBus interface with a few methods I would like to call via node-dbus.

One of the methods, func, takes an argument with the DBus signature "a{sv}", and I'm not sure how node-dbus expects such a parameter to be passed. My naive expectation was that I would simply pass a JavaScript object and it would be serialized correctly:

myinterface.func({a: "foo", b: "bar", c: 42}, function(err, result) {...})

and while this does actually call the method, the other application receives an empty array as an argument, so clearly it's not as simple as that.

So what do I do instead?

jalfd avatar Sep 28 '16 13:09 jalfd

We really want to allow {a: "foo", b: "bar", c: 42} to be used for "a{sv}" but at the moment it's quite verbose, you have to go through each step in the tree: top level structure, array, string, variant.

[ // top level struct is js array
  [ // array is js array
    ['a', ['s', 'foo']], // dict_entry is 2 element array - key,value
    ['b', ['s', 'bar']], //   variant is [signature, data]
    ['c', ['n', 42]]
  ]
]

sidorares avatar Sep 28 '16 13:09 sidorares

As @sidorares said, we are currently working on making it possible to return "real" Javascript object, but this is not yet possible. I sugges you take a look at this file which is an example file I pushed recently showing how to return some of the most commons types. Ironically I've just noticed that I have forgotten the variant type! But at least this will give you and idea of how to return an array, a struct, a dict, etc. When you understand this, just think, as @sidorares suggested, that (variant) = [signature, type]. So if your variant is actually an int32, it should be represented as ['i', 2392]. That's all :-)

nschoe avatar Sep 28 '16 16:09 nschoe

Has the "return a real javascript object" feature been added yet? Thanks!

convintel avatar Oct 24 '18 20:10 convintel