Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a macro to remove fmi logging code in the callback function. #679

Merged
merged 9 commits into from
Mar 1, 2022
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used
option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF)
option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF)
option(LIBCOSIM_NO_FMI_LOGGING "Disable FMI logging during simulation" OFF)

# ==============================================================================
# Global internal configuration
# ==============================================================================

# Configure logging in the fmi callback function
if(LIBCOSIM_NO_FMI_LOGGING)
add_compile_definitions(LIBCOSIM_NO_FMI_LOGGING=1)
endif()

# Our custom CMake scripts go in the cmake/ subdirectory.
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake")

Expand Down
7 changes: 5 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class LibcosimConan(ConanFile):

options = {
"shared": [True, False],
"proxyfmu": [True, False]}
"proxyfmu": [True, False],
"no_fmi_logging": [True, False]}
default_options = (
"proxyfmu=False",
"shared=True"
"shared=True",
"no_fmi_logging=False"
)

def is_tests_enabled(self):
Expand Down Expand Up @@ -65,6 +67,7 @@ def configure_cmake(self):
cmake.definitions["LIBCOSIM_BUILD_APIDOC"] = "OFF"
cmake.definitions["LIBCOSIM_BUILD_TESTS"] = self.is_tests_enabled()
cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared
cmake.definitions["LIBCOSIM_NO_FMI_LOGGING"] = self.options.no_fmi_logging
if self.options.proxyfmu:
cmake.definitions["LIBCOSIM_WITH_PROXYFMU"] = "ON"
cmake.configure()
Expand Down
9 changes: 9 additions & 0 deletions src/cosim/fmi/v1/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,20 @@ std::mutex g_logMutex;

void log_message(
fmi1_component_t,
#ifndef LIBCOSIM_NO_FMI_LOGGING
fmi1_string_t instanceName,
fmi1_status_t status,
fmi1_string_t category,
fmi1_string_t message,
#else
fmi1_string_t,
fmi1_status_t,
fmi1_string_t,
fmi1_string_t,
#endif
...)
{
#ifndef LIBCOSIM_NO_FMI_LOGGING
std::va_list args;
va_start(args, message);
const auto msgLength = std::vsnprintf(nullptr, 0, message, args);
Expand Down Expand Up @@ -242,6 +250,7 @@ void log_message(
g_logRecords[instanceName] =
log_record{status, std::string(msgBuffer.data())};
g_logMutex.unlock();
#endif
}

log_record last_log_record(const std::string& instanceName)
Expand Down
9 changes: 9 additions & 0 deletions src/cosim/fmi/v2/fmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,20 @@ std::mutex g_logMutex;

void log_message(
fmi2_component_environment_t,
#ifndef LIBCOSIM_NO_FMI_LOGGING
fmi2_string_t instanceName,
fmi2_status_t status,
fmi2_string_t category,
fmi2_string_t message,
#else
fmi2_string_t,
fmi2_status_t,
fmi2_string_t,
fmi2_string_t,
#endif
...)
{
#ifndef LIBCOSIM_NO_FMI_LOGGING
std::va_list args;
va_start(args, message);
const auto msgLength = std::vsnprintf(nullptr, 0, message, args);
Expand Down Expand Up @@ -242,6 +250,7 @@ void log_message(
g_logRecords[instanceName] =
log_record{status, std::string(msgBuffer.data())};
g_logMutex.unlock();
#endif
}

log_record last_log_record(const std::string& instanceName)
Expand Down