Patrick Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <tuple> |
| 3 | #include <systemd/sd-bus.h> |
Patrick Williams | 0966ce8 | 2016-10-17 21:54:09 -0500 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
Patrick Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 5 | <% |
| 6 | namespaces = interface.name.split('.') |
| 7 | classname = namespaces.pop() |
| 8 | %> |
| 9 | namespace sdbusplus |
| 10 | { |
| 11 | namespace server |
| 12 | { |
| 13 | % for s in namespaces: |
| 14 | namespace ${s} |
| 15 | { |
| 16 | % endfor |
| 17 | |
| 18 | class ${classname} |
| 19 | { |
| 20 | public: |
Patrick Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 21 | /* 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 Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 42 | % for m in interface.methods: |
| 43 | ${ m.cpp_prototype(loader, interface=interface, ptype='header') } |
| 44 | % endfor |
| 45 | |
Patrick Williams | 5302a46 | 2016-10-18 11:11:51 -0500 | [diff] [blame] | 46 | % for s in interface.signals: |
| 47 | ${ s.cpp_prototype(loader, interface=interface, ptype='header') } |
| 48 | % endfor |
| 49 | |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 50 | % 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 Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 57 | private: |
| 58 | % for m in interface.methods: |
| 59 | ${ m.cpp_prototype(loader, interface=interface, ptype='callback-header') } |
| 60 | % endfor |
| 61 | |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 62 | % 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 Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 74 | static constexpr auto _interface = "${interface.name}"; |
Patrick Williams | 0966ce8 | 2016-10-17 21:54:09 -0500 | [diff] [blame] | 75 | static const vtable::vtable_t _vtable[]; |
Patrick Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 76 | interface::interface _${"_".join(interface.name.split('.'))}_interface; |
| 77 | |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 78 | % 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 Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 86 | }; |
| 87 | |
Patrick Williams | 0e9ad0d | 2016-10-18 14:24:44 -0500 | [diff] [blame] | 88 | % for s in reversed(namespaces): |
Patrick Williams | 04e007f | 2016-10-15 07:15:12 -0500 | [diff] [blame] | 89 | } // namespace ${s} |
| 90 | % endfor |
| 91 | } // namespace server |
| 92 | } // namespace sdbusplus |