--- /dev/null
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null
+#! /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