blob: 2a5c49756c2449e7fd02bd93b65e333b8689e248 [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()
Patrick Williamsa475c032016-10-18 22:03:41 -05006
7 def interface_instance():
8 return "_".join(interface.name.split('.') + ['interface'])
Patrick Williams831839a2016-10-16 18:09:00 -05009 %>
10namespace sdbusplus
11{
12namespace server
13{
14 % for s in namespaces:
15namespace ${s}
16{
17 % endfor
Patrick Williamsadc16822016-10-17 14:43:54 -050018
19${classname}::${classname}(bus::bus& bus, const char* path)
Patrick Williamsa475c032016-10-18 22:03:41 -050020 : _${interface_instance()}(
Patrick Williamsadc16822016-10-17 14:43:54 -050021 bus, path, _interface, _vtable, this)
22{
23}
24
Patrick Williams831839a2016-10-16 18:09:00 -050025 % for m in interface.methods:
26${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp') }
27 % endfor
28
Patrick Williams5302a462016-10-18 11:11:51 -050029 % for s in interface.signals:
30${ s.cpp_prototype(loader, interface=interface, ptype='callback-cpp') }
31 % endfor
32
Patrick Williamsb2cca012016-10-18 14:13:39 -050033 % for p in interface.properties:
34${p.typeName} ${classname}::${p.camelCase}() const
35{
36 return _${p.camelCase};
37}
38
39int ${classname}::_callback_get_${p.name}(
40 sd_bus* bus, const char* path, const char* interface,
41 const char* property, sd_bus_message* reply, void* context,
42 sd_bus_error* error)
43{
44 auto m = message::message(sd_bus_message_ref(reply));
45
46 auto o = static_cast<${classname}*>(context);
47 m.append(o->${p.camelCase}());
48
49 return 0;
50}
51
52${p.typeName} ${classname}::${p.camelCase}(${p.typeName} value)
53{
Patrick Williamsa475c032016-10-18 22:03:41 -050054 if (_${p.camelCase} != value)
55 {
56 _${p.camelCase} = value;
57 _${interface_instance()}.property_changed("${p.name}");
58 }
Patrick Williamsb2cca012016-10-18 14:13:39 -050059
60 return _${p.camelCase};
61}
62
63int ${classname}::_callback_set_${p.name}(
64 sd_bus* bus, const char* path, const char* interface,
65 const char* property, sd_bus_message* value, void* context,
66 sd_bus_error* error)
67{
68 auto m = message::message(sd_bus_message_ref(value));
69
70 auto o = static_cast<${classname}*>(context);
71
72 decltype(_${p.camelCase}) v{};
73 m.read(v);
74 o->${p.camelCase}(v);
75
76 return 0;
77}
78
79namespace details
80{
81namespace ${classname}
82{
83static const auto _property_${p.name} =
84 utility::tuple_to_array(message::types::type_id<
85 ${p.typeName}>());
86}
87}
88 % endfor
89
Patrick Williams178e8fc2016-10-17 16:37:24 -050090const vtable::vtable_t ${classname}::_vtable[] = {
91 vtable::start(),
92 % for m in interface.methods:
93${ m.cpp_prototype(loader, interface=interface, ptype='vtable') }
94 % endfor
Patrick Williams5302a462016-10-18 11:11:51 -050095 % for s in interface.signals:
96${ s.cpp_prototype(loader, interface=interface, ptype='vtable') }
97 % endfor
Patrick Williamsb2cca012016-10-18 14:13:39 -050098 % for p in interface.properties:
99 vtable::property("${p.name}",
100 details::${classname}::_property_${p.name}
101 .data(),
102 _callback_get_${p.name},
Patrick Williamsa475c032016-10-18 22:03:41 -0500103 _callback_set_${p.name},
104 vtable::property_::emits_change),
Patrick Williamsb2cca012016-10-18 14:13:39 -0500105 % endfor
Patrick Williams178e8fc2016-10-17 16:37:24 -0500106 vtable::end()
107};
108
Patrick Williams0e9ad0d2016-10-18 14:24:44 -0500109 % for s in reversed(namespaces):
Patrick Williams831839a2016-10-16 18:09:00 -0500110} // namespace ${s}
111 % endfor
112} // namespace server
113} // namespace sdbusplus