blob: 619e8e5a244e359ef69699caa9a435b02f146abc [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
9import Openbmc
10import Sensors
11
Yi Li54decc82016-05-05 17:42:56 +080012System = __import__(sys.argv[1])
13
Norman James323ed972015-12-09 09:06:37 -060014DBUS_NAME = 'org.openbmc.Sensors'
15OBJ_PATH = '/org/openbmc/sensors'
16
17
18class SensorManager(Openbmc.DbusProperties,Openbmc.DbusObjectManager):
19 def __init__(self,bus,name):
20 Openbmc.DbusProperties.__init__(self)
21 Openbmc.DbusObjectManager.__init__(self)
22 dbus.service.Object.__init__(self,bus,name)
23 self.InterfacesAdded(name,self.properties)
24
25 @dbus.service.method(DBUS_NAME,
26 in_signature='ss', out_signature='')
27 def register(self,object_name,obj_path):
28 if (self.objects.has_key(obj_path) == False):
29 print "Register: "+object_name+" : "+obj_path
30 sensor = eval('Sensors.'+object_name+'(bus,obj_path)')
31 self.add(obj_path,sensor)
32
33 @dbus.service.method(DBUS_NAME,
34 in_signature='s', out_signature='')
35 def delete(self,obj_path):
36 if (self.objects.has_key(obj_path) == True):
37 print "Delete: "+obj_path
38 self.remove(obj_path)
39
40 def SensorChange(self,value,path=None):
41 if (self.objects.has_key(path)):
42 self.objects[path].setValue(value)
43 else:
44 print "ERROR: Sensor not found: "+path
45
46if __name__ == '__main__':
47 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
48 bus = Openbmc.getDBus()
49 name = dbus.service.BusName(DBUS_NAME,bus)
50 root_sensor = SensorManager(bus,OBJ_PATH)
51
52
53 ## instantiate non-polling sensors
54 ## these don't need to be in seperate process
Yi Li54decc82016-05-05 17:42:56 +080055 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(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
63 mainloop = gobject.MainLoop()
64 print "Starting sensor manager"
65 mainloop.run()
66