diff --git a/everestrs/everestrs_sys/everestrs_sys.cpp b/everestrs/everestrs_sys/everestrs_sys.cpp index 2e2f63e9..f553efed 100644 --- a/everestrs/everestrs_sys/everestrs_sys.cpp +++ b/everestrs/everestrs_sys/everestrs_sys.cpp @@ -7,74 +7,65 @@ namespace { -std::unique_ptr create_everest_instance( - const std::string& module_id, const Everest::RuntimeSettings& rs, - const Everest::Config& config) { - return std::make_unique( - module_id, config, true /* FIXME */, rs.mqtt_broker_host, - rs.mqtt_broker_port, rs.mqtt_everest_prefix, rs.mqtt_external_prefix, - rs.telemetry_prefix, rs.telemetry_enabled); +std::unique_ptr create_everest_instance(const std::string& module_id, + const Everest::RuntimeSettings& rs, + const Everest::Config& config) { + return std::make_unique(module_id, config, true /* FIXME */, rs.mqtt_broker_host, + rs.mqtt_broker_port, rs.mqtt_everest_prefix, rs.mqtt_external_prefix, + rs.telemetry_prefix, rs.telemetry_enabled); } -std::unique_ptr create_config_instance( - const Everest::RuntimeSettings& rs) { - // FIXME (aw): where to initialize the logger? - Everest::Logging::init(rs.logging_config_file); - return std::make_unique( - rs.schemas_dir.string(), rs.config_file.string(), rs.modules_dir.string(), - rs.interfaces_dir.string(), rs.types_dir.string(), rs.mqtt_everest_prefix, - rs.mqtt_external_prefix); +std::unique_ptr create_config_instance(const Everest::RuntimeSettings& rs) { + // FIXME (aw): where to initialize the logger? + Everest::Logging::init(rs.logging_config_file); + return std::make_unique(rs.schemas_dir.string(), rs.config_file.string(), rs.modules_dir.string(), + rs.interfaces_dir.string(), rs.types_dir.string(), rs.mqtt_everest_prefix, + rs.mqtt_external_prefix); } JsonBlob json2blob(const json& j) { - // I did not find a way to not copy the data at least once here. - const std::string dumped = j.dump(); - rust::Vec vec; - vec.reserve(dumped.size()); - std::copy(dumped.begin(), dumped.end(), std::back_inserter(vec)); - return JsonBlob{vec}; + // I did not find a way to not copy the data at least once here. + const std::string dumped = j.dump(); + rust::Vec vec; + vec.reserve(dumped.size()); + std::copy(dumped.begin(), dumped.end(), std::back_inserter(vec)); + return JsonBlob{vec}; } -} // namespace +} // namespace -Module::Module(const std::string& module_id, const std::string& prefix, - const std::string& config_file) - : module_id_(module_id), - rs_(prefix, config_file), - config_(create_config_instance(rs_)), - handle_(create_everest_instance(module_id, rs_, *config_)) {} +Module::Module(const std::string& module_id, const std::string& prefix, const std::string& config_file) : + module_id_(module_id), + rs_(prefix, config_file), + config_(create_config_instance(rs_)), + handle_(create_everest_instance(module_id, rs_, *config_)) { +} JsonBlob Module::get_interface(rust::Str interface_name) const { - const auto& interface_def = - config_->get_interface_definition(std::string(interface_name)); - return json2blob(interface_def); + const auto& interface_def = config_->get_interface_definition(std::string(interface_name)); + return json2blob(interface_def); } JsonBlob Module::initialize() { - handle_->connect(); - handle_->spawn_main_loop_thread(); + handle_->connect(); + handle_->spawn_main_loop_thread(); - const std::string& module_name = - config_->get_main_config().at(module_id_).at("module"); - return json2blob(config_->get_manifests().at(module_name)); + const std::string& module_name = config_->get_main_config().at(module_id_).at("module"); + return json2blob(config_->get_manifests().at(module_name)); } void Module::signal_ready(const Runtime& rt) const { - handle_->register_on_ready_handler([&rt]() { rt.on_ready(); }); - handle_->signal_ready(); + handle_->register_on_ready_handler([&rt]() { rt.on_ready(); }); + handle_->signal_ready(); } void Module::provide_command(const Runtime& rt, const CommandMeta& meta) const { - handle_->provide_cmd(std::string(meta.implementation_id), - std::string(meta.name), - [&rt, meta](json args) { - JsonBlob blob = rt.handle_command(meta, json2blob(args)); - return json::parse(blob.data.begin(), blob.data.end()); - }); + handle_->provide_cmd(std::string(meta.implementation_id), std::string(meta.name), [&rt, meta](json args) { + JsonBlob blob = rt.handle_command(meta, json2blob(args)); + return json::parse(blob.data.begin(), blob.data.end()); + }); } -std::unique_ptr create_module(rust::Str module_id, rust::Str prefix, - rust::Str conf) { - return std::make_unique(std::string(module_id), std::string(prefix), - std::string(conf)); +std::unique_ptr create_module(rust::Str module_id, rust::Str prefix, rust::Str conf) { + return std::make_unique(std::string(module_id), std::string(prefix), std::string(conf)); } diff --git a/everestrs/everestrs_sys/everestrs_sys.hpp b/everestrs/everestrs_sys/everestrs_sys.hpp index 879dfafb..e2f40864 100644 --- a/everestrs/everestrs_sys/everestrs_sys.hpp +++ b/everestrs/everestrs_sys/everestrs_sys.hpp @@ -12,24 +12,22 @@ struct JsonBlob; struct Runtime; class Module { - public: - Module(const std::string& module_id, const std::string& prefix, - const std::string& conf); +public: + Module(const std::string& module_id, const std::string& prefix, const std::string& conf); - JsonBlob initialize(); - JsonBlob get_interface(rust::Str interface_name) const; + JsonBlob initialize(); + JsonBlob get_interface(rust::Str interface_name) const; - void signal_ready(const Runtime&rt) const; - void provide_command(const Runtime& rt,const CommandMeta& meta) const; + void signal_ready(const Runtime& rt) const; + void provide_command(const Runtime& rt, const CommandMeta& meta) const; - // TODO(hrapp): Add call_command, publish_variable and subscribe_variable. + // TODO(hrapp): Add call_command, publish_variable and subscribe_variable. - private: - const std::string module_id_; - Everest::RuntimeSettings rs_; - std::unique_ptr config_; - std::unique_ptr handle_; +private: + const std::string module_id_; + Everest::RuntimeSettings rs_; + std::unique_ptr config_; + std::unique_ptr handle_; }; -std::unique_ptr create_module(rust::Str module_name, rust::Str prefix, - rust::Str conf); +std::unique_ptr create_module(rust::Str module_name, rust::Str prefix, rust::Str conf);