From 446ae2bd2f559e56ffc35ada410f55dabb7d996c Mon Sep 17 00:00:00 2001 From: "David Adam (zanchey)" Date: Mon, 7 Sep 2009 21:29:29 +0800 Subject: [PATCH 1/1] initial import of D-BUS server --- COPYING | 18 +++++++++++++++ server.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 COPYING create mode 100755 server.py diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..4e2fff4 --- /dev/null +++ b/COPYING @@ -0,0 +1,18 @@ +Copyright (c) 2009 David Adam + +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. diff --git a/server.py b/server.py new file mode 100755 index 0000000..f0d1336 --- /dev/null +++ b/server.py @@ -0,0 +1,65 @@ +#! /usr/bin/env python +# UCC Door Server - hardware interface server +# reads status of reed switches and provides a D-BUS interface to read them +# David Adam +# 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 -- 2.20.1