blob: e26e7262f80ced5d36df489756a1425829ffe3f8 [file] [log] [blame]
Patrick Williams04e007f2016-10-15 07:15:12 -05001<%
2 def cpp_return_type():
3 if len(method.returns) == 0:
4 return "void"
5 elif len(method.returns) == 1:
6 return method.returns[0].typeName
7 else:
8 return "std::tuple<" + \
9 ", ".join([ r.typeName for r in method.returns ]) + \
10 ">"
11
12 def parameters(defaultValue=False):
13 return ",\n ".\
14 join([ parameter(p, defaultValue) for p in method.parameters ])
15
Patrick Williams831839a2016-10-16 18:09:00 -050016 def parameters_as_local():
17 return "{};\n ".join([ parameter(p) for p in method.parameters ])
18
19 def parameters_as_list():
20 return ", ".join([ p.camelCase for p in method.parameters ])
21
Patrick Williams04e007f2016-10-15 07:15:12 -050022 def parameter(p, defaultValue=False):
Patrick Williamsce8a4672016-10-15 10:38:54 -050023 r = "%s %s" % (p.typeName, p.camelCase)
Patrick Williams04e007f2016-10-15 07:15:12 -050024 if defaultValue:
25 r += default_value(p)
26 return r
27
Patrick Williams831839a2016-10-16 18:09:00 -050028 def returns_as_tuple_index(tuple):
29 return ", ".join([ "std::move(std::get<%d>(%s))" % (i,tuple) \
30 for i in range(len(method.returns))])
31
Patrick Williams04e007f2016-10-15 07:15:12 -050032 def default_value(p):
33 if p.defaultValue != None:
34 return " = " + str(p.defaultValue)
35 else:
36 return ""
Patrick Williams831839a2016-10-16 18:09:00 -050037
38 def interface_name():
39 return interface.name.split('.').pop()
Patrick Williams04e007f2016-10-15 07:15:12 -050040%>
41###
42### Emit 'header'
43###
44 % if ptype == 'header':
45 /** @brief Implementation for ${ method.name }
46 * ${ method.description.strip() }
47 % if len(method.parameters) != 0:
48 *
49 % for p in method.parameters:
Patrick Williamsce8a4672016-10-15 10:38:54 -050050 * @param[in] ${p.camelCase} - ${p.description.strip()}
Patrick Williams04e007f2016-10-15 07:15:12 -050051 % endfor
52 % endif
53 % if len(method.returns) != 0:
54 *
55 % for r in method.returns:
Patrick Williamsce8a4672016-10-15 10:38:54 -050056 * @return ${r.camelCase}[${r.typeName}] - ${r.description.strip()}
Patrick Williams04e007f2016-10-15 07:15:12 -050057 % endfor
58 % endif
59 */
Patrick Williamsce8a4672016-10-15 10:38:54 -050060 virtual ${cpp_return_type()} ${ method.camelCase }(
Patrick Williams04e007f2016-10-15 07:15:12 -050061 ${ parameters() }) = 0;
62###
63### Emit 'callback-header'
64###
65 % elif ptype == 'callback-header':
66 /** @brief sd-bus callback for ${ method.name }
67 */
Patrick Williamsce8a4672016-10-15 10:38:54 -050068 static int _callback_${ method.CamelCase }(
Patrick Williams04e007f2016-10-15 07:15:12 -050069 sd_bus_message*, void*, sd_bus_error*);
Patrick Williams831839a2016-10-16 18:09:00 -050070###
71### Emit 'callback-cpp'
72###
73 % elif ptype == 'callback-cpp':
74int ${interface_name()}::_callback_${ method.CamelCase }(
75 sd_bus_message* msg, void* context, sd_bus_error* error)
76{
77 ### Need to add a ref to msg since we attached it to an sdbusplus::message.
78 auto m = sdbusplus::message::message(sd_bus_message_ref(msg));
79
80 % if len(method.parameters) != 0:
81 ${parameters_as_local()}{};
82
83 m.read(${parameters_as_list()});
84 % endif
85
86 auto o = static_cast<${interface_name()}*>(context);
87 % if len(method.returns) != 0:
88 auto r = \
89 %endif
90 o->${ method.camelCase }(${parameters_as_list()});
91
92 auto reply = m.new_method_return();
93 % if len(method.returns) == 0:
94 // No data to append on reply.
95 % elif len(method.returns) == 1:
96 reply.append(std::move(r));
97 % else:
98 reply.append(${returns_as_tuple_index("r")});
99 % endif
100
101 sdbusplus::bus::method_return(reply);
102
103 return 0;
104}
Patrick Williams04e007f2016-10-15 07:15:12 -0500105 % endif