diff --git a/include/utils/config.hpp b/include/utils/config.hpp index e5d0202e..b93d05ab 100644 --- a/include/utils/config.hpp +++ b/include/utils/config.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -122,7 +123,7 @@ class Config { void load_and_validate_manifest(const std::string& module_id, const json& module_config); - error::ErrorTypeMap error_map; + error::ErrorTypeMap::ConstPtr error_map; /// /// \brief loads and validates the given file \p file_path with the schema \p schema @@ -131,7 +132,7 @@ class Config { std::tuple load_and_validate_with_schema(const fs::path& file_path, const json& schema); public: - error::ErrorTypeMap get_error_map() const; + error::ErrorTypeMap::ConstPtr get_error_map() const; std::string get_module_name(const std::string& module_id) const; bool module_provides(const std::string& module_name, const std::string& impl_id); json get_module_cmds(const std::string& module_name, const std::string& impl_id); diff --git a/include/utils/error/error_factory.hpp b/include/utils/error/error_factory.hpp index 3be3fce3..be407d93 100644 --- a/include/utils/error/error_factory.hpp +++ b/include/utils/error/error_factory.hpp @@ -9,19 +9,18 @@ #include #include +#include namespace Everest { namespace error { -struct ErrorTypeMap; - class ErrorFactory { public: - explicit ErrorFactory(std::shared_ptr error_type_map); - ErrorFactory(std::shared_ptr error_type_map, ImplementationIdentifier default_origin); - ErrorFactory(std::shared_ptr error_type_map, ImplementationIdentifier default_origin, + explicit ErrorFactory(ErrorTypeMap::ConstPtr error_type_map); + ErrorFactory(ErrorTypeMap::ConstPtr error_type_map, ImplementationIdentifier default_origin); + ErrorFactory(ErrorTypeMap::ConstPtr error_type_map, ImplementationIdentifier default_origin, Severity default_severity); - ErrorFactory(std::shared_ptr error_type_map, std::optional default_origin, + ErrorFactory(ErrorTypeMap::ConstPtr error_type_map, std::optional default_origin, std::optional default_severity, std::optional default_state, std::optional default_type, std::optional default_sub_type, std::optional default_message, std::optional default_vendor_id); @@ -52,7 +51,7 @@ class ErrorFactory { std::optional default_message; std::optional default_vendor_id; - const std::shared_ptr error_type_map; + ErrorTypeMap::ConstPtr error_type_map; void set_description(Error& error) const; }; diff --git a/include/utils/error/error_manager_impl.hpp b/include/utils/error/error_manager_impl.hpp index 55079419..d3e7f723 100644 --- a/include/utils/error/error_manager_impl.hpp +++ b/include/utils/error/error_manager_impl.hpp @@ -8,6 +8,7 @@ #include #include +#include namespace Everest { namespace error { @@ -19,7 +20,7 @@ class ErrorManagerImpl { public: using PublishErrorFunc = std::function; - ErrorManagerImpl(std::shared_ptr error_type_map, std::shared_ptr error_database, + ErrorManagerImpl(ErrorTypeMap::ConstPtr error_type_map, std::shared_ptr error_database, std::list allowed_error_types, PublishErrorFunc publish_raised_error, PublishErrorFunc publish_cleared_error, const bool validate_error_types = true); @@ -61,7 +62,7 @@ class ErrorManagerImpl { PublishErrorFunc publish_cleared_error; std::shared_ptr database; - std::shared_ptr error_type_map; + ErrorTypeMap::ConstPtr error_type_map; std::list allowed_error_types; const bool validate_error_types; diff --git a/include/utils/error/error_manager_req.hpp b/include/utils/error/error_manager_req.hpp index 0389699e..f98fe62d 100644 --- a/include/utils/error/error_manager_req.hpp +++ b/include/utils/error/error_manager_req.hpp @@ -5,6 +5,7 @@ #define UTILS_ERROR_MANAGER_REQ_HPP #include +#include #include #include @@ -14,13 +15,12 @@ namespace Everest { namespace error { struct ErrorDatabase; -struct ErrorTypeMap; class ErrorManagerReq { public: using SubscribeErrorFunc = std::function; - ErrorManagerReq(std::shared_ptr error_type_map, std::shared_ptr error_database, + ErrorManagerReq(ErrorTypeMap::ConstPtr error_type_map, std::shared_ptr error_database, std::list 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 error_type_map; + ErrorTypeMap::ConstPtr error_type_map; std::shared_ptr database; std::list allowed_error_types; }; diff --git a/include/utils/error/error_manager_req_global.hpp b/include/utils/error/error_manager_req_global.hpp index 5589b0b3..53b430f2 100644 --- a/include/utils/error/error_manager_req_global.hpp +++ b/include/utils/error/error_manager_req_global.hpp @@ -5,6 +5,7 @@ #define UTILS_ERROR_MANAGER_REQ_GLOBAL_HPP #include +#include #include #include @@ -14,13 +15,12 @@ namespace Everest { namespace error { struct ErrorDatabase; -struct ErrorTypeMap; class ErrorManagerReqGlobal { public: using SubscribeGlobalAllErrorsFunc = std::function; - ErrorManagerReqGlobal(std::shared_ptr error_type_map, std::shared_ptr error_database, + ErrorManagerReqGlobal(ErrorTypeMap::ConstPtr error_type_map, std::shared_ptr error_database, SubscribeGlobalAllErrorsFunc subscribe_global_all_errors_func); void subscribe_global_all_errors(const ErrorCallback& callback, const ErrorCallback& clear_callback); @@ -39,7 +39,7 @@ class ErrorManagerReqGlobal { SubscribeGlobalAllErrorsFunc subscribe_global_all_errors_func; - std::shared_ptr error_type_map; + ErrorTypeMap::ConstPtr error_type_map; std::shared_ptr database; }; diff --git a/include/utils/error/error_type_map.hpp b/include/utils/error/error_type_map.hpp index 45934c7c..0f8809cc 100644 --- a/include/utils/error/error_type_map.hpp +++ b/include/utils/error/error_type_map.hpp @@ -5,6 +5,9 @@ #define UTILS_ERROR_TYPE_MAP_HPP #include +#include +#include +#include #include @@ -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; + private: std::map error_types; }; diff --git a/lib/config.cpp b/lib/config.cpp index b455d662..acd64282 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -397,7 +397,7 @@ std::tuple Config::load_and_validate_with_schema(const fs::path& file Config::Config(std::shared_ptr rs) : Config(rs, false) { } -Config::Config(std::shared_ptr rs, bool manager) : rs(rs), manager(manager) { +Config::Config(std::shared_ptr rs, bool manager) : rs(rs), manager(manager), error_map{nullptr} { BOOST_LOG_FUNCTION(); this->manifests = json({}); @@ -406,7 +406,7 @@ Config::Config(std::shared_ptr 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(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 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; } diff --git a/lib/error/error_factory.cpp b/lib/error/error_factory.cpp index 7983123d..b4e0c53d 100644 --- a/lib/error/error_factory.cpp +++ b/lib/error/error_factory.cpp @@ -8,23 +8,23 @@ namespace Everest { namespace error { -ErrorFactory::ErrorFactory(std::shared_ptr error_type_map_) : +ErrorFactory::ErrorFactory(ErrorTypeMap::ConstPtr error_type_map_) : ErrorFactory(error_type_map_, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt) { } -ErrorFactory::ErrorFactory(std::shared_ptr error_type_map_, ImplementationIdentifier default_origin_) : +ErrorFactory::ErrorFactory(ErrorTypeMap::ConstPtr error_type_map_, ImplementationIdentifier default_origin_) : ErrorFactory(error_type_map_, default_origin_, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt) { } -ErrorFactory::ErrorFactory(std::shared_ptr error_type_map_, ImplementationIdentifier default_origin_, +ErrorFactory::ErrorFactory(ErrorTypeMap::ConstPtr error_type_map_, ImplementationIdentifier default_origin_, Severity default_severity_) : ErrorFactory(error_type_map_, default_origin_, default_severity_, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt) { } -ErrorFactory::ErrorFactory(std::shared_ptr error_type_map_, +ErrorFactory::ErrorFactory(ErrorTypeMap::ConstPtr error_type_map_, std::optional default_origin_, std::optional default_severity_, std::optional default_state_, std::optional default_type_, std::optional default_sub_type_, diff --git a/lib/error/error_manager_impl.cpp b/lib/error/error_manager_impl.cpp index 52a6355b..f538e37e 100644 --- a/lib/error/error_manager_impl.cpp +++ b/lib/error/error_manager_impl.cpp @@ -5,7 +5,6 @@ #include #include -#include #include @@ -15,7 +14,7 @@ namespace Everest { namespace error { -ErrorManagerImpl::ErrorManagerImpl(std::shared_ptr error_type_map_, +ErrorManagerImpl::ErrorManagerImpl(ErrorTypeMap::ConstPtr error_type_map_, std::shared_ptr error_database_, std::list allowed_error_types_, ErrorManagerImpl::PublishErrorFunc publish_raised_error_, diff --git a/lib/error/error_manager_req.cpp b/lib/error/error_manager_req.cpp index 1d103527..749cf9a4 100644 --- a/lib/error/error_manager_req.cpp +++ b/lib/error/error_manager_req.cpp @@ -6,15 +6,13 @@ #include #include #include -#include #include namespace Everest { namespace error { -ErrorManagerReq::ErrorManagerReq(std::shared_ptr error_type_map_, - std::shared_ptr error_database_, +ErrorManagerReq::ErrorManagerReq(ErrorTypeMap::ConstPtr error_type_map_, std::shared_ptr error_database_, std::list allowed_error_types_, SubscribeErrorFunc subscribe_error_func_) : error_type_map(error_type_map_), database(error_database_), diff --git a/lib/error/error_manager_req_global.cpp b/lib/error/error_manager_req_global.cpp index a846a9dd..9c2338f5 100644 --- a/lib/error/error_manager_req_global.cpp +++ b/lib/error/error_manager_req_global.cpp @@ -5,12 +5,11 @@ #include #include -#include namespace Everest { namespace error { -ErrorManagerReqGlobal::ErrorManagerReqGlobal(std::shared_ptr error_type_map_, +ErrorManagerReqGlobal::ErrorManagerReqGlobal(ErrorTypeMap::ConstPtr error_type_map_, std::shared_ptr error_database_, SubscribeGlobalAllErrorsFunc subscribe_global_all_errors_func_) : error_type_map(error_type_map_), diff --git a/lib/everest.cpp b/lib/everest.cpp index 8d870dc6..8a670265 100644 --- a/lib/everest.cpp +++ b/lib/everest.cpp @@ -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( - std::make_shared(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(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( - std::make_shared(this->config.get_error_map()), error_database, allowed_error_types, - publish_raised_error, publish_cleared_error); + this->impl_error_managers[impl] = + std::make_shared(this->config.get_error_map(), error_database, allowed_error_types, + publish_raised_error, publish_cleared_error); // setup error state monitor this->impl_error_state_monitors[impl] = std::make_shared(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( - std::make_shared(this->config.get_error_map()), default_origin); + this->error_factories[impl] = + std::make_shared(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( - std::make_shared(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_database);