Norman James | fa2e76e | 2015-08-26 17:41:20 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import gobject |
| 4 | import dbus |
| 5 | import dbus.service |
| 6 | import dbus.mainloop.glib |
| 7 | import System |
| 8 | |
| 9 | DBUS_NAME = 'org.openbmc.managers.Gpios' |
| 10 | OBJ_NAME = '/org/openbmc/managers/Gpios' |
| 11 | |
| 12 | gpio_config = System.BarreleyeGpios() |
| 13 | gpio_dev = '/sys/class/gpio' |
| 14 | |
| 15 | class GpioManager(dbus.service.Object): |
| 16 | def __init__(self,bus,name): |
| 17 | dbus.service.Object.__init__(self,bus,name) |
| 18 | bus = dbus.SessionBus() |
| 19 | self.gpio_locks = {} |
| 20 | |
| 21 | |
| 22 | @dbus.service.method(DBUS_NAME, |
| 23 | in_signature='s', out_signature='sis') |
| 24 | def init(self,name): |
| 25 | gpio_path = '' |
| 26 | if (gpio_config.has_key(name) == False): |
| 27 | # TODO: Error handling |
| 28 | print "ERROR: "+name+" not found in GPIO config table" |
| 29 | else: |
| 30 | gpio_num = gpio_config[name]['gpio_num'] |
| 31 | print "GPIO Lookup: "+name+" = "+str(gpio_num) |
| 32 | |
| 33 | return [gpio_dev, gpio_num, gpio_config[name]['direction']] |
| 34 | |
| 35 | @dbus.service.method(DBUS_NAME, |
| 36 | in_signature='s', out_signature='') |
| 37 | def open(self,name): |
| 38 | gpio_num = gpio_config[name]['gpio_num'] |
| 39 | self.gpio_locks[gpio_num] = 1 |
| 40 | |
| 41 | @dbus.service.method(DBUS_NAME, |
| 42 | in_signature='s', out_signature='') |
| 43 | def close(self,name): |
| 44 | # unexport? |
| 45 | gpio_num = gpio_config[name]['gpio_num'] |
| 46 | self.gpio_locks[gpio_num] = 0 |
| 47 | |
| 48 | |
| 49 | ## Signal handler |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 54 | |
| 55 | bus = dbus.SessionBus() |
| 56 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 57 | obj = GpioManager(bus, OBJ_NAME) |
| 58 | mainloop = gobject.MainLoop() |
| 59 | |
| 60 | print "Running GpioManager" |
| 61 | mainloop.run() |
| 62 | |