blob: cffabaadb4e613b3098c4262241a6a2c5b5c8b34 [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
Norman James323ed972015-12-09 09:06:37 -06009import Sensors
Brad Bishop84e73b52016-05-12 15:57:52 -040010from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
Norman James323ed972015-12-09 09:06:37 -060011
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
Brad Bishop84e73b52016-05-12 15:57:52 -040018class SensorManager(DbusProperties,DbusObjectManager):
Norman James323ed972015-12-09 09:06:37 -060019 def __init__(self,bus,name):
Brad Bishop84e73b52016-05-12 15:57:52 -040020 DbusProperties.__init__(self)
21 DbusObjectManager.__init__(self)
Norman James323ed972015-12-09 09:06:37 -060022 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)
Brad Bishop84e73b52016-05-12 15:57:52 -040048 bus = get_dbus()
Norman James323ed972015-12-09 09:06:37 -060049 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