-
-
Save cknoll/f5ef77f30b1b2f115e0a12f99cd507ab to your computer and use it in GitHub Desktop.
Simple client-service dbus example in python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import dbus | |
class Client(): | |
def __init__(self): | |
bus = dbus.SessionBus() | |
service = bus.get_object('com.example.service', "/com/example/service") | |
self._message = service.get_dbus_method('get_message', 'com.example.service.Message') | |
self._quit = service.get_dbus_method('quit', 'com.example.service.Quit') | |
def run(self): | |
print "Mesage from service:", self._message() | |
self._quit() | |
if __name__ == "__main__": | |
Client().run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import dbus | |
import dbus.service | |
import dbus.mainloop.glib | |
import gobject | |
class Service(dbus.service.Object): | |
def __init__(self, message): | |
self._message = message | |
def run(self): | |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
bus_name = dbus.service.BusName("com.example.service", dbus.SessionBus()) | |
dbus.service.Object.__init__(self, bus_name, "/com/example/service") | |
self._loop = gobject.MainLoop() | |
print "Service running..." | |
self._loop.run() | |
print "Service stopped" | |
@dbus.service.method("com.example.service.Message", in_signature='', out_signature='s') | |
def get_message(self): | |
print " sending message" | |
return self._message | |
@dbus.service.method("com.example.service.Quit", in_signature='', out_signature='') | |
def quit(self): | |
print " shutting down" | |
self._loop.quit() | |
if __name__ == "__main__": | |
Service("This is the service").run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment