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="genSignal(sig)" buffered="True">
24%if ('type' in sig['sparams']) and \
25    (sig['sparams']['type'] is not None):
26${indent(sig['signal'], 3)}<${sig['sparams']['type']}>(\
27%else:
28${indent(sig['signal'], 3)}(\
29%endif
30%for spk in sig['sparams']['params']:
31${indent(sig['sparams'][spk], 3)},
32%endfor
33${genParams(par=sig)}
34)
35</%def>\
36
37<%def name="genMethod(meth)" buffered="True">
38%if ('type' in meth['mparams']) and \
39    (meth['mparams']['type'] is not None):
40${meth['method']}<${meth['mparams']['type']}>(
41%else:
42${meth['method']}(
43%endif
44%for spk in meth['mparams']['params']:
45${meth['mparams'][spk]},
46%endfor
47${genParams(par=meth)}\
48)
49</%def>\
50
51<%def name="genSSE(event)" buffered="True">
52Group
53{
54%for group in event['groups']:
55%for member in group['members']:
56    {"${member['object']}",
57    "${member['interface']}",
58    "${member['property']}"},
59%endfor
60%endfor
61},
62ActionData{
63%for e in event['action']:
64{Group{
65%for g in e['groups']:
66%for m in g['members']:
67    {"${m['object']}",
68    "${m['interface']}",
69    "${m['property']}"},
70%endfor
71%endfor
72},
73std::vector<Action>{
74%for a in e['actions']:
75%if len(a['parameters']) != 0:
76make_action(action::${a['name']}(
77%else:
78make_action(action::${a['name']}
79%endif
80%for i, p in enumerate(a['parameters']):
81%if (i+1) != len(a['parameters']):
82    ${p},
83%else:
84    ${p}
85%endif
86%endfor
87%if len(a['parameters']) != 0:
88)),
89%else:
90),
91%endif
92%endfor
93}},
94%endfor
95},
96std::vector<Trigger>{
97    %if ('timer' in event['triggers']) and \
98        (event['triggers']['timer'] is not None):
99    make_trigger(trigger::timer(TimerConf{
100    ${event['triggers']['timer']['interval']},
101    ${event['triggers']['timer']['type']}
102    })),
103    %endif
104    %if ('signals' in event['triggers']) and \
105        (event['triggers']['signals'] is not None):
106    %for s in event['triggers']['signals']:
107    make_trigger(trigger::signal(
108        %if ('match' in s) and \
109            (s['match'] is not None):
110        match::${s['match']}(
111        %for i, mp in enumerate(s['mparams']['params']):
112        %if (i+1) != len(s['mparams']['params']):
113        ${indent(s['mparams'][mp], 1)},
114        %else:
115        ${indent(s['mparams'][mp], 1)}
116        %endif
117        %endfor
118        ),
119        %else:
120        "",
121        %endif
122        make_handler<SignalHandler>(\
123        ${genSignal(sig=s)}
124        )
125    )),
126    %endfor
127    %endif
128    %if ('init' in event['triggers']):
129    %for i in event['triggers']['init']:
130    make_trigger(trigger::init(
131        %if ('method' in i):
132        make_handler<MethodHandler>(\
133        ${indent(genMethod(meth=i), 3)}\
134        )
135        %endif
136    )),
137    %endfor
138    %endif
139},
140</%def>\
141