1<%!
2def indent(str, depth):
3    return ''.join(4*' '*depth+line for line in str.splitlines(True))
4%>\
5
6<%def name="genParams(par)" buffered="True">
7%if ('type' in par['hparams']) and \
8    (par['hparams']['type'] is not None):
9handler::${par['handler']}<${par['hparams']['type']}>(
10%else:
11handler::${par['handler']}(
12%endif
13%for i, hpk in enumerate(par['hparams']['params']):
14    %if (i+1) != len(par['hparams']['params']):
15    ${par['hparams'][hpk]},
16    %else:
17    ${par['hparams'][hpk]}
18    %endif
19%endfor
20)
21</%def>\
22
23<%def name="genHandler(sig)" buffered="True">
24%if ('type' in sig['sparams']) and \
25    (sig['sparams']['type'] is not None):
26${sig['signal']}<${sig['sparams']['type']}>(
27%else:
28${sig['signal']}(
29%endif
30%for spk in sig['sparams']['params']:
31${sig['sparams'][spk]},
32%endfor
33${genParams(par=sig)}\
34)
35</%def>\
36
37<%def name="genSSE(event)" buffered="True">
38Group{
39%for group in event['groups']:
40%for member in group['members']:
41{
42    "${member['object']}",
43    "${member['interface']}",
44    "${member['property']}"
45},
46%endfor
47%endfor
48},
49std::vector<Action>{
50%for a in event['action']:
51%if len(a['parameters']) != 0:
52make_action(action::${a['name']}(
53%else:
54make_action(action::${a['name']}
55%endif
56%for i, p in enumerate(a['parameters']):
57%if (i+1) != len(a['parameters']):
58    ${p},
59%else:
60    ${p})
61%endif
62%endfor
63),
64%endfor
65},
66std::vector<Trigger>{
67    %if ('timer' in event['triggers']) and \
68        (event['triggers']['timer'] is not None):
69    make_trigger(trigger::timer(TimerConf{
70    ${event['triggers']['timer']['interval']},
71    ${event['triggers']['timer']['type']}
72    })),
73    %endif
74    %if ('signals' in event['triggers']) and \
75        (event['triggers']['signals'] is not None):
76    %for s in event['triggers']['signals']:
77    make_trigger(trigger::signal(
78        %if ('match' in s) and \
79            (s['match'] is not None):
80        match::${s['match']}(
81        %for i, mp in enumerate(s['mparams']):
82        %if (i+1) != len(s['mparams']):
83        "${mp}",
84        %else:
85        "${mp}"
86        %endif
87        %endfor
88        ),
89        %else:
90        "",
91        %endif
92        make_handler(\
93        ${indent(genHandler(sig=s), 3)}\
94        )
95    )),
96    %endfor
97    %endif
98    %if ('init' in event['triggers']):
99    %for i in event['triggers']['init']:
100    make_trigger(trigger::init(
101        %if ('handler' in i):
102        make_handler(\
103        ${indent(genParams(par=i), 3)}\
104        )
105        %endif
106    )),
107    %endfor
108    %endif
109},
110</%def>\
111