blob: 7015ca02dd360916eaedfc646978c0fcbcfc7ddf [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>
Abhishek Panditaa71a3e2016-11-10 13:33:17 -08005<%
6 namespaces = interface.name.split('.')
7 classname = namespaces.pop()
Patrick Williams9fa85522017-02-01 23:06:33 -06008
9 def setOfPropertyTypes():
10 return set(p.cppTypeParam(interface.name) for p in
11 interface.properties);
Abhishek Panditaa71a3e2016-11-10 13:33:17 -080012%>
Patrick Williams04e007f2016-10-15 07:15:12 -050013namespace sdbusplus
14{
Patrick Williams04e007f2016-10-15 07:15:12 -050015 % for s in namespaces:
16namespace ${s}
17{
18 % endfor
Patrick Williams7aa8a1e2016-11-11 13:30:33 -060019namespace server
20{
Patrick Williams04e007f2016-10-15 07:15:12 -050021
22class ${classname}
23{
24 public:
Patrick Williamsadc16822016-10-17 14:43:54 -050025 /* Define all of the basic class operations:
26 * Not allowed:
27 * - Default constructor to avoid nullptrs.
28 * - Copy operations due to internal unique_ptr.
Patrick Williams7904ed62016-11-29 22:02:37 -060029 * - Move operations due to 'this' being registered as the
30 * 'context' with sdbus.
Patrick Williamsadc16822016-10-17 14:43:54 -050031 * Allowed:
Patrick Williamsadc16822016-10-17 14:43:54 -050032 * - Destructor.
33 */
34 ${classname}() = delete;
35 ${classname}(const ${classname}&) = delete;
36 ${classname}& operator=(const ${classname}&) = delete;
Patrick Williams7904ed62016-11-29 22:02:37 -060037 ${classname}(${classname}&&) = delete;
38 ${classname}& operator=(${classname}&&) = delete;
Patrick Williamsadc16822016-10-17 14:43:54 -050039 virtual ~${classname}() = default;
40
41 /** @brief Constructor to put object onto bus at a dbus path.
42 * @param[in] bus - Bus to attach to.
43 * @param[in] path - Path to attach at.
44 */
45 ${classname}(bus::bus& bus, const char* path);
46
Patrick Williams0aa0dde2016-11-16 08:14:33 -060047 % for e in interface.enums:
48 enum class ${e.name}
49 {
50 % for v in e.values:
51 ${v.name},
52 % endfor
53 };
54 % endfor
55
Patrick Williams9fa85522017-02-01 23:06:33 -060056 % if interface.properties:
57 using PropertiesVariant = sdbusplus::message::variant<
58 ${",\n ".join(setOfPropertyTypes())}>;
59
Patrick Williams4d47bf02017-02-01 23:16:23 -060060 /** @brief Constructor to initialize the object from a map of
61 * properties.
62 *
63 * @param[in] bus - Bus to attach to.
64 * @param[in] path - Path to attach at.
65 * @param[in] vals - Map of property name to value for initalization.
66 */
67 ${classname}(bus::bus& bus, const char* path,
68 const std::map<std::string, PropertiesVariant>& vals);
69
Patrick Williams9fa85522017-02-01 23:06:33 -060070 % endif
Patrick Williams04e007f2016-10-15 07:15:12 -050071 % for m in interface.methods:
72${ m.cpp_prototype(loader, interface=interface, ptype='header') }
73 % endfor
74
Patrick Williams5302a462016-10-18 11:11:51 -050075 % for s in interface.signals:
76${ s.cpp_prototype(loader, interface=interface, ptype='header') }
77 % endfor
78
Patrick Williamsb2cca012016-10-18 14:13:39 -050079 % for p in interface.properties:
80 /** Get value of ${p.name} */
Patrick Williams0aa0dde2016-11-16 08:14:33 -060081 virtual ${p.cppTypeParam(interface.name)} ${p.camelCase}() const;
Patrick Williamsb2cca012016-10-18 14:13:39 -050082 /** Set value of ${p.name} */
Patrick Williams0aa0dde2016-11-16 08:14:33 -060083 virtual ${p.cppTypeParam(interface.name)} \
84${p.camelCase}(${p.cppTypeParam(interface.name)} value);
Patrick Williamsb2cca012016-10-18 14:13:39 -050085 % endfor
86
Patrick Williams9fa85522017-02-01 23:06:33 -060087 % if interface.properties:
88 /** @brief Sets a property by name.
89 * @param[in] name - A string representation of the property name.
90 * @param[in] val - A variant containing the value to set.
91 */
92 void setPropertyByName(const std::string& name,
93 const PropertiesVariant& val);
94
Patrick Williamsdfa19092017-02-02 09:24:56 -060095 /** @brief Gets a property by name.
96 * @param[in] name - A string representation of the property name.
97 * @return - A variant containing the value of the property.
98 */
99 PropertiesVariant getPropertyByName(const std::string& name);
100
Patrick Williams9fa85522017-02-01 23:06:33 -0600101 % endif
Patrick Williams386e8d22016-11-16 16:13:57 -0600102 % for e in interface.enums:
103 /** @brief Convert a string to an appropriate enum value.
104 * @param[in] s - The string to convert in the form of
105 * "${interface.name}.<value name>"
106 * @return - The enum value.
107 */
Patrick Williams93c246c2017-06-16 05:04:01 -0500108 static ${e.name} convert${e.name}FromString(const std::string& s);
Patrick Williams386e8d22016-11-16 16:13:57 -0600109 % endfor
110
Patrick Williams04e007f2016-10-15 07:15:12 -0500111 private:
112 % for m in interface.methods:
113${ m.cpp_prototype(loader, interface=interface, ptype='callback-header') }
114 % endfor
115
Patrick Williamsb2cca012016-10-18 14:13:39 -0500116 % for p in interface.properties:
117 /** @brief sd-bus callback for get-property '${p.name}' */
118 static int _callback_get_${p.name}(
119 sd_bus*, const char*, const char*, const char*,
120 sd_bus_message*, void*, sd_bus_error*);
121 /** @brief sd-bus callback for set-property '${p.name}' */
122 static int _callback_set_${p.name}(
123 sd_bus*, const char*, const char*, const char*,
124 sd_bus_message*, void*, sd_bus_error*);
125
126 % endfor
127
Patrick Williamsadc16822016-10-17 14:43:54 -0500128 static constexpr auto _interface = "${interface.name}";
Patrick Williams0966ce82016-10-17 21:54:09 -0500129 static const vtable::vtable_t _vtable[];
Patrick Williams7aa8a1e2016-11-11 13:30:33 -0600130 sdbusplus::server::interface::interface
131 _${"_".join(interface.name.split('.'))}_interface;
Patrick Williamsadc16822016-10-17 14:43:54 -0500132
Patrick Williamsb2cca012016-10-18 14:13:39 -0500133 % for p in interface.properties:
134 % if p.defaultValue:
Patrick Williams2adcefa2016-11-16 08:23:12 -0600135 ${p.cppTypeParam(interface.name)} _${p.camelCase} = \
136 % if p.is_enum():
137${p.cppTypeParam(interface.name)}::\
138 % endif
139${p.defaultValue};
Patrick Williamsb2cca012016-10-18 14:13:39 -0500140 % else:
Patrick Williams0aa0dde2016-11-16 08:14:33 -0600141 ${p.cppTypeParam(interface.name)} _${p.camelCase}{};
Patrick Williamsb2cca012016-10-18 14:13:39 -0500142 % endif
143 % endfor
144
Patrick Williams04e007f2016-10-15 07:15:12 -0500145};
146
Patrick Williams386e8d22016-11-16 16:13:57 -0600147 % for e in interface.enums:
148/* Specialization of sdbusplus::server::bindings::details::convertForMessage
149 * for enum-type ${classname}::${e.name}.
150 *
151 * This converts from the enum to a constant c-string representing the enum.
152 *
153 * @param[in] e - Enum value to convert.
154 * @return C-string representing the name for the enum value.
155 */
156std::string convertForMessage(${classname}::${e.name} e);
157 % endfor
158
Patrick Williams7aa8a1e2016-11-11 13:30:33 -0600159} // namespace server
Patrick Williams0e9ad0d2016-10-18 14:24:44 -0500160 % for s in reversed(namespaces):
Patrick Williams04e007f2016-10-15 07:15:12 -0500161} // namespace ${s}
162 % endfor
Patrick Williams04e007f2016-10-15 07:15:12 -0500163} // namespace sdbusplus