diff options
| author | Adriana Kobylak <anoo@us.ibm.com> | 2018-06-06 09:36:51 -0500 |
|---|---|---|
| committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2018-06-12 17:40:00 +0000 |
| commit | ee6ac694c3e21b24ebd2f32ef55249c5eb44bccd (patch) | |
| tree | 9bebb7d95f2606936901d92ea855c44b5f69b4bc | |
| parent | 51b20018323935796b4c4eb916f912c1876c96df (diff) | |
| download | sdbusplus-ee6ac694c3e21b24ebd2f32ef55249c5eb44bccd.tar.gz sdbusplus-ee6ac694c3e21b24ebd2f32ef55249c5eb44bccd.zip | |
property: Move property template to its own file
Move the template that generates the property-related code
to its own file out of the interface.mako file so that it's
easier/cleaner to add additional features to the property
template such as error handling.
Tested: Verified the generated code for the example
Calculator remained the same.
Change-Id: Idee37d4b1db6701ffc22de84a7a7ea07a2006d61
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
| -rw-r--r-- | configure.ac | 1 | ||||
| -rw-r--r-- | tools/sdbusplus/property.py | 4 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/interface.mako.server.cpp.in | 100 | ||||
| -rw-r--r-- | tools/sdbusplus/templates/property.mako.prototype.hpp.in | 106 |
4 files changed, 112 insertions, 99 deletions
diff --git a/configure.ac b/configure.ac index aedae42..9ca9f77 100644 --- a/configure.ac +++ b/configure.ac @@ -92,4 +92,5 @@ AC_CONFIG_FILES([sdbusplus/bus.hpp]) AC_CONFIG_FILES([sdbusplus/server.hpp]) AC_CONFIG_FILES([tools/sdbusplus/templates/interface.mako.server.cpp]) AC_CONFIG_FILES([tools/sdbusplus/templates/method.mako.prototype.hpp]) +AC_CONFIG_FILES([tools/sdbusplus/templates/property.mako.prototype.hpp]) AC_OUTPUT diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py index 7ed53ed..c6444c8 100644 --- a/tools/sdbusplus/property.py +++ b/tools/sdbusplus/property.py @@ -164,3 +164,7 @@ class Property(NamedElement, Renderer): def markdown(self, loader): return self.render(loader, "property.mako.md", property=self, post=str.strip) + + def cpp_prototype(self, loader, interface, ptype): + return self.render(loader, "property.mako.prototype.hpp", property=self, + interface=interface, ptype=ptype, post=str.rstrip) diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp.in b/tools/sdbusplus/templates/interface.mako.server.cpp.in index d519c26..4b46711 100644 --- a/tools/sdbusplus/templates/interface.mako.server.cpp.in +++ b/tools/sdbusplus/templates/interface.mako.server.cpp.in @@ -49,105 +49,7 @@ ${ s.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } % endfor % for p in interface.properties: -auto ${classname}::${p.camelCase}() const -> - ${p.cppTypeParam(interface.name)} -{ - return _${p.camelCase}; -} - -int ${classname}::_callback_get_${p.name}( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* reply, void* context, - sd_bus_error* error) -{ - using sdbusplus::server::binding::details::convertForMessage; - - // TODO(venture): Can this except? I wouldn't think so. - auto o = static_cast<${classname}*>(context); - - try - { - auto m = message::message(reply, o->_intf); - -#if @WANT_TRANSACTION@ - { - auto tbus = m.get_bus(); - sdbusplus::server::transaction::Transaction t(tbus, m); - sdbusplus::server::transaction::set_id - (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); - } -#endif - - m.append(convertForMessage(o->${p.camelCase}())); - } - catch(sdbusplus::internal_exception_t& e) - { - o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -auto ${classname}::${p.camelCase}(${p.cppTypeParam(interface.name)} value) -> - ${p.cppTypeParam(interface.name)} -{ - if (_${p.camelCase} != value) - { - _${p.camelCase} = value; - _${interface_instance()}.property_changed("${p.name}"); - } - - return _${p.camelCase}; -} - -int ${classname}::_callback_set_${p.name}( - sd_bus* bus, const char* path, const char* interface, - const char* property, sd_bus_message* value, void* context, - sd_bus_error* error) -{ - auto o = static_cast<${classname}*>(context); - - try - { - auto m = message::message(value, o->_intf); - -#if @WANT_TRANSACTION@ - { - auto tbus = m.get_bus(); - sdbusplus::server::transaction::Transaction t(tbus, m); - sdbusplus::server::transaction::set_id - (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); - } -#endif - - ${p.cppTypeMessage(interface.name)} v{}; - m.read(v); - % if p.is_enum(): - o->${p.camelCase}(${p.enum_namespace(interface.name)}\ -convert${p.enum_name(interface.name)}FromString(v)); - % else: - o->${p.camelCase}(v); - % endif - } - catch(sdbusplus::internal_exception_t& e) - { - o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); - return -EINVAL; - } - - return true; -} - -namespace details -{ -namespace ${classname} -{ -static const auto _property_${p.name} = - utility::tuple_to_array(message::types::type_id< - ${p.cppTypeMessage(interface.name)}>()); -} -} +${ p.cpp_prototype(loader, interface=interface, ptype='callback-cpp') } % endfor % if interface.properties: diff --git a/tools/sdbusplus/templates/property.mako.prototype.hpp.in b/tools/sdbusplus/templates/property.mako.prototype.hpp.in new file mode 100644 index 0000000..fd4a28e --- /dev/null +++ b/tools/sdbusplus/templates/property.mako.prototype.hpp.in @@ -0,0 +1,106 @@ +<% + namespaces = interface.name.split('.') + classname = namespaces.pop() + + def interface_instance(): + return "_".join(interface.name.split('.') + ['interface']) +%> +auto ${classname}::${property.camelCase}() const -> + ${property.cppTypeParam(interface.name)} +{ + return _${property.camelCase}; +} + +int ${classname}::_callback_get_${property.name}( + sd_bus* bus, const char* path, const char* interface, + const char* property, sd_bus_message* reply, void* context, + sd_bus_error* error) +{ + using sdbusplus::server::binding::details::convertForMessage; + + // TODO(venture): Can this except? I wouldn't think so. + auto o = static_cast<${classname}*>(context); + + try + { + auto m = message::message(reply, o->_intf); + +#if @WANT_TRANSACTION@ + { + auto tbus = m.get_bus(); + sdbusplus::server::transaction::Transaction t(tbus, m); + sdbusplus::server::transaction::set_id + (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); + } +#endif + + m.append(convertForMessage(o->${property.camelCase}())); + } + catch(sdbusplus::internal_exception_t& e) + { + o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); + return -EINVAL; + } + + return true; +} + +auto ${classname}::${property.camelCase}(${property.cppTypeParam(interface.name)} value) -> + ${property.cppTypeParam(interface.name)} +{ + if (_${property.camelCase} != value) + { + _${property.camelCase} = value; + _${interface_instance()}.property_changed("${property.name}"); + } + + return _${property.camelCase}; +} + +int ${classname}::_callback_set_${property.name}( + sd_bus* bus, const char* path, const char* interface, + const char* property, sd_bus_message* value, void* context, + sd_bus_error* error) +{ + auto o = static_cast<${classname}*>(context); + + try + { + auto m = message::message(value, o->_intf); + +#if @WANT_TRANSACTION@ + { + auto tbus = m.get_bus(); + sdbusplus::server::transaction::Transaction t(tbus, m); + sdbusplus::server::transaction::set_id + (std::hash<sdbusplus::server::transaction::Transaction>{}(t)); + } +#endif + + ${property.cppTypeMessage(interface.name)} v{}; + m.read(v); + % if property.is_enum(): + o->${property.camelCase}(${property.enum_namespace(interface.name)}\ +convert${property.enum_name(interface.name)}FromString(v)); + % else: + o->${property.camelCase}(v); + % endif + } + catch(sdbusplus::internal_exception_t& e) + { + o->_intf->sd_bus_error_set_const(error, e.name(), e.description()); + return -EINVAL; + } + + return true; +} + +namespace details +{ +namespace ${classname} +{ +static const auto _property_${property.name} = + utility::tuple_to_array(message::types::type_id< + ${property.cppTypeMessage(interface.name)}>()); +} +} |

