Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | |
| 3 | import sys |
| 4 | import os |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import Openbmc |
| 10 | import Sensors |
| 11 | |
Yi Li | 54decc8 | 2016-05-05 17:42:56 +0800 | [diff] [blame] | 12 | System = __import__(sys.argv[1]) |
| 13 | |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 14 | DBUS_NAME = 'org.openbmc.Sensors' |
| 15 | OBJ_PATH = '/org/openbmc/sensors' |
| 16 | |
| 17 | |
| 18 | class SensorManager(Openbmc.DbusProperties,Openbmc.DbusObjectManager): |
| 19 | def __init__(self,bus,name): |
| 20 | Openbmc.DbusProperties.__init__(self) |
| 21 | Openbmc.DbusObjectManager.__init__(self) |
| 22 | dbus.service.Object.__init__(self,bus,name) |
| 23 | self.InterfacesAdded(name,self.properties) |
| 24 | |
| 25 | @dbus.service.method(DBUS_NAME, |
| 26 | in_signature='ss', out_signature='') |
| 27 | def register(self,object_name,obj_path): |
| 28 | if (self.objects.has_key(obj_path) == False): |
| 29 | print "Register: "+object_name+" : "+obj_path |
| 30 | sensor = eval('Sensors.'+object_name+'(bus,obj_path)') |
| 31 | self.add(obj_path,sensor) |
| 32 | |
| 33 | @dbus.service.method(DBUS_NAME, |
| 34 | in_signature='s', out_signature='') |
| 35 | def delete(self,obj_path): |
| 36 | if (self.objects.has_key(obj_path) == True): |
| 37 | print "Delete: "+obj_path |
| 38 | self.remove(obj_path) |
| 39 | |
| 40 | def SensorChange(self,value,path=None): |
| 41 | if (self.objects.has_key(path)): |
| 42 | self.objects[path].setValue(value) |
| 43 | else: |
| 44 | print "ERROR: Sensor not found: "+path |
| 45 | |
| 46 | if __name__ == '__main__': |
| 47 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 48 | bus = Openbmc.getDBus() |
| 49 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 50 | root_sensor = SensorManager(bus,OBJ_PATH) |
| 51 | |
| 52 | |
| 53 | ## instantiate non-polling sensors |
| 54 | ## these don't need to be in seperate process |
Yi Li | 54decc8 | 2016-05-05 17:42:56 +0800 | [diff] [blame] | 55 | for (id, the_sensor) in System.MISC_SENSORS.items(): |
| 56 | sensor_class = the_sensor['class'] |
| 57 | obj_path = System.ID_LOOKUP['SENSOR'][id] |
| 58 | sensor_obj = getattr(Sensors, sensor_class)(bus, obj_path) |
| 59 | if 'os_path' in the_sensor: |
| 60 | sensor_obj.sysfs_attr = the_sensor['os_path'] |
| 61 | root_sensor.add(obj_path, sensor_obj) |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 62 | |
| 63 | mainloop = gobject.MainLoop() |
| 64 | print "Starting sensor manager" |
| 65 | mainloop.run() |
| 66 | |