blob: ba55ef60ae3d9661b861015ca5c01e5442813f2c [file] [log] [blame]
Patrick Williams04e007f2016-10-15 07:15:12 -05001#pragma once
2#include <tuple>
3#include <systemd/sd-bus.h>
Patrick Williams0966ce82016-10-17 21:54:09 -05004#include <sdbusplus/server.hpp>
Patrick Williams04e007f2016-10-15 07:15:12 -05005 <%
6 namespaces = interface.name.split('.')
7 classname = namespaces.pop()
8 %>
9namespace sdbusplus
10{
11namespace server
12{
13 % for s in namespaces:
14namespace ${s}
15{
16 % endfor
17
18class ${classname}
19{
20 public:
Patrick Williamsadc16822016-10-17 14:43:54 -050021 /* Define all of the basic class operations:
22 * Not allowed:
23 * - Default constructor to avoid nullptrs.
24 * - Copy operations due to internal unique_ptr.
25 * Allowed:
26 * - Move operations.
27 * - Destructor.
28 */
29 ${classname}() = delete;
30 ${classname}(const ${classname}&) = delete;
31 ${classname}& operator=(const ${classname}&) = delete;
32 ${classname}(${classname}&&) = default;
33 ${classname}& operator=(${classname}&&) = default;
34 virtual ~${classname}() = default;
35
36 /** @brief Constructor to put object onto bus at a dbus path.
37 * @param[in] bus - Bus to attach to.
38 * @param[in] path - Path to attach at.
39 */
40 ${classname}(bus::bus& bus, const char* path);
41
Patrick Williams04e007f2016-10-15 07:15:12 -050042 % for m in interface.methods:
43${ m.cpp_prototype(loader, interface=interface, ptype='header') }
44 % endfor
45
Patrick Williams5302a462016-10-18 11:11:51 -050046 % for s in interface.signals:
47${ s.cpp_prototype(loader, interface=interface, ptype='header') }
48 % endfor
49
Patrick Williamsb2cca012016-10-18 14:13:39 -050050 % for p in interface.properties:
51 /** Get value of ${p.name} */
52 virtual ${p.typeName} ${p.camelCase}() const;
53 /** Set value of ${p.name} */
54 virtual ${p.typeName} ${p.camelCase}(${p.typeName} value);
55 % endfor
56
Patrick Williams04e007f2016-10-15 07:15:12 -050057 private:
58 % for m in interface.methods:
59${ m.cpp_prototype(loader, interface=interface, ptype='callback-header') }
60 % endfor
61
Patrick Williamsb2cca012016-10-18 14:13:39 -050062 % for p in interface.properties:
63 /** @brief sd-bus callback for get-property '${p.name}' */
64 static int _callback_get_${p.name}(
65 sd_bus*, const char*, const char*, const char*,
66 sd_bus_message*, void*, sd_bus_error*);
67 /** @brief sd-bus callback for set-property '${p.name}' */
68 static int _callback_set_${p.name}(
69 sd_bus*, const char*, const char*, const char*,
70 sd_bus_message*, void*, sd_bus_error*);
71
72 % endfor
73
Patrick Williamsadc16822016-10-17 14:43:54 -050074 static constexpr auto _interface = "${interface.name}";
Patrick Williams0966ce82016-10-17 21:54:09 -050075 static const vtable::vtable_t _vtable[];
Patrick Williamsadc16822016-10-17 14:43:54 -050076 interface::interface _${"_".join(interface.name.split('.'))}_interface;
77
Patrick Williamsb2cca012016-10-18 14:13:39 -050078 % for p in interface.properties:
79 % if p.defaultValue:
80 ${p.typeName} _${p.camelCase} = ${p.defaultValue};
81 % else:
82 ${p.typeName} _${p.camelCase}{};
83 % endif
84 % endfor
85
Patrick Williams04e007f2016-10-15 07:15:12 -050086};
87
Patrick Williams0e9ad0d2016-10-18 14:24:44 -050088 % for s in reversed(namespaces):
Patrick Williams04e007f2016-10-15 07:15:12 -050089} // namespace ${s}
90 % endfor
91} // namespace server
92} // namespace sdbusplus