From 3ed2262727b56f49cc07ac56fdcd2d8ddf928447 Mon Sep 17 00:00:00 2001 From: aw Date: Thu, 13 Jun 2024 12:06:47 +0200 Subject: [PATCH] bugfix(ev-cli): support array type in subscription - the json array object has been casted to `nlohman::json::array` so far, instead of `std::vector` for subscription - this commit introduces some code duplication, as it copies the handling from the `_gather_cmds` implementation -- this should be refactored - NOTE: the array of enum handling has not been checked bugfix: add correct type within public publish interface - NOTE: all of this different type if/elseing needs to be refactored if it should stay maintainable Signed-off-by: aw --- ev-dev-tools/src/ev_cli/__init__.py | 2 +- .../src/ev_cli/templates/interface-Base.hpp.j2 | 4 +++- .../src/ev_cli/templates/interface-Exports.hpp.j2 | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ev-dev-tools/src/ev_cli/__init__.py b/ev-dev-tools/src/ev_cli/__init__.py index 0fd09ab2..4962beba 100644 --- a/ev-dev-tools/src/ev_cli/__init__.py +++ b/ev-dev-tools/src/ev_cli/__init__.py @@ -1,2 +1,2 @@ """EVerest command line utility.""" -__version__ = '0.2.0' +__version__ = '0.2.1' diff --git a/ev-dev-tools/src/ev_cli/templates/interface-Base.hpp.j2 b/ev-dev-tools/src/ev_cli/templates/interface-Base.hpp.j2 index 367f9df5..96eb3d5a 100644 --- a/ev-dev-tools/src/ev_cli/templates/interface-Base.hpp.j2 +++ b/ev-dev-tools/src/ev_cli/templates/interface-Base.hpp.j2 @@ -48,7 +48,9 @@ public: // publish functions for variables {% for var in vars %} void publish_{{ var.name }}( - {%- if 'object_type' in var %} + {% if 'array_type' in var %} + const std::vector<{{ var.array_type }}>& + {%- elif 'object_type' in var %} {{- var.object_type }} {%- elif 'enum_type' in var %} {{- var.enum_type }} diff --git a/ev-dev-tools/src/ev_cli/templates/interface-Exports.hpp.j2 b/ev-dev-tools/src/ev_cli/templates/interface-Exports.hpp.j2 index a288705c..40f08624 100644 --- a/ev-dev-tools/src/ev_cli/templates/interface-Exports.hpp.j2 +++ b/ev-dev-tools/src/ev_cli/templates/interface-Exports.hpp.j2 @@ -50,6 +50,16 @@ public: {% elif 'enum_type' in var %} auto native_value = {{ string_to_enum(var.enum_type) }}({{ var_to_cpp(var) }}(value)); listener(native_value); + {% elif 'array_type' in var %} + {% if 'array_type_contains_enum' in var %} + std::vector<{{ arg.array_type }}> typed_value; + for (auto& entry : value) { + typed_value.push_back({{ string_to_enum(var.array_type) }}(entry)); + } + listener(typed_value); + {% else %} + listener(value); + {% endif %} {% elif var.json_type != 'null' %} listener({{ var_to_cpp(var) }}(value)); {% else %}