#! /usr/bin/python2.4
import gobject
import dbus
import dbus.service
import dbus.glib # (Only if python binding version >= 0.41.0)
class Obj(dbus.service.Object):
"""Sample object exported over D-Bus.
"""
# Initialize the dbus.service.Object with our "bus name" (i.e. the name
# of our connection, not of the bus!) and the path identifying the
# object within that connection.
def __init__(self, bus_name, object_path):
dbus.service.Object.__init__(self, bus_name, object_path)
# Anotation: export following method on D-Bus, under given interface
@dbus.service.method('org.me.HelloInterface')
def hi(self, text):
# Return value will be sent to the invoker across D-Bus.
print "hello here" + text
return "Hello there"
@dbus.service.method('org.me.HelloInterface')
def fail(self):
# Exceptions, too, are propagated to the invoker across D-Bus.
print "ohh, this fails"
raise Exception, 'Aaaaargh!'
# Find a bus to export our object on--in this case, the user's session bus.
session_bus = dbus.SessionBus()
# Request a well-known name for our connection: "org.me"
bus_name = dbus.service.BusName('org.me', bus=session_bus)
# Create an Obj, exporting it under the object path '/org/me/test'
obj = Obj(bus_name, '/org/me/test')
# Enter main event loop
gobject.MainLoop().run()