Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass committed Sep 28, 2023
1 parent b6da315 commit 982c6ea
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 63 deletions.
87 changes: 39 additions & 48 deletions everestrs/everestrs_sys/everestrs_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,65 @@

namespace {

std::unique_ptr<Everest::Everest> create_everest_instance(
const std::string& module_id, const Everest::RuntimeSettings& rs,
const Everest::Config& config) {
return std::make_unique<Everest::Everest>(
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<Everest::Everest> create_everest_instance(const std::string& module_id,
const Everest::RuntimeSettings& rs,
const Everest::Config& config) {
return std::make_unique<Everest::Everest>(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<Everest::Config> 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<Everest::Config>(
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<Everest::Config> 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<Everest::Config>(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<uint8_t> 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<uint8_t> 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<Module> create_module(rust::Str module_id, rust::Str prefix,
rust::Str conf) {
return std::make_unique<Module>(std::string(module_id), std::string(prefix),
std::string(conf));
std::unique_ptr<Module> create_module(rust::Str module_id, rust::Str prefix, rust::Str conf) {
return std::make_unique<Module>(std::string(module_id), std::string(prefix), std::string(conf));
}
28 changes: 13 additions & 15 deletions everestrs/everestrs_sys/everestrs_sys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Everest::Config> config_;
std::unique_ptr<Everest::Everest> handle_;
private:
const std::string module_id_;

Check notice on line 27 in everestrs/everestrs_sys/everestrs_sys.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

everestrs/everestrs_sys/everestrs_sys.hpp#L27

class member 'Module::module_id_' is never used.
Everest::RuntimeSettings rs_;
std::unique_ptr<Everest::Config> config_;
std::unique_ptr<Everest::Everest> handle_;
};

std::unique_ptr<Module> create_module(rust::Str module_name, rust::Str prefix,
rust::Str conf);
std::unique_ptr<Module> create_module(rust::Str module_name, rust::Str prefix, rust::Str conf);

0 comments on commit 982c6ea

Please sign in to comment.