From: David Adam (zanchey) Date: Mon, 7 Sep 2009 14:33:19 +0000 (+0800) Subject: client-signal.py: example client that listens for signals X-Git-Url: https://git.ucc.asn.au/?p=uccdoor.git;a=commitdiff_plain;h=d54b8e2dbac774ec1a9074777da0bdca3ccbde46 client-signal.py: example client that listens for signals --- diff --git a/client-signal.py b/client-signal.py new file mode 100644 index 0000000..ba0da59 --- /dev/null +++ b/client-signal.py @@ -0,0 +1,36 @@ +# UCC Door Server - example synchronous client +# David Adam +# Released under an MIT-style license; see COPYING for details. + +import dbus +import gobject + +def signal_handler(new_status, path): + door = path.split('/')[-1:][0] + # globals! + if door in doors: + print "Received new status %d from %s" % (new_status, door) + +if __name__ == '__main__': + + from dbus.mainloop.glib import DBusGMainLoop + DBusGMainLoop(set_as_default=True) + # get on the bus + system_bus = dbus.SystemBus() + + doors = {'uccdoor': None, 'unisfadoor': None, 'chdoor': None, 'mrdoor': None, 'uccpir': None} + + # According to the D-BUS documentation, you shouldn't create an object just + # to listen to a signal, as this may cause server activation. However, your + # client might like to do more clever things with the object. + for door in doors.keys(): + doors[door] = system_bus.get_object('au.asn.ucc.DoorServer', '/au/asn/ucc/doors/%s' % door) + + for door, remote_object in doors.items(): + remote_object.connect_to_signal('status_changed', signal_handler, + dbus_interface='au.asn.ucc.DoorInterface', + path_keyword='path') + + # engage! + loop = gobject.MainLoop() + loop.run() \ No newline at end of file