Patrick Williams | 0966ce8 | 2016-10-17 21:54:09 -0500 | [diff] [blame] | 1 | #include <sdbusplus/server.hpp> |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 2 | #include <${"/".join(interface.name.split('.') + [ 'server.hpp' ])}> |
| 3 | <% |
| 4 | namespaces = interface.name.split('.') |
| 5 | classname = namespaces.pop() |
Patrick Williams | a475c03 | 2016-10-18 22:03:41 -0500 | [diff] [blame] | 6 | |
| 7 | def interface_instance(): |
| 8 | return "_".join(interface.name.split('.') + ['interface']) |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 9 | %> |
| 10 | namespace sdbusplus |
| 11 | { |
| 12 | namespace server |
| 13 | { |
| 14 | % for s in namespaces: |
| 15 | namespace ${s} |
| 16 | { |
| 17 | % endfor |
Patrick Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 18 | |
| 19 | ${classname}::${classname}(bus::bus& bus, const char* path) |
Patrick Williams | a475c03 | 2016-10-18 22:03:41 -0500 | [diff] [blame] | 20 | : _${interface_instance()}( |
Patrick Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 21 | bus, path, _interface, _vtable, this) |
| 22 | { |
| 23 | } |
| 24 | |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 25 | % for m in interface.methods: |
| 26 | ${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } |
| 27 | % endfor |
| 28 | |
Patrick Williams | 5302a46 | 2016-10-18 11:11:51 -0500 | [diff] [blame] | 29 | % for s in interface.signals: |
| 30 | ${ s.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } |
| 31 | % endfor |
| 32 | |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 33 | % for p in interface.properties: |
| 34 | ${p.typeName} ${classname}::${p.camelCase}() const |
| 35 | { |
| 36 | return _${p.camelCase}; |
| 37 | } |
| 38 | |
| 39 | int ${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 Williams | a475c03 | 2016-10-18 22:03:41 -0500 | [diff] [blame] | 54 | if (_${p.camelCase} != value) |
| 55 | { |
| 56 | _${p.camelCase} = value; |
| 57 | _${interface_instance()}.property_changed("${p.name}"); |
| 58 | } |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 59 | |
| 60 | return _${p.camelCase}; |
| 61 | } |
| 62 | |
| 63 | int ${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 | |
| 79 | namespace details |
| 80 | { |
| 81 | namespace ${classname} |
| 82 | { |
| 83 | static const auto _property_${p.name} = |
| 84 | utility::tuple_to_array(message::types::type_id< |
| 85 | ${p.typeName}>()); |
| 86 | } |
| 87 | } |
| 88 | % endfor |
| 89 | |
Patrick Williams | 178e8fc | 2016-10-17 16:37:24 -0500 | [diff] [blame] | 90 | const 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 Williams | 5302a46 | 2016-10-18 11:11:51 -0500 | [diff] [blame] | 95 | % for s in interface.signals: |
| 96 | ${ s.cpp_prototype(loader, interface=interface, ptype='vtable') } |
| 97 | % endfor |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 98 | % for p in interface.properties: |
| 99 | vtable::property("${p.name}", |
| 100 | details::${classname}::_property_${p.name} |
| 101 | .data(), |
| 102 | _callback_get_${p.name}, |
Patrick Williams | a475c03 | 2016-10-18 22:03:41 -0500 | [diff] [blame] | 103 | _callback_set_${p.name}, |
| 104 | vtable::property_::emits_change), |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame] | 105 | % endfor |
Patrick Williams | 178e8fc | 2016-10-17 16:37:24 -0500 | [diff] [blame] | 106 | vtable::end() |
| 107 | }; |
| 108 | |
Patrick Williams | 0e9ad0d | 2016-10-18 14:24:44 -0500 | [diff] [blame] | 109 | % for s in reversed(namespaces): |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 110 | } // namespace ${s} |
| 111 | % endfor |
| 112 | } // namespace server |
| 113 | } // namespace sdbusplus |