Fri 22 Apr 2005
The bindings are almost to the point I where I want to commit them. Methods took me a bit to get right and I want to start moving some of the code from the helper function to the decorator itself. After figuring out the details of decorators I was able to whip up the signal stuff in five minutes at the end of the day. I need to get this stuff working with hal_device_manager and then I can commit. I can even implement the Introspection interface fairly quickly I think. Marshling with introspection data will take a bit longer but that is all internal stuff that developers don’t need to worry about.
The biggest problem right now is a bug in DBus which does not send messages over the bus if they have a NULL interface. For some reason this works fine with the org.freedesktop.DBus service but with every other service method calls just hang until they time out.
Here is the test class I have been using for your viewing pleasure:
import dbus
import gtk
class SomeObject(dbus.Object):
def __init__(self, service):
dbus.Object.__init__(self, '/SomeObject', service)
@dbus.method('org.designfu.SampleInterface')
def HelloWorld(self, hello_message):
print (str(hello_message))
return ['Hello', ' from example-service.py']
@dbus.method('org.designfu.SampleInterface')
def GetDict(self):
return {'first': 'Hello Dict', 'second': ' from example-service.py'}
class SomeInheritedObject(SomeObject):
@dbus.method('org.designfu.SampleInterface.Tuple')
def HelloWorld(self):
return ('Hello Tuple', ' from example-service.py')
@dbus.signal('org.designfu.SignalInterface')
def HelloSignal(self, msg):
pass
session_bus = dbus.SessionBus()
service = dbus.Service('org.designfu.SampleService', bus=session_bus)
object = SomeInheritedObject(service)
#emit the signal
object.HelloSignal("Well hello")
gtk.main()
And the test client:
import dbus
import gtk
bus = dbus.SessionBus()
sys_bus = dbus.SystemBus()
remote_object = bus.get_object('org.designfu.SampleService', '/SomeObject')
iface = dbus.Interface(remote_object, 'org.designfu.SampleInterface.Tuple')
dbus_obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
hal_obj = sys_bus.get_object('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')
#this will timeout if we don't give it an interface
drives = hal_obj.FindDeviceByCapability('storage.cdrom', dbus_interface='org.freedesktop.Hal.Manager')
print str(drives)
#this will succeed even without the interface
print dbus_obj.ListNames()
def do_print(value):
print str(value)
def do_error(e):
print str(e)
hello_reply_tuple = iface.HelloWorld(reply_handler=do_print, error_handler=do_error)
hello_reply_list = remote_object.HelloWorld('Hello from example-client.py!', reply_handler=do_print, error_handler=do_error, dbus_interface='org.designfu.SampleInterface')
#this times out because of the bug
hello_reply_dict = remote_object.GetDict(reply_handler=do_print, error_handler=do_error)
gtk.main()
I know the examples were there just to test what I was writting and arn’t in the nicest form. Rest assured when I am done I will have a bunch of useful realworld examples for people to learn from. I am hoping to get the bindings to the point where writting dbus services and clients is a pleasurable experience. I know my work on these bindings have brought me back to my hacking roots where learning little tricks and solving problems in a clever way is almost like a game. It brings back the wonder and fun that got me into programming in the first place.
[read this post in: ar de es fr it ja ko pt ru zh-CN ]