blob: e0a264e0fadd964c2a4a8d45cf9285b57fe7b614 [file] [log] [blame]
Norman Jamesfa2e76e2015-08-26 17:41:20 -05001#!/usr/bin/env python
2
3import gobject
4import dbus
5import dbus.service
6import dbus.mainloop.glib
7import System
8
9DBUS_NAME = 'org.openbmc.managers.Gpios'
10OBJ_NAME = '/org/openbmc/managers/Gpios'
11
12gpio_config = System.BarreleyeGpios()
13gpio_dev = '/sys/class/gpio'
14
15class 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
52if __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