blob: 222b28bcb86736b19cfc8513c590bf707610363b [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001#!/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
8from gi.repository import GLib
9from pydbus import SessionBus
10
11loop = GLib.MainLoop()
12
13class 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
41bus = SessionBus()
42bus.publish("net.lew21.pydbus.ClientServerExample", MyDBUSService())
43loop.run()
44