lots of changes
diff --git a/bin/System/Barreleye.py b/bin/System/Barreleye.py
deleted file mode 100644
index 364a280..0000000
--- a/bin/System/Barreleye.py
+++ /dev/null
@@ -1,120 +0,0 @@
-#! /usr/bin/python
-
-def BarreleyeProcesses():
- config = {}
-
- config['org.openbmc.control.Power'] = {
- 'exe_name' : 'bin/power_control.exe',
- 'heartbeat' : 'no',
- 'instances' : [
- {
- 'name' : 'PowerControl1',
- 'user_label': 'Power control',
- }
- ]
- }
-
- config['org.openbmc.sensors.Temperature.Ambient'] = {
- 'exe_name' : 'bin/sensor_ambient.exe',
- 'heartbeat' : "yes",
- 'instances' : [
- {
- 'name' : 'AmbientTemperature1',
- 'user_label': 'Ambient Temperature 1',
- 'parameters': ['/dev/i2c0','0xA0'],
- 'poll_interval': 5000,
- 'lower_critical': 5,
- 'lower_warning' : 10,
- 'upper_warning' : 15,
- 'upper_critical': 20
- },
- {
- 'name' : 'AmbientTemperature2',
- 'user_label': 'Ambient Temperature 2',
- 'parameters': ['/dev/i2c0','0xA2'],
- 'poll_interval': 5000,
- 'lower_critical': 5,
- 'lower_warning' : 10,
- 'upper_warning' : 15,
- 'upper_critical': 20
- }
- ]
- }
- config['org.openbmc.buttons.ButtonPower'] = {
- 'exe_name' : 'bin/button_power.exe',
- 'heartbeat' : 'no',
- 'instances' : [
- {
- 'name' : 'PowerButton1',
- 'user_label': 'Main Power Button',
- }
- ]
- }
- config['org.openbmc.sensors.HostStatus'] = {
- 'exe_name' : 'bin/sensor_host_status.exe',
- 'heartbeat' : "no",
- 'instances' : [
- {
- 'name' : 'HostStatus1',
- 'user_label': 'Host Status',
- }
- ]
- }
- config['org.openbmc.leds.ChassisIdentify'] = {
- 'exe_name' : 'bin/chassis_identify.exe',
- 'heartbeat' : "no",
- 'instances' : [
- {
- 'name' : 'ChassisIdentify1',
- 'user_label': 'Chassis Identify LED',
- }
- ]
- }
- config['org.openbmc.flash.BIOS'] = {
- 'exe_name' : 'bin/flash_bios.exe',
- 'heartbeat' : "no",
- 'instances' : [
- {
- 'name' : 'BIOS1',
- 'user_label': 'BIOS SPI Flash',
- }
- ]
- }
- config['org.openbmc.control.Host'] = {
- 'exe_name' : 'bin/control_host.exe',
- 'heartbeat' : "no",
- 'instances' : [
- {
- 'name' : 'HostControl1',
- 'user_label': 'Host Control',
- }
- ]
- }
- config['org.openbmc.control.Chassis'] = {
- 'exe_name' : 'bin/chassis_control.py',
- 'heartbeat' : "no",
- 'instances' : [
- {
- 'name' : 'Chassis',
- 'user_label': 'Chassis Control',
- }
- ]
- }
-
-
- return config
-
-def BarreleyeGpios():
- gpio = {}
- gpio['FSI_CLK'] = { 'gpio_num': 23, 'direction': 'out' }
- gpio['FSI_DATA'] = { 'gpio_num': 24, 'direction': 'out' }
- gpio['FSI_ENABLE'] = { 'gpio_num': 25, 'direction': 'out' }
- gpio['POWER_PIN'] = { 'gpio_num': 26, 'direction': 'out' }
- gpio['CRONUS_SEL'] = { 'gpio_num': 27, 'direction': 'out' }
- gpio['PGOOD'] = { 'gpio_num': 28, 'direction': 'in' }
- gpio['IDENTIFY'] = { 'gpio_num': 30, 'direction': 'out' }
- gpio['POWER_BUTTON'] = { 'gpio_num': 31, 'direction': 'in' }
-
-
- return gpio
-
diff --git a/bin/System/Barreleye.pyc b/bin/System/Barreleye.pyc
deleted file mode 100644
index c79f477..0000000
--- a/bin/System/Barreleye.pyc
+++ /dev/null
Binary files differ
diff --git a/bin/System/__init__.py b/bin/System/__init__.py
deleted file mode 100644
index 0cb7ef8..0000000
--- a/bin/System/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
-from Barreleye import BarreleyeProcesses
-from Barreleye import BarreleyeGpios
diff --git a/bin/System/__init__.pyc b/bin/System/__init__.pyc
deleted file mode 100644
index 92a4920..0000000
--- a/bin/System/__init__.pyc
+++ /dev/null
Binary files differ
diff --git a/bin/chassis_control.py b/bin/chassis_control.py
index d11ab40..22c0314 100644
--- a/bin/chassis_control.py
+++ b/bin/chassis_control.py
@@ -1,42 +1,63 @@
#!/usr/bin/env python
+import sys
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
+import System
DBUS_NAME = 'org.openbmc.control.Chassis'
-OBJ_NAME = '/org/openbmc/control/Chassis'
+OBJ_NAME = '/org/openbmc/control/Chassis/'+sys.argv[1]
POWER_OFF = 0
POWER_ON = 1
+process_config = System.BarreleyeProcesses()
+
+
+
class ChassisControlObject(dbus.service.Object):
def __init__(self,bus,name):
+ self.dbus_objects = { }
+ self.dbus_busses = {
+ 'org.openbmc.control.Power' : [ { 'name' : 'PowerControl1' , 'intf' : 'org.openbmc.control.Power' } ],
+ 'org.openbmc.leds.ChassisIdentify' : [ { 'name' : 'ChassisIdentify1', 'intf' : 'org.openbmc.control.Chassis' } ],
+ 'org.openbmc.control.Host' : [ { 'name' : 'HostControl1', 'intf' : 'org.openbmc.control.Host' } ]
+ }
self.power_sequence = 0
dbus.service.Object.__init__(self,bus,name)
bus = dbus.SessionBus()
try:
- # Get PowerControl object
- power_control_service = bus.get_object('org.openbmc.control.Power','/org/openbmc/control/Power/0')
- self.power_control_iface = dbus.Interface(power_control_service, 'org.openbmc.control.Power')
- # Get ChassisIdentify object
- chassis_identify_service = bus.get_object('org.openbmc.leds.ChassisIdentify','/org/openbmc/leds/ChassisIdentify/0')
- self.identify_led_iface = dbus.Interface(chassis_identify_service, 'org.openbmc.Led');
- # Get HostControl object
- host_control_service = bus.get_object('org.openbmc.control.Host','/org/openbmc/control/Host/0')
- self.host_control_iface = dbus.Interface(host_control_service, 'org.openbmc.control.Host');
-
- bus.add_signal_receiver(self.power_button_signal_handler,
- dbus_interface = "org.openbmc.Button", signal_name = "ButtonPressed")
- bus.add_signal_receiver(self.power_good_signal_handler,
- dbus_interface = "org.openbmc.control.Power", signal_name = "PowerGood")
-
-
+ for bus_name in self.dbus_busses.keys():
+ self.request_name(bus_name,"",bus_name)
+ bus.add_signal_receiver(self.request_name,
+ dbus_interface = 'org.freedesktop.DBus',
+ signal_name = "NameOwnerChanged")
except dbus.exceptions.DBusException, e:
# TODO: not sure what to do if can't find other services
- print "Unable to find dependent services: ",e
+ print e
+ bus.add_signal_receiver(self.power_button_signal_handler,
+ dbus_interface = "org.openbmc.Button", signal_name = "ButtonPressed",
+ path="/org/openbmc/buttons/ButtonPower/PowerButton1" )
+ bus.add_signal_receiver(self.power_good_signal_handler,
+ dbus_interface = "org.openbmc.control.Power", signal_name = "PowerGood",
+ path="/org/openbmc/control/Power/PowerControl1")
+
+
+
+ def request_name(self, bus_name, a, b):
+ # bus added
+ if (len(b) > 0 ):
+ if (self.dbus_busses.has_key(bus_name)):
+ obj_path = "/"+bus_name.replace('.','/')
+ for objs in self.dbus_busses[bus_name]:
+ inst_name = objs['name']
+ obj = bus.get_object(bus_name,obj_path+"/"+inst_name)
+ print "Interface: "+inst_name+","+objs['intf']
+ self.dbus_objects[inst_name] = dbus.Interface(obj, objs['intf'])
+
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='s')
@@ -48,7 +69,7 @@
in_signature='', out_signature='')
def setIdentify(self):
print "Turn on identify"
- self.identify_led_iface.setOn()
+ self.dbus_objects['ChassisIdentify1'].setOn()
return None
@@ -56,7 +77,7 @@
in_signature='', out_signature='')
def clearIdentify(self):
print "Turn off identify"
- r=self.identify_led_iface.setOff()
+ r=self.dbus_objects['ChassisIdentify1'].setOff()
return None
@dbus.service.method(DBUS_NAME,
@@ -65,7 +86,7 @@
print "Turn on power and boot"
self.power_sequence = 0
if (self.getPowerState()==0):
- self.power_control_iface.setPowerState(POWER_ON)
+ self.dbus_objects['PowerControl1'].setPowerState(POWER_ON)
self.power_sequence = 1
return None
@@ -73,13 +94,13 @@
in_signature='', out_signature='')
def setPowerOff(self):
print "Turn off power"
- self.power_control_iface.setPowerState(POWER_OFF);
+ self.dbus_objects['PowerControl1'].setPowerState(POWER_OFF);
return None
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='i')
def getPowerState(self):
- state = self.power_control_iface.getPowerState();
+ state = self.dbus_objects['PowerControl1'].getPowerState();
return state
@dbus.service.method(DBUS_NAME,
@@ -106,7 +127,7 @@
## Signal handler
def power_good_signal_handler(self):
if (self.power_sequence==1):
- self.host_control_iface.boot()
+ self.dbus_objects['HostControl1'].boot()
self.power_sequence = 2
diff --git a/bin/gpio_manager.py b/bin/gpio_manager.py
deleted file mode 100644
index e0a264e..0000000
--- a/bin/gpio_manager.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python
-
-import gobject
-import dbus
-import dbus.service
-import dbus.mainloop.glib
-import System
-
-DBUS_NAME = 'org.openbmc.managers.Gpios'
-OBJ_NAME = '/org/openbmc/managers/Gpios'
-
-gpio_config = System.BarreleyeGpios()
-gpio_dev = '/sys/class/gpio'
-
-class GpioManager(dbus.service.Object):
- def __init__(self,bus,name):
- dbus.service.Object.__init__(self,bus,name)
- bus = dbus.SessionBus()
- self.gpio_locks = {}
-
-
- @dbus.service.method(DBUS_NAME,
- in_signature='s', out_signature='sis')
- def init(self,name):
- gpio_path = ''
- if (gpio_config.has_key(name) == False):
- # TODO: Error handling
- print "ERROR: "+name+" not found in GPIO config table"
- else:
- gpio_num = gpio_config[name]['gpio_num']
- print "GPIO Lookup: "+name+" = "+str(gpio_num)
-
- return [gpio_dev, gpio_num, gpio_config[name]['direction']]
-
- @dbus.service.method(DBUS_NAME,
- in_signature='s', out_signature='')
- def open(self,name):
- gpio_num = gpio_config[name]['gpio_num']
- self.gpio_locks[gpio_num] = 1
-
- @dbus.service.method(DBUS_NAME,
- in_signature='s', out_signature='')
- def close(self,name):
- # unexport?
- gpio_num = gpio_config[name]['gpio_num']
- self.gpio_locks[gpio_num] = 0
-
-
- ## Signal handler
-
-
-if __name__ == '__main__':
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-
- bus = dbus.SessionBus()
- name = dbus.service.BusName(DBUS_NAME, bus)
- obj = GpioManager(bus, OBJ_NAME)
- mainloop = gobject.MainLoop()
-
- print "Running GpioManager"
- mainloop.run()
-
diff --git a/bin/sensor_management.py b/bin/sensor_management.py
deleted file mode 100644
index 014a5b4..0000000
--- a/bin/sensor_management.py
+++ /dev/null
@@ -1,152 +0,0 @@
-#!/usr/bin/env python
-
-
-import gobject
-import dbus
-import dbus.service
-import dbus.mainloop.glib
-import xml.etree.ElementTree as ET
-import System
-
-NORMAL = 0
-LOWER_WARNING = 1
-LOWER_CRITICAL = 2
-UPPER_WARNING = 3
-UPPER_CRITICAL = 4
-
-
-sensor_config = System.Barreleye()
-
-## finds objects held by Dbus ObjectManager
-def get_interface(obj_path):
- bus_name = sensor_config[obj_path]['bus_name']
- obj_name = "/"+bus_name.replace('.','/')
- obj = bus.get_object(bus_name, obj_name)
- #Find object in object manager and retrieve interface name
- manager = dbus.Interface(obj,'org.freedesktop.DBus.ObjectManager')
- objects = manager.GetManagedObjects()
- interface = None
- if (objects.has_key(obj_path)):
- for intf in objects[obj_path].keys():
- if (intf.find('Sensor') > 0):
- interface = intf
-
- if (interface == None):
- raise Exception("Unable to find sensor: "+obj_path)
-
- return interface
-
-
-## Maintains last value, handles sensor changed events, applies thresholds
-## The Sensor class is not exported onto dbus
-class Sensor:
-
- def __init__(self, bus, obj_name, warning_callback, critical_callback):
- obj = bus.get_object(sensor_config[obj_name]['bus_name'],obj_name)
-
- ## member variables
- self.object_name = obj_name
- interface_name = get_interface(obj_name)
- self.interface = dbus.Interface(obj,interface_name)
- self.value = self.interface.getValue()
- self.upper_critical_threshold = None
- self.lower_critical_threshold = None
- self.upper_warning_threshold = None
- self.lower_warning_threshold = None
- self.threshold_state = NORMAL
- self.emit_warning = warning_callback
- self.emit_critical = critical_callback
-
- ## add signal handler to update cached value when sensor changes
- bus.add_signal_receiver(self.sensor_changed_signal_handler,
- dbus_interface = interface_name, signal_name = "Changed")
-
- def set_thresholds(self,lc,lw,uw,uc):
- self.upper_critical_threshold = uc
- self.lower_critical_threshold = lc
- self.upper_warning_threshold = uw
- self.lower_warning_threshold = lw
-
- def set_config(self,data):
- self.interface.setConfigData(data)
-
- ## called when associated sensor dbus object emits a Changed signal
- def sensor_changed_signal_handler(self,value):
- ## update value from signal data
- self.value = value
-
- ## check thresholds
- state = NORMAL
- if (value < self.lower_critical_threshold):
- state = LOWER_CRITICAL
- elif (value < self.lower_warning_threshold):
- state = LOWER_WARNING
- elif (value > self.upper_critical_threshold):
- state = UPPER_CRITICAL
- elif (value > self.upper_warning_threshold):
- state = UPPER_WARNING
- ## only emit signal if threshold state has changed
- if (state != self.threshold_state):
- self.threshold_state = state
- if (state == LOWER_CRITICAL or state == UPPER_CRITICAL):
- self.emit_critical(self.object_name)
- if (state == LOWER_WARNING or state == UPPER_WARNING):
- self.emit_warning(self.object_name)
-
-
- def get_value(self):
- return self.value
-
-
-class SensorManagement(dbus.service.Object):
- def __init__(self,bus,name):
- dbus.service.Object.__init__(self,bus,name)
- self.sensor_cache = {}
- try:
- for objname in sensor_config.keys():
- print "Loading: "+objname
- sensor_new = Sensor(bus,objname,
- self.WarningThreshold,self.CriticalThreshold)
- sensor_new.set_thresholds(sensor_config[objname]['lower_critical'],
- sensor_config[objname]['lower_warning'],
- sensor_config[objname]['upper_warning'],
- sensor_config[objname]['upper_critical'])
- if (sensor_config[objname].has_key('parameters')):
- sensor_new.set_config(sensor_config[objname]['parameters'])
- self.sensor_cache[objname] = sensor_new
-
- except dbus.exceptions.DBusException, e:
- # TODO: not sure what to do if can't find other services
- print "Unable to find dependent services: ",e
-
-
- @dbus.service.method("org.openbmc.SensorManagement",
- in_signature='s', out_signature='a{ss}')
- def getAllSensors(self,obj_name):
- return None
-
- @dbus.service.method("org.openbmc.SensorManagement",
- in_signature='s', out_signature='i')
- def getSensorValue(self,obj_name):
- sensor = self.sensor_cache[obj_name]
- return sensor.get_value()
-
- @dbus.service.signal('org.openbmc.SensorManagement')
- def CriticalThreshold(self, obj):
- print "Critical: "+obj
-
- @dbus.service.signal('org.openbmc.SensorManagement')
- def WarningThreshold(self, obj):
- print "Warning: "+obj
-
-
-if __name__ == '__main__':
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
- bus = dbus.SessionBus()
- name = dbus.service.BusName("org.openbmc.SensorManagement",bus)
- obj = SensorManagement(bus,'/org/openbmc/SensorManagement')
- mainloop = gobject.MainLoop()
-
- print "Running SensorManagementService"
- mainloop.run()
-
diff --git a/bin/sensor_management2.py b/bin/sensor_management2.py
deleted file mode 100644
index e897410..0000000
--- a/bin/sensor_management2.py
+++ /dev/null
@@ -1,111 +0,0 @@
-#!/usr/bin/env python
-
-
-import gobject
-import dbus
-import dbus.service
-import dbus.mainloop.glib
-import xml.etree.ElementTree as ET
-import System
-
-DBUS_NAME = 'org.openbmc.managers.Sensors'
-OBJ_NAME = '/org/openbmc/managers/Sensors'
-
-NORMAL = 0
-LOWER_WARNING = 1
-LOWER_CRITICAL = 2
-UPPER_WARNING = 3
-UPPER_CRITICAL = 4
-
-
-sensor_config = System.BarreleyeSensors()
-
-## finds objects held by Dbus ObjectManager
-def get_interface(bus_name):
- obj_name = "/"+bus_name.replace('.','/')
- obj = bus.get_object(bus_name, obj_name)
-
- #Find object in object manager and retrieve interface name
- manager = dbus.Interface(obj,'org.freedesktop.DBus.ObjectManager')
- objects = manager.GetManagedObjects()
- obj_path = None
- interface = None
-
- for o in objects:
- for intf in objects[o].keys():
- if (intf.find('Sensor') > 0):
- interface = intf
- obj_path = o
-
- if (interface == None):
- raise Exception("Unable to find sensor: "+obj_path)
-
- return [obj_path, interface]
-
-
-class SensorManagement(dbus.service.Object):
- def __init__(self,bus,name):
- dbus.service.Object.__init__(self,bus,name)
- self.sensor_cache = {}
- for bus_name in bus.list_names():
- if (bus_name.find('org.openbmc.sensors')==0):
- self.request_name(bus_name,"",bus_name)
-
- bus.add_signal_receiver(self.request_name,
- dbus_interface = 'org.freedesktop.DBus',
- signal_name = "NameOwnerChanged")
-
-
- def request_name(self, bus_name, a, b):
- if (len(b) > 0 and bus_name.find('org.openbmc.sensors') == 0):
- if (sensor_config.has_key(bus_name) == True):
- try:
- print "Loading: "+bus_name
- obj_info = get_interface(bus_name)
- obj = bus.get_object(bus_name,obj_info[0])
- intf = dbus.Interface(obj,obj_info[1])
- intf.setThresholds(sensor_config[bus_name]['lower_critical'],
- sensor_config[bus_name]['lower_warning'],
- sensor_config[bus_name]['upper_warning'],
- sensor_config[bus_name]['upper_critical'])
- if (sensor_config[bus_name].has_key('parameters')):
- intf.setConfigData(sensor_config[bus_name]['parameters'])
-
- except dbus.exceptions.DBusException, e:
- # TODO: not sure what to do if can't find other services
- print "Unable to find dependent services: ",e
- else:
- print "Sensor found on bus but no config: "+bus_name
- if (len(b) == 0 and bus_name.find('org.openbmc') ==0):
- print "Sensor stopped: "+bus_name
-
- @dbus.service.method(DBUS_NAME,
- in_signature='s', out_signature='a{ss}')
- def getAllSensors(self,obj_name):
- return None
-
- @dbus.service.method(DBUS_NAME,
- in_signature='s', out_signature='i')
- def getSensorValue(self,obj_name):
- sensor = self.sensor_cache[obj_name]
- return sensor.get_value()
-
- @dbus.service.signal(DBUS_NAME)
- def CriticalThreshold(self, obj):
- print "Critical: "+obj
-
- @dbus.service.signal(DBUS_NAME)
- def WarningThreshold(self, obj):
- print "Warning: "+obj
-
-
-if __name__ == '__main__':
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
- bus = dbus.SessionBus()
- name = dbus.service.BusName(DBUS_NAME,bus)
- obj = SensorManagement(bus,OBJ_NAME)
- mainloop = gobject.MainLoop()
-
- print "Running SensorManagerService"
- mainloop.run()
-
diff --git a/bin/system_manager.py b/bin/system_manager.py
index 7d17da6..7b902c2 100644
--- a/bin/system_manager.py
+++ b/bin/system_manager.py
@@ -1,43 +1,54 @@
#!/usr/bin/env python
+import sys
import subprocess
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib
import xml.etree.ElementTree as ET
-import System
+
+if (len(sys.argv) < 2):
+ print "Usage: system_manager.py [system name]"
+ exit(1)
+
+System = __import__(sys.argv[1])
+import Openbmc
DBUS_NAME = 'org.openbmc.managers.System'
OBJ_NAME = '/org/openbmc/managers/System'
-
-gpio_dev = '/sys/class/gpio'
-process_config = System.BarreleyeProcesses()
-gpio_config = System.BarreleyeGpios()
+HEARTBEAT_CHECK_INTERVAL = 20000
def findConfigInstance(bus_name,obj_path):
line = obj_path.split('/')
instance_name = line[len(line)-1]
- if (process_config.has_key(bus_name) == False):
+ if (System.SYSTEM_CONFIG.has_key(bus_name) == False):
return {}
- for instance in process_config[bus_name]['instances']:
+ for instance in System.SYSTEM_CONFIG[bus_name]['instances']:
if (instance['name'] == instance_name):
return instance
-def parseIntrospection(bus_name,obj_name,interfaces):
+def parseIntrospection(bus_name,obj_name,interfaces,init_interfaces):
obj = bus.get_object(bus_name, obj_name)
introspect_iface = dbus.Interface(obj,'org.freedesktop.DBus.Introspectable')
tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect()))
root = tree.getroot()
interfaces[obj_name] = []
+ init_interfaces[obj_name] = {}
for intf in root.iter('interface'):
intf_name = intf.attrib['name']
if (intf_name == 'org.freedesktop.DBus.ObjectManager'):
manager = dbus.Interface(obj,'org.freedesktop.DBus.ObjectManager')
for managed_obj in manager.GetManagedObjects():
- parseIntrospection(bus_name,managed_obj,interfaces)
- elif (intf_name.find('org.openbmc') == 0):
+ parseIntrospection(bus_name,managed_obj,interfaces,init_interfaces)
+ elif (intf_name.find(Openbmc.BUS_PREFIX) == 0):
interfaces[obj_name].append(intf_name)
+ for method in intf.iter('method'):
+ if (method.attrib['name'] == 'init'):
+ #print "Init: "+obj_name+" : "+intf_name
+ init_interfaces[obj_name][intf_name]=1
+
+
class SystemManager(dbus.service.Object):
@@ -47,71 +58,99 @@
dbus_interface = 'org.freedesktop.DBus',
signal_name = "NameOwnerChanged")
# launch dbus object processes
- for bus_name in process_config.keys():
- exe_name = process_config[bus_name]['exe_name']
- cmdline = [ ]
- cmdline.append(exe_name)
- for instance in process_config[bus_name]['instances']:
- cmdline.append(instance['name'])
- subprocess.Popen(cmdline);
+ for bus_name in System.SYSTEM_CONFIG.keys():
+ self.start_process(bus_name)
- gobject.timeout_add(5000, self.heartbeat_check)
+ gobject.timeout_add(HEARTBEAT_CHECK_INTERVAL, self.heartbeat_check)
+
+ def start_process(self,bus_name):
+ exe_name = System.SYSTEM_CONFIG[bus_name]['exe_name']
+ cmdline = [ ]
+ cmdline.append(exe_name)
+ for instance in System.SYSTEM_CONFIG[bus_name]['instances']:
+ cmdline.append(instance['name'])
+ try:
+ print "Starting process: "+" ".join(cmdline)
+ System.SYSTEM_CONFIG[bus_name]['popen'] = subprocess.Popen(cmdline);
+ except Exception as e:
+ ## TODO: error
+ print "Error starting process: "+" ".join(cmdline)
+
def heartbeat_check(self):
print "heartbeat check"
- for bus_name in process_config.keys():
- if (process_config[bus_name]['heartbeat'] == 'yes'):
- if (process_config[bus_name]['heartbeat_count'] == 0):
+ for bus_name in System.SYSTEM_CONFIG.keys():
+ ## even if process doesn't request heartbeat check,
+ ## make sure process is still alive
+ p = System.SYSTEM_CONFIG[bus_name]['popen']
+ p.poll()
+ if (p.returncode != None):
+ print "Process for "+bus_name+" appears to be dead"
+ self.start_process(bus_name)
+
+ elif (System.SYSTEM_CONFIG[bus_name]['heartbeat'] == 'yes'):
+ if (System.SYSTEM_CONFIG[bus_name]['heartbeat_count'] == 0):
print "Heartbeat error: "+bus_name
+ p = System.SYSTEM_CONFIG[bus_name]['popen']
+ p.poll()
+ if (p.returncode == None):
+ print "Process must be hung, so killing"
+ p.kill()
+
+ self.start_process(bus_name)
else:
- process_config[bus_name]['heartbeat_count'] == 0
- print "Heartbeat ok"
+ System.SYSTEM_CONFIG[bus_name]['heartbeat_count'] = 0
+ print "Heartbeat ok: "+bus_name
+
+ return True
def heartbeat_update(self,bus_name):
- process_config[bus_name]['heartbeat_count']=1
+ System.SYSTEM_CONFIG[bus_name]['heartbeat_count']=1
def setup_sensor(self,intf):
pass
def request_name(self, bus_name, a, b):
- if (len(b) > 0 and bus_name.find('org.openbmc') == 0):
- try:
- if (process_config.has_key(bus_name)):
- process_config[bus_name]['heartbeat_count'] = 0
- obj_name = "/"+bus_name.replace('.','/')
- interfaces = {}
- parseIntrospection(bus_name,obj_name,interfaces)
- for obj_path in interfaces.keys():
- instance = findConfigInstance(bus_name,obj_path)
- for intf_name in interfaces[obj_path]:
- obj = bus.get_object(bus_name,obj_path)
- intf = dbus.Interface(obj,intf_name)
- if (intf_name == 'org.openbmc.SensorIntegerThreshold'):
- intf.set(instance['lower_critical'],
- instance['lower_warning'],
- instance['upper_warning'],
- instance['upper_critical'])
-
- if (intf_name == 'org.openbmc.SensorInteger'):
- if (process_config[bus_name]['heartbeat'] == 'yes'):
- bus.add_signal_receiver(self.heartbeat_update,
- dbus_interface = intf_name,
- signal_name = "Heartbeat")
+ if (len(b) > 0 and bus_name.find(Openbmc.BUS_PREFIX) == 0):
+ if (System.SYSTEM_CONFIG.has_key(bus_name)):
+ System.SYSTEM_CONFIG[bus_name]['heartbeat_count'] = 0
+ obj_name = "/"+bus_name.replace('.','/')
+ interfaces = {}
+ init_interfaces = {}
+ # introspect object to get used interfaces
+ parseIntrospection(bus_name,obj_name,interfaces,init_interfaces)
+ for obj_path in interfaces.keys():
+ # find instance in system config
+ instance = findConfigInstance(bus_name,obj_path)
+ for intf_name in interfaces[obj_path]:
+ self.initObject(bus_name,obj_path,intf_name,instance)
+ for init_intf in init_interfaces[obj_path].keys():
+ obj = bus.get_object(bus_name,obj_path)
+ intf = dbus.Interface(obj,init_intf)
+ intf.init()
- if (instance.has_key('parameters')):
- intf.setConfigData(instance['parameters'])
- except Exception as e:
- print e
+ def initObject(self,bus_name,obj_path,intf_name,instance):
+ obj = bus.get_object(bus_name,obj_path)
+ intf = dbus.Interface(obj,intf_name)
+ if (instance.has_key('properties')):
+ properties = dbus.Interface(obj, 'org.freedesktop.DBus.Properties')
+ for prop_intf in instance['properties']:
+ for prop in instance['properties'][prop_intf]:
+ value = instance['properties'][prop_intf][prop]
+ properties.Set(prop_intf,prop,value)
- if (len(b)==0 and bus_name.find('org.openbmc.sensors') == 0):
- exe_name = process_config[bus_name]['exe_name']
- cmdline = [ ]
- cmdline.append(exe_name)
- for instance in process_config[bus_name]['instances']:
- cmdline.append(instance['name'])
-
- subprocess.Popen(cmdline);
+ ## TODO: fix this explicit check
+ if (intf_name == 'org.openbmc.Control' or intf_name == 'org.openbmc.SensorInteger'):
+ if (System.SYSTEM_CONFIG[bus_name]['heartbeat'] == 'yes'):
+ print "Add heartbeat: "+intf_name;
+ bus.add_signal_receiver(self.heartbeat_update,
+ dbus_interface = intf_name,
+ signal_name = "Heartbeat")
+
+ if (instance.has_key('parameters')):
+ intf.setConfigData(instance['parameters'])
+
@dbus.service.signal(DBUS_NAME)
def CriticalThreshold(self, obj):
@@ -126,14 +165,14 @@
def gpioInit(self,name):
gpio_path = ''
gpio_num = 0
- if (gpio_config.has_key(name) == False):
+ if (System.GPIO_CONFIG.has_key(name) == False):
# TODO: Error handling
print "ERROR: "+name+" not found in GPIO config table"
return ['',0,'']
else:
- gpio_num = gpio_config[name]['gpio_num']
+ gpio_num = System.GPIO_CONFIG[name]['gpio_num']
- return [gpio_dev, gpio_num, gpio_config[name]['direction']]
+ return [Openbmc.GPIO_DEV, gpio_num, System.GPIO_CONFIG[name]['direction']]
if __name__ == '__main__':
@@ -143,7 +182,6 @@
obj = SystemManager(bus,OBJ_NAME)
mainloop = gobject.MainLoop()
-
print "Running SystemManager"
mainloop.run()