diff --git a/everestrs/everestrs-build/jinja/module.jinja2 b/everestrs/everestrs-build/jinja/module.jinja2 index 2ff50008..6909512b 100644 --- a/everestrs/everestrs-build/jinja/module.jinja2 +++ b/everestrs/everestrs-build/jinja/module.jinja2 @@ -105,7 +105,7 @@ impl Module { {% endfor %} ) -> ::std::sync::Arc { let runtime = ::everestrs::Runtime::new(); - let connections = ::everestrs::get_module_connections(); + let connections = runtime.get_module_connections(); let this = ::std::sync::Arc::new(Self { on_ready, {% for provide in provides %} diff --git a/everestrs/everestrs/src/everestrs_sys.cpp b/everestrs/everestrs/src/everestrs_sys.cpp index a03cd2c5..08e7a65f 100644 --- a/everestrs/everestrs/src/everestrs_sys.cpp +++ b/everestrs/everestrs/src/everestrs_sys.cpp @@ -155,11 +155,8 @@ rust::Vec get_module_configs(rust::Str module_id, rust::Str pref return out; } -rust::Vec get_module_connections(rust::Str module_id, rust::Str prefix, rust::Str config_file) { - const auto rs = std::make_shared(std::string(prefix), std::string(config_file)); - Everest::Config config{rs}; - - const auto connections = config.get_main_config().at(std::string(module_id))["connections"]; +rust::Vec Module::get_module_connections() const { + const auto connections = config_->get_main_config().at(std::string(module_id_))["connections"]; // Iterate over the connections block. rust::Vec out; @@ -174,7 +171,6 @@ int init_logging(rust::Str module_id, rust::Str prefix, rust::Str config_file) { using namespace boost::log; using namespace Everest::Logging; - const std::string module_id_cpp{module_id}; const std::string prefix_cpp{prefix}; const std::string config_file_cpp{config_file}; diff --git a/everestrs/everestrs/src/everestrs_sys.hpp b/everestrs/everestrs/src/everestrs_sys.hpp index 00e50132..647b2e3d 100644 --- a/everestrs/everestrs/src/everestrs_sys.hpp +++ b/everestrs/everestrs/src/everestrs_sys.hpp @@ -27,6 +27,7 @@ class Module { JsonBlob call_command(rust::Str implementation_id, size_t index, rust::Str name, JsonBlob args) const; void subscribe_variable(const Runtime& rt, rust::String implementation_id, size_t index, rust::String name) const; void publish_variable(rust::Str implementation_id, rust::Str name, JsonBlob blob) const; + rust::Vec get_module_connections() const; private: const std::string module_id_; @@ -38,7 +39,7 @@ class Module { std::unique_ptr create_module(rust::Str module_name, rust::Str prefix, rust::Str conf); rust::Vec get_module_configs(rust::Str module_name, rust::Str prefix, rust::Str conf); -rust::Vec get_module_connections(rust::Str module_name, rust::Str prefix, rust::Str conf); +// rust::Vec get_module_connections(rust::Str module_name, rust::Str prefix, rust::Str conf); int init_logging(rust::Str module_name, rust::Str prefix, rust::Str conf); void log2cxx(int level, int line, rust::Str file, rust::Str message); diff --git a/everestrs/everestrs/src/lib.rs b/everestrs/everestrs/src/lib.rs index 70d0dde2..43f69be0 100644 --- a/everestrs/everestrs/src/lib.rs +++ b/everestrs/everestrs/src/lib.rs @@ -159,20 +159,16 @@ mod ffi { name: String, ); + /// Returns the `connections` block defined in the `config.yaml` for + /// the current module. + fn get_module_connections(self: &Module) -> Vec; + /// Publishes the given `blob` under the `implementation_id` and `name`. fn publish_variable(self: &Module, implementation_id: &str, name: &str, blob: JsonBlob); /// Returns the module config from cpp. fn get_module_configs(module_id: &str, prefix: &str, conf: &str) -> Vec; - /// Returns the `connections` block defined in the `config.yaml` for - /// the current module. - fn get_module_connections( - module_id: &str, - prefix: &str, - conf: &str, - ) -> Vec; - /// Call this once. fn init_logging(module_id: &str, prefix: &str, conf: &str) -> i32; @@ -439,7 +435,7 @@ impl Runtime { } } - let connections = get_module_connections(); + let connections = self.get_module_connections(); // Subscribe to all variables that might be of interest. for (implementation_id, requires) in manifest.requires { @@ -463,6 +459,15 @@ impl Runtime { // again. (self.cpp_module).as_ref().unwrap().signal_ready(self); } + + /// The interface for fetching the module connections though the C++ runtime. + pub fn get_module_connections(&self) -> HashMap { + let raw_connections = self.cpp_module.as_ref().unwrap().get_module_connections(); + raw_connections + .into_iter() + .map(|connection| (connection.implementation_id, connection.slots)) + .collect() + } } /// A store for our config values. The type is closely related to @@ -560,18 +565,3 @@ pub fn get_module_configs() -> HashMap> { out } - -/// The interface for fetching the module connections though the C++ runtime. -pub fn get_module_connections() -> HashMap { - let args: Args = argh::from_env(); - let raw_connections = ffi::get_module_connections( - &args.module, - &args.prefix.to_string_lossy(), - &args.conf.to_string_lossy(), - ); - - raw_connections - .into_iter() - .map(|connection| (connection.implementation_id, connection.slots)) - .collect() -}