Skip to content

Commit

Permalink
Merge branch 'main' into feature/restructure-mqtt-config
Browse files Browse the repository at this point in the history
  • Loading branch information
hikinggrass authored Jan 29, 2025
2 parents ee90bf1 + 84395f2 commit 26f70b0
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 198 deletions.
13 changes: 7 additions & 6 deletions include/framework/everest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,18 @@ class Everest {

///
/// \brief Subscribes to an error of another module indentified by the given \p req and error type
/// \p error_type. The given \p callback is called when a new error is raised and \p clear_callback is called when
/// an error is cleared
/// \p error_type. The given \p raise_callback is called when a new error is raised and \p clear_callback is called
/// when an error is cleared
///
void subscribe_error(const Requirement& req, const error::ErrorType& error_type,
const error::ErrorCallback& callback, const error::ErrorCallback& clear_callback);
const error::ErrorCallback& raise_callback, const error::ErrorCallback& clear_callback);

///
/// \brief Subscribes globally to all errors of all modules. The given \p callback is called when a new error is
/// raised. The given \p clear_callback is called when an error is cleared
/// \brief Subscribes globally to all errors of all modules. The given \p raise_callback is called when a new error
/// is raised. The given \p clear_callback is called when an error is cleared
///
void subscribe_global_all_errors(const error::ErrorCallback& callback, const error::ErrorCallback& clear_callback);
void subscribe_global_all_errors(const error::ErrorCallback& raise_callback,
const error::ErrorCallback& clear_callback);

///
/// \brief Check that external MQTT is configured - raises exception on error
Expand Down
73 changes: 44 additions & 29 deletions include/utils/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ struct RuntimeSettings;
///
/// \brief A structure that contains all available schemas
///
struct schemas {
struct Schemas {
nlohmann::json config; ///< The config schema
nlohmann::json manifest; ///< The manifest scheme
nlohmann::json interface; ///< The interface schema
nlohmann::json type; ///< The type schema
nlohmann::json error_declaration_list; ///< The error-declaration-list schema
};

struct Validators {
nlohmann::json_schema::json_validator config;
nlohmann::json_schema::json_validator manifest;
nlohmann::json_schema::json_validator type;
nlohmann::json_schema::json_validator interface;
nlohmann::json_schema::json_validator error_declaration_list;
};

struct SchemaValidation {
Schemas schemas;
Validators validators;
};

///
/// \brief Allowed format of a type URI, which are of a format like this /type_file_name#/TypeName
///
Expand All @@ -50,6 +63,30 @@ struct ImplementationInfo {
std::string impl_intf;
};

///
/// \brief A simple json schema loader that uses the builtin draft7 schema of
/// the json schema validator when it encounters it, throws an exception
/// otherwise
void loader(const nlohmann::json_uri& uri, nlohmann::json& schema);

///
/// \brief An extension to the default format checker of the json schema
/// validator supporting uris
void format_checker(const std::string& format, const std::string& value);

///
/// \brief loads and validates a json schema at the provided \p path
///
/// \returns the loaded json schema as a json object as well as a related schema validator
std::tuple<nlohmann::json, nlohmann::json_schema::json_validator> load_schema(const fs::path& path);

///
/// \brief loads the config.json and manifest.json in the schemes subfolder of
/// the provided \p schemas_dir
///
/// \returns the loaded configs and related validators
SchemaValidation load_schemas(const fs::path& schemas_dir);

///
/// \brief Base class for configs
///
Expand All @@ -62,7 +99,7 @@ class ConfigBase {
nlohmann::json interfaces;
nlohmann::json interface_definitions;
nlohmann::json types;
schemas _schemas;
Schemas schemas;

std::unordered_map<std::string, ModuleTierMappings> tier_mappings;
// experimental caches
Expand Down Expand Up @@ -190,6 +227,8 @@ class ManagerConfig : public ConfigBase {
private:
const ManagerSettings& ms;
std::unordered_map<std::string, std::optional<TelemetryConfig>> telemetry_configs;
Validators validators;
std::unique_ptr<nlohmann::json_schema::json_validator> draft7_validator;

///
/// \brief loads and validates the manifest of the module \p module_id using the provided \p module config
Expand Down Expand Up @@ -324,19 +363,6 @@ class Config : public ConfigBase {
/// otherwise
void ref_loader(const nlohmann::json_uri& uri, nlohmann::json& schema);

///
/// \brief loads the config.json and manifest.json in the schemes subfolder of
/// the provided \p schemas_dir
///
/// \returns the config and manifest schemas
static schemas load_schemas(const fs::path& schemas_dir);

///
/// \brief loads and validates a json schema at the provided \p path
///
/// \returns the loaded json schema as a json object
static nlohmann::json load_schema(const fs::path& path);

///
/// \brief loads all module manifests relative to the \p main_dir
///
Expand All @@ -348,25 +374,14 @@ class Config : public ConfigBase {
///
/// \returns a set of object keys
static std::set<std::string> keys(const nlohmann::json& object);

///
/// \brief A simple json schema loader that uses the builtin draft7 schema of
/// the json schema validator when it encounters it, throws an exception
/// otherwise
static void loader(const nlohmann::json_uri& uri, nlohmann::json& schema);

///
/// \brief An extension to the default format checker of the json schema
/// validator supporting uris
static void format_checker(const std::string& format, const std::string& value);
};
} // namespace Everest

NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<Everest::schemas> {
static void to_json(nlohmann::json& j, const Everest::schemas& s);
template <> struct adl_serializer<Everest::Schemas> {
static void to_json(nlohmann::json& j, const Everest::Schemas& s);

static void from_json(const nlohmann::json& j, Everest::schemas& s);
static void from_json(const nlohmann::json& j, Everest::Schemas& s);
};
NLOHMANN_JSON_NAMESPACE_END

Expand Down
Loading

0 comments on commit 26f70b0

Please sign in to comment.