blob: b263c7a22963e61703d5a61d104b3473d0eedc40 [file] [log] [blame]
Patrick Williams04e007f2016-10-15 07:15:12 -05001#pragma once
2#include <tuple>
3#include <systemd/sd-bus.h>
Patrick Venture263712f2018-04-16 14:19:08 -07004#include <sdbusplus/sdbus.hpp>
Patrick Williams0966ce82016-10-17 21:54:09 -05005#include <sdbusplus/server.hpp>
Abhishek Panditaa71a3e2016-11-10 13:33:17 -08006<%
7 namespaces = interface.name.split('.')
8 classname = namespaces.pop()
Patrick Williams9fa85522017-02-01 23:06:33 -06009
10 def setOfPropertyTypes():
11 return set(p.cppTypeParam(interface.name) for p in
12 interface.properties);
Abhishek Panditaa71a3e2016-11-10 13:33:17 -080013%>
Patrick Williams04e007f2016-10-15 07:15:12 -050014namespace sdbusplus
15{
Patrick Williams04e007f2016-10-15 07:15:12 -050016 % for s in namespaces:
17namespace ${s}
18{
19 % endfor
Patrick Williams7aa8a1e2016-11-11 13:30:33 -060020namespace server
21{
Patrick Williams04e007f2016-10-15 07:15:12 -050022
23class ${classname}
24{
25 public:
Patrick Williamsadc16822016-10-17 14:43:54 -050026 /* Define all of the basic class operations:
27 * Not allowed:
28 * - Default constructor to avoid nullptrs.
29 * - Copy operations due to internal unique_ptr.
Patrick Williams7904ed62016-11-29 22:02:37 -060030 * - Move operations due to 'this' being registered as the
31 * 'context' with sdbus.
Patrick Williamsadc16822016-10-17 14:43:54 -050032 * Allowed:
Patrick Williamsadc16822016-10-17 14:43:54 -050033 * - Destructor.
34 */
35 ${classname}() = delete;
36 ${classname}(const ${classname}&) = delete;
37 ${classname}& operator=(const ${classname}&) = delete;
Patrick Williams7904ed62016-11-29 22:02:37 -060038 ${classname}(${classname}&&) = delete;
39 ${classname}& operator=(${classname}&&) = delete;
Patrick Williamsadc16822016-10-17 14:43:54 -050040 virtual ~${classname}() = default;
41
42 /** @brief Constructor to put object onto bus at a dbus path.
43 * @param[in] bus - Bus to attach to.
44 * @param[in] path - Path to attach at.
45 */
46 ${classname}(bus::bus& bus, const char* path);
47
Patrick Williams0aa0dde2016-11-16 08:14:33 -060048 % for e in interface.enums:
49 enum class ${e.name}
50 {
51 % for v in e.values:
52 ${v.name},
53 % endfor
54 };
55 % endfor
56
Patrick Williams9fa85522017-02-01 23:06:33 -060057 % if interface.properties:
58 using PropertiesVariant = sdbusplus::message::variant<
59 ${",\n ".join(setOfPropertyTypes())}>;
60
Patrick Williams4d47bf02017-02-01 23:16:23 -060061 /** @brief Constructor to initialize the object from a map of
62 * properties.
63 *
64 * @param[in] bus - Bus to attach to.
65 * @param[in] path - Path to attach at.
Gunnar Mills5f9874f2017-10-25 13:41:41 -050066 * @param[in] vals - Map of property name to value for initialization.
Patrick Williams4d47bf02017-02-01 23:16:23 -060067 */
68 ${classname}(bus::bus& bus, const char* path,
Richard Marian Thomaiyar261fe752018-06-18 13:53:56 +053069 const std::map<std::string, PropertiesVariant>& vals,
70 bool skipSignal = false);
Patrick Williams4d47bf02017-02-01 23:16:23 -060071
Patrick Williams9fa85522017-02-01 23:06:33 -060072 % endif
Patrick Williams04e007f2016-10-15 07:15:12 -050073 % for m in interface.methods:
74${ m.cpp_prototype(loader, interface=interface, ptype='header') }
75 % endfor
76
Patrick Williams5302a462016-10-18 11:11:51 -050077 % for s in interface.signals:
78${ s.cpp_prototype(loader, interface=interface, ptype='header') }
79 % endfor
80
Patrick Williamsb2cca012016-10-18 14:13:39 -050081 % for p in interface.properties:
82 /** Get value of ${p.name} */
Patrick Williams0aa0dde2016-11-16 08:14:33 -060083 virtual ${p.cppTypeParam(interface.name)} ${p.camelCase}() const;
Richard Marian Thomaiyar261fe752018-06-18 13:53:56 +053084 /** Set value of ${p.name} with option to skip sending signal */
85 virtual ${p.cppTypeParam(interface.name)} \
86${p.camelCase}(${p.cppTypeParam(interface.name)} value,
87 bool skipSignal);
Patrick Williamsb2cca012016-10-18 14:13:39 -050088 /** Set value of ${p.name} */
Patrick Williams0aa0dde2016-11-16 08:14:33 -060089 virtual ${p.cppTypeParam(interface.name)} \
90${p.camelCase}(${p.cppTypeParam(interface.name)} value);
Patrick Williamsb2cca012016-10-18 14:13:39 -050091 % endfor
92
Patrick Williams9fa85522017-02-01 23:06:33 -060093 % if interface.properties:
94 /** @brief Sets a property by name.
James Feistf7509062018-03-23 14:15:56 -070095 * @param[in] _name - A string representation of the property name.
Patrick Williams9fa85522017-02-01 23:06:33 -060096 * @param[in] val - A variant containing the value to set.
97 */
James Feistf7509062018-03-23 14:15:56 -070098 void setPropertyByName(const std::string& _name,
Richard Marian Thomaiyar261fe752018-06-18 13:53:56 +053099 const PropertiesVariant& val,
100 bool skipSignal = false);
Patrick Williams9fa85522017-02-01 23:06:33 -0600101
Patrick Williamsdfa19092017-02-02 09:24:56 -0600102 /** @brief Gets a property by name.
James Feistf7509062018-03-23 14:15:56 -0700103 * @param[in] _name - A string representation of the property name.
Patrick Williamsdfa19092017-02-02 09:24:56 -0600104 * @return - A variant containing the value of the property.
105 */
James Feistf7509062018-03-23 14:15:56 -0700106 PropertiesVariant getPropertyByName(const std::string& _name);
Patrick Williamsdfa19092017-02-02 09:24:56 -0600107
Patrick Williams9fa85522017-02-01 23:06:33 -0600108 % endif
Patrick Williams386e8d22016-11-16 16:13:57 -0600109 % for e in interface.enums:
110 /** @brief Convert a string to an appropriate enum value.
111 * @param[in] s - The string to convert in the form of
112 * "${interface.name}.<value name>"
113 * @return - The enum value.
114 */
Patrick Williams93c246c2017-06-16 05:04:01 -0500115 static ${e.name} convert${e.name}FromString(const std::string& s);
Patrick Williams386e8d22016-11-16 16:13:57 -0600116 % endfor
117
Patrick Williams04e007f2016-10-15 07:15:12 -0500118 private:
119 % for m in interface.methods:
120${ m.cpp_prototype(loader, interface=interface, ptype='callback-header') }
121 % endfor
122
Patrick Williamsb2cca012016-10-18 14:13:39 -0500123 % for p in interface.properties:
124 /** @brief sd-bus callback for get-property '${p.name}' */
125 static int _callback_get_${p.name}(
126 sd_bus*, const char*, const char*, const char*,
127 sd_bus_message*, void*, sd_bus_error*);
128 /** @brief sd-bus callback for set-property '${p.name}' */
129 static int _callback_set_${p.name}(
130 sd_bus*, const char*, const char*, const char*,
131 sd_bus_message*, void*, sd_bus_error*);
132
133 % endfor
134
Patrick Williamsadc16822016-10-17 14:43:54 -0500135 static constexpr auto _interface = "${interface.name}";
Patrick Williams0966ce82016-10-17 21:54:09 -0500136 static const vtable::vtable_t _vtable[];
Patrick Williams7aa8a1e2016-11-11 13:30:33 -0600137 sdbusplus::server::interface::interface
138 _${"_".join(interface.name.split('.'))}_interface;
Patrick Venture263712f2018-04-16 14:19:08 -0700139 sdbusplus::SdBusInterface *_intf;
Patrick Williamsadc16822016-10-17 14:43:54 -0500140
Patrick Williamsb2cca012016-10-18 14:13:39 -0500141 % for p in interface.properties:
142 % if p.defaultValue:
Patrick Williams2adcefa2016-11-16 08:23:12 -0600143 ${p.cppTypeParam(interface.name)} _${p.camelCase} = \
144 % if p.is_enum():
145${p.cppTypeParam(interface.name)}::\
146 % endif
147${p.defaultValue};
Patrick Williamsb2cca012016-10-18 14:13:39 -0500148 % else:
Patrick Williams0aa0dde2016-11-16 08:14:33 -0600149 ${p.cppTypeParam(interface.name)} _${p.camelCase}{};
Patrick Williamsb2cca012016-10-18 14:13:39 -0500150 % endif
151 % endfor
152
Patrick Williams04e007f2016-10-15 07:15:12 -0500153};
154
Patrick Williams386e8d22016-11-16 16:13:57 -0600155 % for e in interface.enums:
156/* Specialization of sdbusplus::server::bindings::details::convertForMessage
157 * for enum-type ${classname}::${e.name}.
158 *
159 * This converts from the enum to a constant c-string representing the enum.
160 *
161 * @param[in] e - Enum value to convert.
162 * @return C-string representing the name for the enum value.
163 */
164std::string convertForMessage(${classname}::${e.name} e);
165 % endfor
166
Patrick Williams7aa8a1e2016-11-11 13:30:33 -0600167} // namespace server
Patrick Williams0e9ad0d2016-10-18 14:24:44 -0500168 % for s in reversed(namespaces):
Patrick Williams04e007f2016-10-15 07:15:12 -0500169} // namespace ${s}
170 % endfor
Patrick Williams04e007f2016-10-15 07:15:12 -0500171} // namespace sdbusplus