Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | # Based on http://stackoverflow.com/questions/22390064/use-dbus-to-just-send-a-message-in-python |
| 4 | |
| 5 | # Python DBUS Test Server |
| 6 | # runs until the Quit() method is called via DBUS |
| 7 | |
| 8 | from gi.repository import GLib |
| 9 | from pydbus import SessionBus |
| 10 | |
| 11 | loop = GLib.MainLoop() |
| 12 | |
| 13 | class MyDBUSService(object): |
| 14 | """ |
| 15 | <node> |
| 16 | <interface name='net.lew21.pydbus.ClientServerExample'> |
| 17 | <method name='Hello'> |
| 18 | <arg type='s' name='response' direction='out'/> |
| 19 | </method> |
| 20 | <method name='EchoString'> |
| 21 | <arg type='s' name='a' direction='in'/> |
| 22 | <arg type='s' name='response' direction='out'/> |
| 23 | </method> |
| 24 | <method name='Quit'/> |
| 25 | </interface> |
| 26 | </node> |
| 27 | """ |
| 28 | |
| 29 | def Hello(self): |
| 30 | """returns the string 'Hello, World!'""" |
| 31 | return "Hello, World!" |
| 32 | |
| 33 | def EchoString(self, s): |
| 34 | """returns whatever is passed to it""" |
| 35 | return s |
| 36 | |
| 37 | def Quit(self): |
| 38 | """removes this object from the DBUS connection and exits""" |
| 39 | loop.quit() |
| 40 | |
| 41 | bus = SessionBus() |
| 42 | bus.publish("net.lew21.pydbus.ClientServerExample", MyDBUSService()) |
| 43 | loop.run() |
| 44 | |