Adriana Kobylak | ee6ac69 | 2018-06-06 09:36:51 -0500 | [diff] [blame] | 1 | <% |
| 2 | namespaces = interface.name.split('.') |
| 3 | classname = namespaces.pop() |
| 4 | |
| 5 | def interface_instance(): |
| 6 | return "_".join(interface.name.split('.') + ['interface']) |
Adriana Kobylak | 75a2e25 | 2018-06-06 10:49:24 -0500 | [diff] [blame^] | 7 | |
| 8 | def error_namespace(e): |
| 9 | n = e.split('.'); |
| 10 | n.pop(); # Remove error name. |
| 11 | |
| 12 | n = map((lambda x: interface.name if x == "self" else x), n); |
| 13 | return '::'.join('.'.join(n).split('.')); |
| 14 | |
| 15 | def error_name(e): |
| 16 | return e.split('.').pop(); |
| 17 | |
| 18 | def error_include(e): |
| 19 | l = error_namespace(e).split('::') |
| 20 | l.pop() # Remove "Error" |
| 21 | return '/'.join(l) + '/error.hpp'; |
Adriana Kobylak | ee6ac69 | 2018-06-06 09:36:51 -0500 | [diff] [blame] | 22 | %> |
Adriana Kobylak | 75a2e25 | 2018-06-06 10:49:24 -0500 | [diff] [blame^] | 23 | % if ptype == 'callback-cpp': |
Adriana Kobylak | ee6ac69 | 2018-06-06 09:36:51 -0500 | [diff] [blame] | 24 | auto ${classname}::${property.camelCase}() const -> |
| 25 | ${property.cppTypeParam(interface.name)} |
| 26 | { |
| 27 | return _${property.camelCase}; |
| 28 | } |
| 29 | |
| 30 | int ${classname}::_callback_get_${property.name}( |
| 31 | sd_bus* bus, const char* path, const char* interface, |
| 32 | const char* property, sd_bus_message* reply, void* context, |
| 33 | sd_bus_error* error) |
| 34 | { |
| 35 | using sdbusplus::server::binding::details::convertForMessage; |
| 36 | |
| 37 | // TODO(venture): Can this except? I wouldn't think so. |
| 38 | auto o = static_cast<${classname}*>(context); |
| 39 | |
| 40 | try |
| 41 | { |
| 42 | auto m = message::message(reply, o->_intf); |
| 43 | |
| 44 | #if @WANT_TRANSACTION@ |
| 45 | { |
| 46 | auto tbus = m.get_bus(); |
| 47 | sdbusplus::server::transaction::Transaction t(tbus, m); |
| 48 | sdbusplus::server::transaction::set_id |
| 49 | (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | m.append(convertForMessage(o->${property.camelCase}())); |
| 54 | } |
| 55 | catch(sdbusplus::internal_exception_t& e) |
| 56 | { |
| 57 | o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); |
| 58 | return -EINVAL; |
| 59 | } |
Adriana Kobylak | 75a2e25 | 2018-06-06 10:49:24 -0500 | [diff] [blame^] | 60 | % for e in property.errors: |
| 61 | catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e) |
| 62 | { |
| 63 | o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); |
| 64 | return -EINVAL; |
| 65 | } |
| 66 | % endfor |
Adriana Kobylak | ee6ac69 | 2018-06-06 09:36:51 -0500 | [diff] [blame] | 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | auto ${classname}::${property.camelCase}(${property.cppTypeParam(interface.name)} value) -> |
| 72 | ${property.cppTypeParam(interface.name)} |
| 73 | { |
| 74 | if (_${property.camelCase} != value) |
| 75 | { |
| 76 | _${property.camelCase} = value; |
| 77 | _${interface_instance()}.property_changed("${property.name}"); |
| 78 | } |
| 79 | |
| 80 | return _${property.camelCase}; |
| 81 | } |
| 82 | |
| 83 | int ${classname}::_callback_set_${property.name}( |
| 84 | sd_bus* bus, const char* path, const char* interface, |
| 85 | const char* property, sd_bus_message* value, void* context, |
| 86 | sd_bus_error* error) |
| 87 | { |
| 88 | auto o = static_cast<${classname}*>(context); |
| 89 | |
| 90 | try |
| 91 | { |
| 92 | auto m = message::message(value, o->_intf); |
| 93 | |
| 94 | #if @WANT_TRANSACTION@ |
| 95 | { |
| 96 | auto tbus = m.get_bus(); |
| 97 | sdbusplus::server::transaction::Transaction t(tbus, m); |
| 98 | sdbusplus::server::transaction::set_id |
| 99 | (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); |
| 100 | } |
| 101 | #endif |
| 102 | |
| 103 | ${property.cppTypeMessage(interface.name)} v{}; |
| 104 | m.read(v); |
| 105 | % if property.is_enum(): |
| 106 | o->${property.camelCase}(${property.enum_namespace(interface.name)}\ |
| 107 | convert${property.enum_name(interface.name)}FromString(v)); |
| 108 | % else: |
| 109 | o->${property.camelCase}(v); |
| 110 | % endif |
| 111 | } |
| 112 | catch(sdbusplus::internal_exception_t& e) |
| 113 | { |
| 114 | o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); |
| 115 | return -EINVAL; |
| 116 | } |
Adriana Kobylak | 75a2e25 | 2018-06-06 10:49:24 -0500 | [diff] [blame^] | 117 | % for e in property.errors: |
| 118 | catch(sdbusplus::${error_namespace(e)}::${error_name(e)}& e) |
| 119 | { |
| 120 | o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); |
| 121 | return -EINVAL; |
| 122 | } |
| 123 | % endfor |
Adriana Kobylak | ee6ac69 | 2018-06-06 09:36:51 -0500 | [diff] [blame] | 124 | |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | namespace details |
| 129 | { |
| 130 | namespace ${classname} |
| 131 | { |
| 132 | static const auto _property_${property.name} = |
| 133 | utility::tuple_to_array(message::types::type_id< |
| 134 | ${property.cppTypeMessage(interface.name)}>()); |
| 135 | } |
| 136 | } |
Adriana Kobylak | 75a2e25 | 2018-06-06 10:49:24 -0500 | [diff] [blame^] | 137 | % elif ptype == 'callback-cpp-includes': |
| 138 | % for e in property.errors: |
| 139 | #include <${error_include(e)}> |
| 140 | % endfor |
| 141 | % endif |