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 | 44d4ad9 | 2016-08-30 19:14:46 -0400 | [diff] [blame] | 9 | |
| 10 | try: |
| 11 | import obmc_system_config as System |
| 12 | has_system = True |
| 13 | except ImportError: |
| 14 | has_system = False |
Yi Li | 54decc8 | 2016-05-05 17:42:56 +0800 | [diff] [blame] | 15 | |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 16 | DBUS_NAME = 'org.openbmc.Sensors' |
| 17 | OBJ_PATH = '/org/openbmc/sensors' |
| 18 | |
| 19 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 20 | class SensorManager(DbusProperties, DbusObjectManager): |
| 21 | def __init__(self, bus, name): |
Brad Bishop | f47f5fa | 2016-09-08 22:29:01 -0400 | [diff] [blame] | 22 | super(SensorManager, self).__init__( |
| 23 | conn=bus, |
| 24 | object_path=name) |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 25 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 26 | @dbus.service.method( |
| 27 | DBUS_NAME, in_signature='ss', out_signature='') |
| 28 | def register(self, object_name, obj_path): |
| 29 | if obj_path not in self.objects: |
| 30 | print "Register: "+object_name+" : "+obj_path |
| 31 | sensor = eval('obmc.sensors.'+object_name+'(bus,obj_path)') |
| 32 | self.add(obj_path, sensor) |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 33 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 34 | @dbus.service.method( |
| 35 | DBUS_NAME, in_signature='s', out_signature='') |
| 36 | def delete(self, obj_path): |
| 37 | if obj_path in self.objects: |
| 38 | print "Delete: "+obj_path |
| 39 | self.remove(obj_path) |
| 40 | |
| 41 | def SensorChange(self, value, path=None): |
| 42 | if path in self.objects: |
| 43 | self.objects[path].setValue(value) |
| 44 | else: |
| 45 | print "ERROR: Sensor not found: "+path |
| 46 | |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 47 | if __name__ == '__main__': |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 48 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 49 | bus = get_dbus() |
| 50 | root_sensor = SensorManager(bus, OBJ_PATH) |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 51 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 52 | ## instantiate non-polling sensors |
| 53 | ## these don't need to be in seperate process |
Brad Bishop | 44d4ad9 | 2016-08-30 19:14:46 -0400 | [diff] [blame] | 54 | if has_system: |
| 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(obmc.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 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 63 | mainloop = gobject.MainLoop() |
Norman James | 323ed97 | 2015-12-09 09:06:37 -0600 | [diff] [blame] | 64 | |
Brad Bishop | 670f255 | 2016-08-30 19:12:54 -0400 | [diff] [blame] | 65 | root_sensor.unmask_signals() |
| 66 | name = dbus.service.BusName(DBUS_NAME, bus) |
| 67 | print "Starting sensor manager" |
| 68 | mainloop.run() |
Brad Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 69 | |
| 70 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |