+#! /usr/bin/env python
+# UCC Door Server - hardware interface server
+# reads status of reed switches and provides a D-BUS interface to read them
+# Released under an MIT-style license; see COPYING for details.
+
+# statuses: 1 means open circuit, 0 means closed circuit, -1 means error
+
+import dbus, dbus.service
+import gobject
+
+class Door(dbus.service.Object):
+
+ def __init__(self, doorname, bus):
+ self.interval = 10 # seconds
+ self.service = doorname
+ self.status = -1
+
+ # set up D-BUS service name
+ object_path = '/au/asn/ucc/doors/%s' % doorname
+ dbus.service.Object.__init__(self, bus, object_path)
+
+ # get initial state
+ self.poll()
+
+ def poll(self):
+ # check LAT
+ # XXX to be added
+
+ newstatus = -1
+ if newstatus != self.status:
+ self.status = newstatus
+ # emit signal
+ # XXX to be added
+
+ # set up timeout again
+ gobject.timeout_add_seconds(self.interval, self.poll)
+
+ @dbus.service.method('au.asn.ucc.DoorInterface', in_signature='',
+ out_signature='n')
+ def get_status(self):
+ return self.status
+
+if __name__ == '__main__':
+ doors = ('uccdoor', 'unisfadoor', 'chdoor', 'mrdoor', 'uccpir')
+
+ from dbus.mainloop.glib import DBusGMainLoop
+ DBusGMainLoop(set_as_default=True)
+ # get on the bus
+ system_bus = dbus.SystemBus()
+ system_bus.request_name('au.asn.ucc.DoorServer')
+
+ door_objects = []
+
+ for door in doors:
+ door_objects.append(Door(door, system_bus))
+
+ # engage!
+ loop = gobject.MainLoop()
+ try:
+ loop.run()
+ except KeyboardInterrupt:
+ loop.quit()
+ except:
+ pass