Skip to content

Commit

Permalink
Don't call again config
Browse files Browse the repository at this point in the history
Signed-off-by: Dima Dorezyuk <[email protected]>
  • Loading branch information
Dima Dorezyuk committed Oct 10, 2024
1 parent e6e0192 commit 5b80d0b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion everestrs/everestrs-build/jinja/module.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Module {
{% endfor %}
) -> ::std::sync::Arc<Self> {
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 %}
Expand Down
8 changes: 2 additions & 6 deletions everestrs/everestrs/src/everestrs_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,8 @@ rust::Vec<RsModuleConfig> get_module_configs(rust::Str module_id, rust::Str pref
return out;
}

rust::Vec<RsModuleConnections> get_module_connections(rust::Str module_id, rust::Str prefix, rust::Str config_file) {
const auto rs = std::make_shared<Everest::RuntimeSettings>(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<RsModuleConnections> 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<RsModuleConnections> out;
Expand All @@ -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};
Expand Down
3 changes: 2 additions & 1 deletion everestrs/everestrs/src/everestrs_sys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RsModuleConnections> get_module_connections() const;

private:
const std::string module_id_;
Expand All @@ -38,7 +39,7 @@ class Module {
std::unique_ptr<Module> create_module(rust::Str module_name, rust::Str prefix, rust::Str conf);

rust::Vec<RsModuleConfig> get_module_configs(rust::Str module_name, rust::Str prefix, rust::Str conf);
rust::Vec<RsModuleConnections> get_module_connections(rust::Str module_name, rust::Str prefix, rust::Str conf);
// rust::Vec<RsModuleConnections> 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);
38 changes: 14 additions & 24 deletions everestrs/everestrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RsModuleConnections>;

/// 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<RsModuleConfig>;

/// 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<RsModuleConnections>;

/// Call this once.
fn init_logging(module_id: &str, prefix: &str, conf: &str) -> i32;

Expand Down Expand Up @@ -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 {
Expand All @@ -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<String, usize> {
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
Expand Down Expand Up @@ -560,18 +565,3 @@ pub fn get_module_configs() -> HashMap<String, HashMap<String, Config>> {

out
}

/// The interface for fetching the module connections though the C++ runtime.
pub fn get_module_connections() -> HashMap<String, usize> {
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()
}

0 comments on commit 5b80d0b

Please sign in to comment.