client-signal.py: example client that listens for signals
authorDavid Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>
Mon, 7 Sep 2009 14:33:19 +0000 (22:33 +0800)
committerDavid Adam (zanchey) <zanchey@ucc.gu.uwa.edu.au>
Tue, 13 Oct 2009 14:38:46 +0000 (22:38 +0800)
client-signal.py [new file with mode: 0644]

diff --git a/client-signal.py b/client-signal.py
new file mode 100644 (file)
index 0000000..ba0da59
--- /dev/null
@@ -0,0 +1,36 @@
+# UCC Door Server - example synchronous client
+# David Adam <zanchey@ucc.gu.uwa.edu.au>
+# 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

UCC git Repository :: git.ucc.asn.au