Generate groups defined on actions
Change-Id: Iac5b31f01cb402d45abef1bf14df1405cafd3dbc
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/gen-fan-zone-defs.py b/control/gen-fan-zone-defs.py
index f422522..2cc93fc 100755
--- a/control/gen-fan-zone-defs.py
+++ b/control/gen-fan-zone-defs.py
@@ -141,27 +141,31 @@
e += "Group{\n"
for group in event['groups']:
for member in group['members']:
- e += "{\n"
- e += "\"" + member['object'] + "\",\n"
+ e += "{\"" + member['object'] + "\",\n"
e += "\"" + member['interface'] + "\",\n"
- e += "\"" + member['property'] + "\"\n"
- e += "},\n"
+ e += "\"" + member['property'] + "\"},\n"
e += "},\n"
- e += "{Group{},\n"
- e += "std::vector<Action>{\n"
- for a in event['action']:
- if len(a['parameters']) != 0:
+ e += "ActionData{\n"
+ for d in event['action']:
+ e += "{Group{\n"
+ for g in d['groups']:
+ for m in g['members']:
+ e += "{" + m['object'] + ",\n"
+ e += m['interface'] + ",\n"
+ e += m['property'] + "},\n"
+ e += "},\n"
+ e += "std::vector<Action>{\n"
+ for a in d['actions']:
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"
+ 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 += "},\n"
e += "std::vector<Trigger>{\n"
if ('timer' in event['triggers']) and \
@@ -411,6 +415,7 @@
eAction = next(a for a in events['actions']
if a['name'] == eActions['name'])
actions['name'] = eAction['name']
+ actions['groups'] = getGroups(zNum, zCond, eActions, events)
params = []
if ('parameters' in eAction) and \
(eAction['parameters'] is not None):
@@ -506,11 +511,29 @@
event['action'] = []
if ('actions' in e) and \
(e['actions'] is not None):
- event['action'] = getActions(zone_num,
- zone_conditions,
- e,
- e,
- events_data)
+ # List of dicts containing the list of groups and list of actions
+ sseActions = []
+ eActions = getActions(zone_num, zone_conditions, e, e, events_data)
+ for eAction in eActions:
+ # Skip events that have no groups defined for the event or actions
+ if not event['groups'] and not eAction['groups']:
+ continue
+ # Find group in sseActions
+ grpExists = False
+ for sseDict in sseActions:
+ if eAction['groups'] == sseDict['groups']:
+ # Extend 'actions' list
+ del eAction['groups']
+ sseDict['actions'].append(eAction)
+ grpExists = True
+ break
+ if not grpExists:
+ grps = eAction['groups']
+ del eAction['groups']
+ actList = []
+ actList.append(eAction)
+ sseActions.append({'groups':grps, 'actions':actList})
+ event['action'] = sseActions
# Add event triggers
event['triggers'] = {}
diff --git a/control/templates/defs.mako b/control/templates/defs.mako
index 3a68e99..b090fb9 100644
--- a/control/templates/defs.mako
+++ b/control/templates/defs.mako
@@ -49,35 +49,42 @@
</%def>\
<%def name="genSSE(event)" buffered="True">
-Group{
+Group
+{
%for group in event['groups']:
%for member in group['members']:
-{
- "${member['object']}",
+ {"${member['object']}",
"${member['interface']}",
- "${member['property']}"
-},
+ "${member['property']}"},
%endfor
%endfor
},
-{Group{},
+ActionData{
+%for e in event['action']:
+{Group{
+%for g in e['groups']:
+%for m in g['members']:
+ {"${m['object']}",
+ "${m['interface']}",
+ "${m['property']}"},
+%endfor
+%endfor
+},
std::vector<Action>{
-%for a in event['action']:
-%if len(a['parameters']) != 0:
+%for a in e['actions']:
make_action(action::${a['name']}(
-%else:
-make_action(action::${a['name']}
-%endif
%for i, p in enumerate(a['parameters']):
%if (i+1) != len(a['parameters']):
${p},
%else:
- ${p})
+ ${p}
%endif
%endfor
-),
+)),
%endfor
}},
+%endfor
+},
std::vector<Trigger>{
%if ('timer' in event['triggers']) and \
(event['triggers']['timer'] is not None):
diff --git a/control/templates/fan_zone_defs.mako.cpp b/control/templates/fan_zone_defs.mako.cpp
index 59b302d..a710a9e 100644
--- a/control/templates/fan_zone_defs.mako.cpp
+++ b/control/templates/fan_zone_defs.mako.cpp
@@ -100,17 +100,17 @@
(event['pc'] is not None):
SetSpeedEvent{
"${event['pc']['pcname']}",
- Group{
+ Group
+ {
%for group in event['pc']['pcgrps']:
%for member in group['members']:
- {
- "${member['object']}",
+ {"${member['object']}",
"${member['interface']}",
- "${member['property']}"
- },
+ "${member['property']}"},
%endfor
%endfor
},
+ ActionData{
{Group{},
std::vector<Action>{
%for i, a in enumerate(event['pc']['pcact']):
@@ -160,6 +160,7 @@
),
%endif
}},
+ },
std::vector<Trigger>{
%if ('timer' in event['pc']['triggers']) and \
(event['pc']['triggers']['timer'] is not None):