blob: b606033e67df2955351897de19df696f333ceb62 [file] [log] [blame]
Patrick Williams0966ce82016-10-17 21:54:09 -05001#include <sdbusplus/server.hpp>
Patrick Williams831839a2016-10-16 18:09:00 -05002#include <${"/".join(interface.name.split('.') + [ 'server.hpp' ])}>
3 <%
4 namespaces = interface.name.split('.')
5 classname = namespaces.pop()
6 %>
7namespace sdbusplus
8{
9namespace server
10{
11 % for s in namespaces:
12namespace ${s}
13{
14 % endfor
Patrick Williamsadc16822016-10-17 14:43:54 -050015
16${classname}::${classname}(bus::bus& bus, const char* path)
17 : _${"_".join(interface.name.split('.'))}_interface(
18 bus, path, _interface, _vtable, this)
19{
20}
21
Patrick Williams831839a2016-10-16 18:09:00 -050022 % for m in interface.methods:
23${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp') }
24 % endfor
25
Patrick Williams5302a462016-10-18 11:11:51 -050026 % for s in interface.signals:
27${ s.cpp_prototype(loader, interface=interface, ptype='callback-cpp') }
28 % endfor
29
Patrick Williamsb2cca012016-10-18 14:13:39 -050030 % for p in interface.properties:
31${p.typeName} ${classname}::${p.camelCase}() const
32{
33 return _${p.camelCase};
34}
35
36int ${classname}::_callback_get_${p.name}(
37 sd_bus* bus, const char* path, const char* interface,
38 const char* property, sd_bus_message* reply, void* context,
39 sd_bus_error* error)
40{
41 auto m = message::message(sd_bus_message_ref(reply));
42
43 auto o = static_cast<${classname}*>(context);
44 m.append(o->${p.camelCase}());
45
46 return 0;
47}
48
49${p.typeName} ${classname}::${p.camelCase}(${p.typeName} value)
50{
51 _${p.camelCase} = value;
52
53 return _${p.camelCase};
54}
55
56int ${classname}::_callback_set_${p.name}(
57 sd_bus* bus, const char* path, const char* interface,
58 const char* property, sd_bus_message* value, void* context,
59 sd_bus_error* error)
60{
61 auto m = message::message(sd_bus_message_ref(value));
62
63 auto o = static_cast<${classname}*>(context);
64
65 decltype(_${p.camelCase}) v{};
66 m.read(v);
67 o->${p.camelCase}(v);
68
69 return 0;
70}
71
72namespace details
73{
74namespace ${classname}
75{
76static const auto _property_${p.name} =
77 utility::tuple_to_array(message::types::type_id<
78 ${p.typeName}>());
79}
80}
81 % endfor
82
Patrick Williams178e8fc2016-10-17 16:37:24 -050083const vtable::vtable_t ${classname}::_vtable[] = {
84 vtable::start(),
85 % for m in interface.methods:
86${ m.cpp_prototype(loader, interface=interface, ptype='vtable') }
87 % endfor
Patrick Williams5302a462016-10-18 11:11:51 -050088 % for s in interface.signals:
89${ s.cpp_prototype(loader, interface=interface, ptype='vtable') }
90 % endfor
Patrick Williamsb2cca012016-10-18 14:13:39 -050091 % for p in interface.properties:
92 vtable::property("${p.name}",
93 details::${classname}::_property_${p.name}
94 .data(),
95 _callback_get_${p.name},
96 _callback_set_${p.name}),
97 % endfor
Patrick Williams178e8fc2016-10-17 16:37:24 -050098 vtable::end()
99};
100
Patrick Williams831839a2016-10-16 18:09:00 -0500101 % for s in namespaces:
102} // namespace ${s}
103 % endfor
104} // namespace server
105} // namespace sdbusplus