-
Notifications
You must be signed in to change notification settings - Fork 20
Use shared error type map #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| #define UTILS_ERROR_MANAGER_REQ_HPP | ||
|
|
||
| #include <utils/error.hpp> | ||
| #include <utils/error/error_type_map.hpp> | ||
|
|
||
| #include <list> | ||
| #include <map> | ||
|
|
@@ -14,13 +15,12 @@ namespace Everest { | |
| namespace error { | ||
|
|
||
| struct ErrorDatabase; | ||
| struct ErrorTypeMap; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really get what the idea behind all the forward defines was - I've removed it to just use the ErrorTypeMapPtr type
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of forward declarations is to avoid including dependencies in the header file to reduce compile times after changing something in the included files |
||
|
|
||
| class ErrorManagerReq { | ||
| public: | ||
| using SubscribeErrorFunc = std::function<void(const ErrorType&, const ErrorCallback&, const ErrorCallback&)>; | ||
|
|
||
| ErrorManagerReq(std::shared_ptr<ErrorTypeMap> error_type_map, std::shared_ptr<ErrorDatabase> error_database, | ||
| ErrorManagerReq(ErrorTypeMap::ConstPtr error_type_map, std::shared_ptr<ErrorDatabase> error_database, | ||
| std::list<ErrorType> allowed_error_types, SubscribeErrorFunc subscribe_error_func); | ||
|
|
||
| void subscribe_error(const ErrorType& type, const ErrorCallback& callback, const ErrorCallback& clear_callback); | ||
|
|
@@ -42,7 +42,7 @@ class ErrorManagerReq { | |
|
|
||
| SubscribeErrorFunc subscribe_error_func; | ||
|
|
||
| std::shared_ptr<ErrorTypeMap> error_type_map; | ||
| ErrorTypeMap::ConstPtr error_type_map; | ||
| std::shared_ptr<ErrorDatabase> database; | ||
| std::list<ErrorType> allowed_error_types; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |||
| #define UTILS_ERROR_TYPE_MAP_HPP | ||||
|
|
||||
| #include <filesystem> | ||||
| #include <map> | ||||
| #include <memory> | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This dependency can be avoided, when not defining this
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also not sure if I understand - we use it in this library a lot. What do you mean with "avoid" the dependency? Are you concerned about the preprocessor adding this? |
||||
| #include <string> | ||||
|
|
||||
| #include <utils/error.hpp> | ||||
|
|
||||
|
|
@@ -50,6 +53,10 @@ class ErrorTypeMap { | |||
| /// | ||||
| bool has(const ErrorType& error_type) const; | ||||
|
|
||||
| /// Const pointer to a ErrorTypeMap. This is the default how we share the | ||||
| /// error type map between different classes. | ||||
| using ConstPtr = std::shared_ptr<const ErrorTypeMap>; | ||||
|
|
||||
|
Comment on lines
+56
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to keep using
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if i understand - we're using it |
||||
| private: | ||||
| std::map<ErrorType, std::string> error_types; | ||||
| }; | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -397,7 +397,7 @@ std::tuple<json, int> Config::load_and_validate_with_schema(const fs::path& file | |
| Config::Config(std::shared_ptr<RuntimeSettings> rs) : Config(rs, false) { | ||
| } | ||
|
|
||
| Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), manager(manager) { | ||
| Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), manager(manager), error_map{nullptr} { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default value is not needed, especially because it is initialized in the body of the constructor |
||
| BOOST_LOG_FUNCTION(); | ||
|
|
||
| this->manifests = json({}); | ||
|
|
@@ -406,7 +406,7 @@ Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), mana | |
| this->types = json({}); | ||
| this->errors = json({}); | ||
| this->_schemas = Config::load_schemas(this->rs->schemas_dir); | ||
| this->error_map = error::ErrorTypeMap(this->rs->errors_dir); | ||
| this->error_map = std::make_shared<error::ErrorTypeMap>(error::ErrorTypeMap(this->rs->errors_dir)); | ||
|
|
||
| // load and process config file | ||
| fs::path config_path = rs->config_file; | ||
|
|
@@ -551,7 +551,7 @@ Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), mana | |
| parse_3_tier_model_mapping(); | ||
| } | ||
|
|
||
| error::ErrorTypeMap Config::get_error_map() const { | ||
| error::ErrorTypeMap::ConstPtr Config::get_error_map() const { | ||
| return this->error_map; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,8 +73,7 @@ Everest::Everest(std::string module_id_, const Config& config_, bool validate_da | |
| this->subscribe_global_all_errors(callback, clear_callback); | ||
| }; | ||
| this->global_error_manager = std::make_shared<error::ErrorManagerReqGlobal>( | ||
| std::make_shared<error::ErrorTypeMap>(this->config.get_error_map()), global_error_database, | ||
| subscribe_global_all_errors_func); | ||
| this->config.get_error_map(), global_error_database, subscribe_global_all_errors_func); | ||
| this->global_error_state_monitor = std::make_shared<error::ErrorStateMonitor>(global_error_database); | ||
| } else { | ||
| this->global_error_manager = nullptr; | ||
|
|
@@ -103,9 +102,9 @@ Everest::Everest(std::string module_id_, const Config& config_, bool validate_da | |
| error::ErrorManagerImpl::PublishErrorFunc publish_cleared_error = [this, impl](const error::Error& error) { | ||
| this->publish_cleared_error(impl, error); | ||
| }; | ||
| this->impl_error_managers[impl] = std::make_shared<error::ErrorManagerImpl>( | ||
| std::make_shared<error::ErrorTypeMap>(this->config.get_error_map()), error_database, allowed_error_types, | ||
| publish_raised_error, publish_cleared_error); | ||
| this->impl_error_managers[impl] = | ||
| std::make_shared<error::ErrorManagerImpl>(this->config.get_error_map(), error_database, allowed_error_types, | ||
| publish_raised_error, publish_cleared_error); | ||
|
Comment on lines
+105
to
+107
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really get what changed here |
||
|
|
||
| // setup error state monitor | ||
| this->impl_error_state_monitors[impl] = std::make_shared<error::ErrorStateMonitor>(error_database); | ||
|
|
@@ -153,8 +152,8 @@ Everest::Everest(std::string module_id_, const Config& config_, bool validate_da | |
|
|
||
| // setup error factory | ||
| ImplementationIdentifier default_origin(this->module_id, impl, mapping); | ||
| this->error_factories[impl] = std::make_shared<error::ErrorFactory>( | ||
| std::make_shared<error::ErrorTypeMap>(this->config.get_error_map()), default_origin); | ||
| this->error_factories[impl] = | ||
| std::make_shared<error::ErrorFactory>(this->config.get_error_map(), default_origin); | ||
| } | ||
|
|
||
| // setup error_databases, error_managers and error_state_monitors for all requirements | ||
|
|
@@ -177,8 +176,7 @@ Everest::Everest(std::string module_id_, const Config& config_, bool validate_da | |
| this->subscribe_error(req, type, callback, clear_callback); | ||
| }; | ||
| this->req_error_managers[req] = std::make_shared<error::ErrorManagerReq>( | ||
| std::make_shared<error::ErrorTypeMap>(this->config.get_error_map()), error_database, allowed_error_types, | ||
| subscribe_error_func); | ||
| this->config.get_error_map(), error_database, allowed_error_types, subscribe_error_func); | ||
|
|
||
| // setup error state monitor | ||
| this->req_error_state_monitors[req] = std::make_shared<error::ErrorStateMonitor>(error_database); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep this forward declaration to avoid unnecessary dependencies in all these header files