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() |
| 6 | %> |
| 7 | namespace sdbusplus |
| 8 | { |
| 9 | namespace server |
| 10 | { |
| 11 | % for s in namespaces: |
| 12 | namespace ${s} |
| 13 | { |
| 14 | % endfor |
Patrick Williams | adc1682 | 2016-10-17 14:43:54 -0500 | [diff] [blame] | 15 | |
| 16 | ${classname}::${classname}(bus::bus& bus, const char* path) |
| 17 | : _${"_".join(interface.name.split('.'))}_interface( |
| 18 | bus, path, _interface, _vtable, this) |
| 19 | { |
| 20 | } |
| 21 | |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 22 | % for m in interface.methods: |
| 23 | ${ m.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } |
| 24 | % endfor |
| 25 | |
Patrick Williams | 5302a46 | 2016-10-18 11:11:51 -0500 | [diff] [blame] | 26 | % for s in interface.signals: |
| 27 | ${ s.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } |
| 28 | % endfor |
| 29 | |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame^] | 30 | % for p in interface.properties: |
| 31 | ${p.typeName} ${classname}::${p.camelCase}() const |
| 32 | { |
| 33 | return _${p.camelCase}; |
| 34 | } |
| 35 | |
| 36 | int ${classname}::_callback_get_${p.name}( |
| 37 | sd_bus* bus, const char* path, const char* interface, |
| 38 | const char* property, sd_bus_message* reply, void* context, |
| 39 | sd_bus_error* error) |
| 40 | { |
| 41 | auto m = message::message(sd_bus_message_ref(reply)); |
| 42 | |
| 43 | auto o = static_cast<${classname}*>(context); |
| 44 | m.append(o->${p.camelCase}()); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | ${p.typeName} ${classname}::${p.camelCase}(${p.typeName} value) |
| 50 | { |
| 51 | _${p.camelCase} = value; |
| 52 | |
| 53 | return _${p.camelCase}; |
| 54 | } |
| 55 | |
| 56 | int ${classname}::_callback_set_${p.name}( |
| 57 | sd_bus* bus, const char* path, const char* interface, |
| 58 | const char* property, sd_bus_message* value, void* context, |
| 59 | sd_bus_error* error) |
| 60 | { |
| 61 | auto m = message::message(sd_bus_message_ref(value)); |
| 62 | |
| 63 | auto o = static_cast<${classname}*>(context); |
| 64 | |
| 65 | decltype(_${p.camelCase}) v{}; |
| 66 | m.read(v); |
| 67 | o->${p.camelCase}(v); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | namespace details |
| 73 | { |
| 74 | namespace ${classname} |
| 75 | { |
| 76 | static const auto _property_${p.name} = |
| 77 | utility::tuple_to_array(message::types::type_id< |
| 78 | ${p.typeName}>()); |
| 79 | } |
| 80 | } |
| 81 | % endfor |
| 82 | |
Patrick Williams | 178e8fc | 2016-10-17 16:37:24 -0500 | [diff] [blame] | 83 | const vtable::vtable_t ${classname}::_vtable[] = { |
| 84 | vtable::start(), |
| 85 | % for m in interface.methods: |
| 86 | ${ m.cpp_prototype(loader, interface=interface, ptype='vtable') } |
| 87 | % endfor |
Patrick Williams | 5302a46 | 2016-10-18 11:11:51 -0500 | [diff] [blame] | 88 | % for s in interface.signals: |
| 89 | ${ s.cpp_prototype(loader, interface=interface, ptype='vtable') } |
| 90 | % endfor |
Patrick Williams | b2cca01 | 2016-10-18 14:13:39 -0500 | [diff] [blame^] | 91 | % for p in interface.properties: |
| 92 | vtable::property("${p.name}", |
| 93 | details::${classname}::_property_${p.name} |
| 94 | .data(), |
| 95 | _callback_get_${p.name}, |
| 96 | _callback_set_${p.name}), |
| 97 | % endfor |
Patrick Williams | 178e8fc | 2016-10-17 16:37:24 -0500 | [diff] [blame] | 98 | vtable::end() |
| 99 | }; |
| 100 | |
Patrick Williams | 831839a | 2016-10-16 18:09:00 -0500 | [diff] [blame] | 101 | % for s in namespaces: |
| 102 | } // namespace ${s} |
| 103 | % endfor |
| 104 | } // namespace server |
| 105 | } // namespace sdbusplus |