Skip to content

Commit

Permalink
disable_logging parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhjp01 committed Feb 15, 2022
1 parent f854df0 commit 9a6690e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
7 changes: 7 additions & 0 deletions include/cosim/fmi/fmu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class fmu
virtual std::shared_ptr<fmi::importer> importer() const = 0;

virtual ~fmu() { }

void disable_logging(bool disabled) { logging_disabled = disabled; }

bool is_logging_disabled() const { return logging_disabled; }

protected:
bool logging_disabled;
};


Expand Down
5 changes: 3 additions & 2 deletions include/cosim/orchestration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ class model_uri_resolver
class fmu_file_uri_sub_resolver : public model_uri_sub_resolver
{
public:
fmu_file_uri_sub_resolver();
explicit fmu_file_uri_sub_resolver(bool disable_logging = false);

explicit fmu_file_uri_sub_resolver(std::shared_ptr<file_cache> cache);
explicit fmu_file_uri_sub_resolver(std::shared_ptr<file_cache> cache, bool disable_logging = false);

std::shared_ptr<model> lookup_model(const uri& modelUri) override;

private:
std::shared_ptr<fmi::importer> importer_;
bool disable_logging;
};


Expand Down
9 changes: 1 addition & 8 deletions src/cosim/fmi/v1/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,10 @@ slave_instance::slave_instance(
fmu->importer()->last_error_message());
}

auto fmi_no_logging_env = std::getenv("LIBCOSIM_NO_FMI_LOGGING");
long fmi_no_logging = -1;
if (fmi_no_logging_env) {
char* ptr;
fmi_no_logging = strtol(fmi_no_logging_env, &ptr, 10);
}

fmi1_callback_functions_t callbacks;
callbacks.allocateMemory = std::calloc;
callbacks.freeMemory = std::free;
callbacks.logger = (fmi_no_logging == 1) ? empty_log_message : log_message;
callbacks.logger = fmu->is_logging_disabled() ? empty_log_message : log_message;
callbacks.stepFinished = step_finished_placeholder;

if (fmi1_import_create_dllfmu(handle_, callbacks, false) != jm_status_success) {
Expand Down
9 changes: 1 addition & 8 deletions src/cosim/fmi/v2/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,10 @@ slave_instance::slave_instance(
fmu->importer()->last_error_message());
}

auto fmi_no_logging_env = std::getenv("LIBCOSIM_NO_FMI_LOGGING");
long fmi_no_logging = -1;
if (fmi_no_logging_env) {
char* ptr;
fmi_no_logging = strtol(fmi_no_logging_env, &ptr, 10);
}

fmi2_callback_functions_t callbacks;
callbacks.allocateMemory = std::calloc;
callbacks.freeMemory = std::free;
callbacks.logger = (fmi_no_logging == 1) ? empty_log_message : log_message;
callbacks.logger = fmu->is_logging_disabled() ? empty_log_message : log_message;
callbacks.stepFinished = step_finished_placeholder;
callbacks.componentEnvironment = nullptr;

Expand Down
8 changes: 6 additions & 2 deletions src/cosim/orchestration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,18 @@ class fmu_model : public model
} // namespace


fmu_file_uri_sub_resolver::fmu_file_uri_sub_resolver()
fmu_file_uri_sub_resolver::fmu_file_uri_sub_resolver(bool disable_logging)
: importer_(fmi::importer::create())
, disable_logging(disable_logging)
{
}


fmu_file_uri_sub_resolver::fmu_file_uri_sub_resolver(
std::shared_ptr<file_cache> cache)
std::shared_ptr<file_cache> cache,
bool disable_logging)
: importer_(fmi::importer::create(cache))
, disable_logging(disable_logging)
{
}

Expand All @@ -128,6 +131,7 @@ std::shared_ptr<model> fmu_file_uri_sub_resolver::lookup_model(const uri& modelU
const auto path = file_uri_to_path(modelUri);
if (path.extension() != ".fmu") return nullptr;
auto fmu = importer_->import(path);
fmu->disable_logging(disable_logging);
return std::make_shared<fmu_model>(fmu);
}

Expand Down

0 comments on commit 9a6690e

Please sign in to comment.