Skip to content

Commit

Permalink
move error handling to everest.hpp
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Heinrich <[email protected]>
  • Loading branch information
andistorm committed Apr 30, 2024
1 parent 187c536 commit c0eee45
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions ev-dev-tools/src/ev_cli/templates/interface-Base.hpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@

class {{ info.class_name }} : public Everest::ImplementationBase {
public:
{{ info.class_name }}(Everest::ModuleAdapter* ev, const std::string& name) : Everest::ImplementationBase(), _ev(ev), _name(name) {
std::shared_ptr<Everest::error::ErrorDatabase> error_database(new Everest::error::ErrorDatabaseMap());
std::list<Everest::error::ErrorType> allowed_error_types = {
{% for error in errors %}
{"{{ error.namespace }}/{{ error.name }}"}{{ ',' if not loop.last }}
{% endfor %}
};
_error_manager = std::make_unique<Everest::error::ErrorManager>(error_type_map, error_database, allowed_error_types);
_error_state_monitor = std::make_unique<Everest::error::ErrorStateMonitor>(error_database);
};
{{ info.class_name }}(Everest::ModuleAdapter* ev, const std::string& name) : Everest::ImplementationBase(), _ev(ev), _name(name) {};

{% if not vars %}
// no variables defined for this interface
Expand Down Expand Up @@ -55,23 +46,17 @@ public:
{% endif %}

void raise_error(const error::Error& error) {
_error_manager->raise_error(error);
_ev->publish_error(error);
_ev->get_error_manager(_name)->raise_error(error);
}

void clear_error(const ErrorType& type, const ErrorSubType& sub_type) {
std::list<ErrorPtr> cleared_errors = _error_manager->clear_error(type, sub_type);
for (auto error : cleared_errors) {
_ev->publish_cleared_error(_name, error.get());
}
_ev->get_error_manager(_name)->clear_error(type, sub_type);
}

void clear_all_errors_of_impl() {
std::list<ErrorPtr> cleared_errors = _error_manager->clear_all_errors();
for (auto error : cleared_errors) {
_ev->publish_cleared_error(_name, error.get());
}
_ev->get_error_manager(_name)->clear_all_errors();
}

protected:
{% if not cmds %}
// no commands defined for this interface
Expand All @@ -84,8 +69,6 @@ protected:

private:
Everest::ModuleAdapter* const _ev;
std::unique_ptr<Everest::error::ErrorManager> _error_manager;
std::unique_ptr<Everest::error::ErrorStateMonitor> _error_state_monitor;
const std::string _name;

// helper function for getting all commands
Expand Down

0 comments on commit c0eee45

Please sign in to comment.