blob: c1a3204496e1ffe0fc12c6abde9237d797775426 [file] [log] [blame]
Brad Bishop670f2552016-08-30 19:12:54 -04001#!/usr/bin/env python
Norman James323ed972015-12-09 09:06:37 -06002
Norman James323ed972015-12-09 09:06:37 -06003import gobject
4import dbus
5import dbus.service
6import dbus.mainloop.glib
Brad Bishopee1b1542016-05-12 16:55:00 -04007import obmc.sensors
Brad Bishop84e73b52016-05-12 15:57:52 -04008from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
Brad Bishop0b380f72016-06-10 00:29:50 -04009import obmc_system_config as System
Yi Li54decc82016-05-05 17:42:56 +080010
Norman James323ed972015-12-09 09:06:37 -060011DBUS_NAME = 'org.openbmc.Sensors'
12OBJ_PATH = '/org/openbmc/sensors'
13
14
Brad Bishop670f2552016-08-30 19:12:54 -040015class 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 James323ed972015-12-09 09:06:37 -060020
Brad Bishop670f2552016-08-30 19:12:54 -040021 @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 James323ed972015-12-09 09:06:37 -060028
Brad Bishop670f2552016-08-30 19:12:54 -040029 @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 James323ed972015-12-09 09:06:37 -060042if __name__ == '__main__':
Brad Bishop670f2552016-08-30 19:12:54 -040043 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
44 bus = get_dbus()
45 root_sensor = SensorManager(bus, OBJ_PATH)
Norman James323ed972015-12-09 09:06:37 -060046
Brad Bishop670f2552016-08-30 19:12:54 -040047 ## 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 James323ed972015-12-09 09:06:37 -060056
Brad Bishop670f2552016-08-30 19:12:54 -040057 mainloop = gobject.MainLoop()
Norman James323ed972015-12-09 09:06:37 -060058
Brad Bishop670f2552016-08-30 19:12:54 -040059 root_sensor.unmask_signals()
60 name = dbus.service.BusName(DBUS_NAME, bus)
61 print "Starting sensor manager"
62 mainloop.run()