blob: 8273225380855490f01490b5590f152571e52ba7 [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 Bishop44d4ad92016-08-30 19:14:46 -04009
10try:
11 import obmc_system_config as System
12 has_system = True
13except ImportError:
14 has_system = False
Yi Li54decc82016-05-05 17:42:56 +080015
Norman James323ed972015-12-09 09:06:37 -060016DBUS_NAME = 'org.openbmc.Sensors'
17OBJ_PATH = '/org/openbmc/sensors'
18
19
Brad Bishop670f2552016-08-30 19:12:54 -040020class SensorManager(DbusProperties, DbusObjectManager):
21 def __init__(self, bus, name):
Brad Bishopf47f5fa2016-09-08 22:29:01 -040022 super(SensorManager, self).__init__(
23 conn=bus,
24 object_path=name)
Norman James323ed972015-12-09 09:06:37 -060025
Brad Bishop670f2552016-08-30 19:12:54 -040026 @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 James323ed972015-12-09 09:06:37 -060033
Brad Bishop670f2552016-08-30 19:12:54 -040034 @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 James323ed972015-12-09 09:06:37 -060047if __name__ == '__main__':
Brad Bishop670f2552016-08-30 19:12:54 -040048 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
49 bus = get_dbus()
50 root_sensor = SensorManager(bus, OBJ_PATH)
Norman James323ed972015-12-09 09:06:37 -060051
Brad Bishop670f2552016-08-30 19:12:54 -040052 ## instantiate non-polling sensors
53 ## these don't need to be in seperate process
Brad Bishop44d4ad92016-08-30 19:14:46 -040054 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 James323ed972015-12-09 09:06:37 -060062
Brad Bishop670f2552016-08-30 19:12:54 -040063 mainloop = gobject.MainLoop()
Norman James323ed972015-12-09 09:06:37 -060064
Brad Bishop670f2552016-08-30 19:12:54 -040065 root_sensor.unmask_signals()
66 name = dbus.service.BusName(DBUS_NAME, bus)
67 print "Starting sensor manager"
68 mainloop.run()
Brad Bishop53066752016-09-21 08:48:04 -040069
70# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4