blob: 34ea0fcb11cd7c4a46d6217c173728a9182bb636 [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)
22 self.InterfacesAdded(name,self.properties)
23
24 @dbus.service.method(DBUS_NAME,
25 in_signature='ss', out_signature='')
26 def register(self,object_name,obj_path):
27 if (self.objects.has_key(obj_path) == False):
28 print "Register: "+object_name+" : "+obj_path
Brad Bishopee1b1542016-05-12 16:55:00 -040029 sensor = eval('obmc.sensors.'+object_name+'(bus,obj_path)')
Norman James323ed972015-12-09 09:06:37 -060030 self.add(obj_path,sensor)
31
32 @dbus.service.method(DBUS_NAME,
33 in_signature='s', out_signature='')
34 def delete(self,obj_path):
35 if (self.objects.has_key(obj_path) == True):
36 print "Delete: "+obj_path
37 self.remove(obj_path)
38
39 def SensorChange(self,value,path=None):
40 if (self.objects.has_key(path)):
41 self.objects[path].setValue(value)
42 else:
43 print "ERROR: Sensor not found: "+path
44
45if __name__ == '__main__':
46 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -040047 bus = get_dbus()
Norman James323ed972015-12-09 09:06:37 -060048 root_sensor = SensorManager(bus,OBJ_PATH)
49
50
51 ## instantiate non-polling sensors
52 ## these don't need to be in seperate process
Yi Li54decc82016-05-05 17:42:56 +080053 for (id, the_sensor) in System.MISC_SENSORS.items():
54 sensor_class = the_sensor['class']
55 obj_path = System.ID_LOOKUP['SENSOR'][id]
Brad Bishopee1b1542016-05-12 16:55:00 -040056 sensor_obj = getattr(obmc.sensors, sensor_class)(bus, obj_path)
Yi Li54decc82016-05-05 17:42:56 +080057 if 'os_path' in the_sensor:
58 sensor_obj.sysfs_attr = the_sensor['os_path']
59 root_sensor.add(obj_path, sensor_obj)
Norman James323ed972015-12-09 09:06:37 -060060
61 mainloop = gobject.MainLoop()
Brad Bishop70852a32016-06-29 22:58:51 -040062 name = dbus.service.BusName(DBUS_NAME,bus)
Norman James323ed972015-12-09 09:06:37 -060063 print "Starting sensor manager"
64 mainloop.run()
65