Yesterday night, I sat down at my box and decided to hack a bit of DBUS. My aim was to send a string across, do something and send something back. More correctly, RPC over D-BUS. Here's the code in python (server and client).
def helloworld(msg): return "Hello World"; obj = dbus.Object("/t3/s1", dbus.Service("t3.s1"),[helloworld]) gtk.main() # mainloop
bus = dbus.Bus(dbus.Bus.TYPE_SESSION) obj = bus.get_service('t3.s1').get_object('/t3/s1', 't3.s1') print obj.helloworld()
Pretty simple, huh ? Here's a link to a more functional version - with things like passing data structures via the RPC api. D-BUS looks a lot more promising than using Orbit2 brokers. I have to see how functional this is for multi-user systems, where ICE made sense (and DCOP).
And for those six lines - I'd have used lamda: "Hello World"; in place of the method and cut down a line. But the remote method name is picked up from the __name__ of the method (for lambda it turns out to be '<lambda>'). Python really rocks if you want method meta-data.