blob: be8a04b9f0a52e76197bca95151deca28f60cfba [file] [log] [blame]
Ed Tanousc9b55212017-06-12 13:25:51 -07001# Copyright (c) Benjamin Kietzman (github.com/bkietz)
2#
3# Distributed under the Boost Software License, Version 1.0. (See accompanying
4# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6import dbus
7import dbus.service
8from dbus.mainloop.glib import DBusGMainLoop
9from gobject import MainLoop
10
11bus_name = 'com.example.Sample'
12
13class Example(dbus.service.Object):
14 def __init__(self, connection, path):
15 dbus.service.Object.__init__(self, connection, path)
16 self._last_input = None
17
18 @dbus.service.method(bus_name+'.Iface', in_signature='v', out_signature='s')
19 def StringifyVariant(self, var):
20 self.LastInputChanged(var) # emits the signal
21 return str(var)
22
23 @dbus.service.signal(bus_name+'.Iface', signature='v')
24 def LastInputChanged(self, var):
25 # run just before the signal is actually emitted
26 # just put "pass" if nothing should happen
27 self._last_input = var
28
29 @dbus.service.method(bus_name+'.Iface', in_signature='', out_signature='v')
30 def GetLastInput(self):
31 return self._last_input
32
33bus = dbus.SessionBus(mainloop=DBusGMainLoop())
34bus.request_name(bus_name)
35
36example = Example(bus, '/path/to/obj')
37
38print bus.get_name_owner(bus_name)
39MainLoop().run()