summaryrefslogtreecommitdiffstats
path: root/control
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2019-01-16 11:02:57 -0600
committerMatthew Barth <msbarth@us.ibm.com>2019-01-25 16:30:54 -0600
commita1aef7a100a9b27d2133622a695bb8c09c2869bf (patch)
tree696852b69e02284ae8b63a47d153d42977439217 /control
parentc410ddab30097756f48a90fa94e0f6760c7cc850 (diff)
downloadphosphor-fan-presence-a1aef7a100a9b27d2133622a695bb8c09c2869bf.tar.gz
phosphor-fan-presence-a1aef7a100a9b27d2133622a695bb8c09c2869bf.zip
Parser updates to support alternate events action
With the use alternate events action, the ability to generate an event type is required within the parser. This action requires two separate lists of events to be generated and to generate the event code, it was necessary to add what code is generated for each section that comprises an event to the parser directly. Tested: Updated events yaml with an event to use the alternate events action Verified the generated code builds and runs on wspoon Change-Id: I2078610222b0ae0f7fdbcf348e5c9ff02c4108b6 Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control')
-rwxr-xr-xcontrol/gen-fan-zone-defs.py98
1 files changed, 94 insertions, 4 deletions
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
index 3db9a40..e83512a 100755
--- a/control/gen-fan-zone-defs.py
+++ b/control/gen-fan-zone-defs.py
@@ -24,6 +24,78 @@ def convertToMap(listOfDict):
return listOfDict
+def genEvent(event):
+ """
+ Generates the source code of an event and returns it as a string
+ """
+ e = "SetSpeedEvent{\n"
+
+ e += "Group{\n"
+ for group in event['groups']:
+ for member in group['members']:
+ e += "{\n"
+ e += "\"" + member['object'] + "\",\n"
+ e += "{\"" + member['interface'] + "\",\n"
+ e += " \"" + member['property'] + "\"}\n"
+ e += "},\n"
+ e += "},\n"
+
+ e += "std::vector<Action>{\n"
+ for a in event['action']:
+ if len(a['parameters']) != 0:
+ e += "make_action(action::" + a['name'] + "(\n"
+ else:
+ e += "make_action(action::" + a['name'] + "\n"
+ for i, p in enumerate(a['parameters']):
+ if (i+1) != len(a['parameters']):
+ e += p + ",\n"
+ else:
+ e += p + ")\n"
+ e += "),\n"
+ e += "},\n"
+
+ e += "TimerConf{\n"
+ e += "\t" + event['timer']['interval'] + ",\n"
+ e += "\t" + event['timer']['type'] + "\n"
+ e += "},\n"
+
+ e += "std::vector<Signal>{\n"
+ for s in event['signals']:
+ e += "Signal{\n"
+ e += "match::" + s['match'] + "(\n"
+ for i, mp in enumerate(s['mparams']):
+ if (i+1) != len(s['mparams']):
+ e += "\"" + mp + "\",\n"
+ else:
+ e += "\"" + mp + "\"\n"
+ e += "),\n"
+ e += "make_handler(\n"
+ if ('type' in s['sparams']) and (s['sparams']['type'] is not None):
+ e += s['signal'] + "<" + s['sparams']['type'] + ">(\n"
+ else:
+ e += s['signal'] + "(\n"
+ for sp in s['sparams']['params']:
+ e += s['sparams'][sp] + ",\n"
+ if ('type' in s['hparams']) and (s['hparams']['type'] is not None):
+ e += ("handler::" + s['handler'] +
+ "<" + s['hparams']['type'] + ">(\n")
+ else:
+ e += "handler::" + s['handler'] + "(\n)"
+ for i, hp in enumerate(s['hparams']['params']):
+ if (i+1) != len(s['hparams']['params']):
+ e += s['hparams'][hp] + ",\n"
+ else:
+ e += s['hparams'][hp] + "\n"
+ e += "))\n"
+ e += ")\n"
+ e += "},\n"
+ e += "}\n"
+
+ e += "}"
+
+ return e
+
+
def getGroups(zNum, zCond, edata, events):
"""
Extract and construct the groups for the given event.
@@ -45,7 +117,6 @@ def getGroups(zNum, zCond, edata, events):
zNum not in z['zones']
for z in eGroups['zone_conditions']):
continue
-
eGroup = next(g for g in events['groups']
if g['name'] == eGroups['name'])
@@ -74,7 +145,7 @@ def getGroups(zNum, zCond, edata, events):
return groups
-def getActions(edata, actions, events):
+def getActions(zNum, zCond, edata, actions, events):
"""
Extracts and constructs the make_action function call for
all the actions within the given event.
@@ -93,7 +164,11 @@ def getActions(edata, actions, events):
if type(eActions[p]) is not dict:
if p == 'actions':
param = "std::vector<Action>{"
- pActs = getActions(edata, eActions, events)
+ pActs = getActions(zNum,
+ zCond,
+ edata,
+ eActions,
+ events)
for a in pActs:
if (len(a['parameters']) != 0):
param += (
@@ -109,6 +184,17 @@ def getActions(edata, actions, events):
param += ("make_action(action::" + a['name'])
param += "),"
param += "}"
+ elif p == 'defevents' or p == 'altevents':
+ param = "std::vector<SetSpeedEvent>{\n"
+ for i, e in enumerate(eActions[p]):
+ aEvent = getEvent(zNum, zCond, e, events)
+ if not aEvent:
+ continue
+ if (i+1) != len(eActions[p]):
+ param += genEvent(aEvent) + ",\n"
+ else:
+ param += genEvent(aEvent) + "\n"
+ param += "\t}"
elif p == 'property':
if isinstance(eActions[p], str) or \
"string" in str(eActions[p]['type']).lower():
@@ -166,7 +252,11 @@ def getEvent(zone_num, zone_conditions, e, events_data):
event['action'] = []
if ('actions' in e) and \
(e['actions'] is not None):
- event['action'] = getActions(e, e, events_data)
+ event['action'] = getActions(zone_num,
+ zone_conditions,
+ e,
+ e,
+ events_data)
# Add signal handlers
signals = []
OpenPOWER on IntegriCloud