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