blob: 45c1b922f8bcca761c7a8a2faad002f4f78e526e [file] [log] [blame]
Norman James323ed972015-12-09 09:06:37 -06001#!/usr/bin/python -u
2
3import sys
4import os
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
Brad Bishopee1b1542016-05-12 16:55:00 -04009import obmc.sensors
Brad Bishop84e73b52016-05-12 15:57:52 -040010from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
Brad Bishop0b380f72016-06-10 00:29:50 -040011import obmc_system_config as System
Yi Li54decc82016-05-05 17:42:56 +080012
Norman James323ed972015-12-09 09:06:37 -060013DBUS_NAME = 'org.openbmc.Sensors'
14OBJ_PATH = '/org/openbmc/sensors'
15
16
Brad Bishop84e73b52016-05-12 15:57:52 -040017class SensorManager(DbusProperties,DbusObjectManager):
Norman James323ed972015-12-09 09:06:37 -060018 def __init__(self,bus,name):
Brad Bishop84e73b52016-05-12 15:57:52 -040019 DbusProperties.__init__(self)
20 DbusObjectManager.__init__(self)
Norman James323ed972015-12-09 09:06:37 -060021 dbus.service.Object.__init__(self,bus,name)
Norman James323ed972015-12-09 09:06:37 -060022
23 @dbus.service.method(DBUS_NAME,
24 in_signature='ss', out_signature='')
25 def register(self,object_name,obj_path):
26 if (self.objects.has_key(obj_path) == False):
27 print "Register: "+object_name+" : "+obj_path
Brad Bishopee1b1542016-05-12 16:55:00 -040028 sensor = eval('obmc.sensors.'+object_name+'(bus,obj_path)')
Norman James323ed972015-12-09 09:06:37 -060029 self.add(obj_path,sensor)
30
31 @dbus.service.method(DBUS_NAME,
32 in_signature='s', out_signature='')
33 def delete(self,obj_path):
34 if (self.objects.has_key(obj_path) == True):
35 print "Delete: "+obj_path
36 self.remove(obj_path)
37
38 def SensorChange(self,value,path=None):
39 if (self.objects.has_key(path)):
40 self.objects[path].setValue(value)
41 else:
42 print "ERROR: Sensor not found: "+path
43
44if __name__ == '__main__':
45 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -040046 bus = get_dbus()
Norman James323ed972015-12-09 09:06:37 -060047 root_sensor = SensorManager(bus,OBJ_PATH)
48
49
50 ## instantiate non-polling sensors
51 ## these don't need to be in seperate process
Yi Li54decc82016-05-05 17:42:56 +080052 for (id, the_sensor) in System.MISC_SENSORS.items():
53 sensor_class = the_sensor['class']
54 obj_path = System.ID_LOOKUP['SENSOR'][id]
Brad Bishopee1b1542016-05-12 16:55:00 -040055 sensor_obj = getattr(obmc.sensors, sensor_class)(bus, obj_path)
Yi Li54decc82016-05-05 17:42:56 +080056 if 'os_path' in the_sensor:
57 sensor_obj.sysfs_attr = the_sensor['os_path']
58 root_sensor.add(obj_path, sensor_obj)
Norman James323ed972015-12-09 09:06:37 -060059
60 mainloop = gobject.MainLoop()
Brad Bishopf0f3efe2016-06-29 23:20:24 -040061
62 root_sensor.unmask_signals()
Brad Bishop70852a32016-06-29 22:58:51 -040063 name = dbus.service.BusName(DBUS_NAME,bus)
Norman James323ed972015-12-09 09:06:37 -060064 print "Starting sensor manager"
65 mainloop.run()
66