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