Vizible’s Blog

Simple DBus App

Posted in Programming by wearetherock on January 24, 2009

test_server.py

import dbus
import dbus.service
import dbus.mainloop.glib
import gobject

class Test(dbus.service.Object):
  
  @dbus.service.method("com.example.MyInterface",in_signature="", out_signature="s")
  def hello_world(self):
    return 'Hello, world'
    
if __name__ == '__main__' :
  dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
  session_bus = dbus.SessionBus()
  name = dbus.service.BusName("com.example.MyName", session_bus)
  object = Test(session_bus, '/MyObject', name)
  
  mainloop = gobject.MainLoop()
  print 'Running service ...'
  mainloop.run()
  

test_client.py

import dbus

bus = dbus.SessionBus()
remote_object = bus.get_object("com.example.MyName",
  "/MyObject")
test = dbus.Interface( remote_object, "com.example.MyInterface")
text = test.hello_world()
print text
Advertisements
Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: