I have been experimenting with dbus recently. But I can't get my dbus service to guess the correct data types for boolean values. Consider the following example:
import gtk
import dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
class Service(dbus.service.Object):
def __init__(self):
bus_name = dbus.service.BusName("org.foo.bar", bus = dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, "/org/foo/bar")
@dbus.service.method("org.foo.bar", in_signature = "a{sa{sv}}",
out_signature = "a{sa{sv}}")
def perform(self, data):
return data
if __name__ == "__main__":
DBusGMainLoop(set_as_default = True)
s = Service()
gtk.main()
This piece of code creates the dbus service, which provides an execution method that takes one parameter, which is a dictionary that maps from strings to other dictionaries, which in turn convert strings to variants. I chose this format because of the format in which my dictionaries are located:
{
"key1": {
"type": ("tuple", "value")
},
"key2": {
"name": "John Doe",
"gender": "male",
"age": 23
},
"test": {
"true-property": True,
"false-property": False
}
}
When I pass this dictionary through my service, the boolean values are converted to integers. In my opinion, verification should not be so complicated. Consider this ( value- a variable that must be converted to a dbus type):
if isinstance(value, bool):
return dbus.Boolean(value)
isinstance(value, int), .
?