From 64912864d57f29dc5812fa3c6b33e915a6199879 Mon Sep 17 00:00:00 2001 From: Philipp Date: Thu, 27 May 2021 15:45:56 +0200 Subject: [PATCH 01/32] initial testing --- co_sim_io/impl/co_sim_io_impl.hpp | 7 ++- tests/CMakeLists.txt | 22 +++++++++ tests/co_sim_io/impl/singleton_tests/main.cpp | 47 +++++++++++++++++++ .../co_sim_io/impl/singleton_tests/main2.cpp | 18 +++++++ .../impl/singleton_tests/main_partner.cpp | 41 ++++++++++++++++ .../co_sim_io/impl/singleton_tests/sub_1.cpp | 28 +++++++++++ .../co_sim_io/impl/singleton_tests/sub_1.hpp | 19 ++++++++ .../co_sim_io/impl/singleton_tests/sub_12.cpp | 14 ++++++ .../impl/test_include_co_sim_io_1.cpp | 1 + .../impl/test_include_co_sim_io_2.cpp | 1 + 10 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/main.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/main2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/main_partner.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/sub_1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/sub_1.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/sub_12.cpp diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 279a4943..815a7ab5 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -30,7 +30,12 @@ namespace CoSimIO { namespace Internals { // TODO make sure this is unique even across compilation units (test somehow) -static std::unordered_map> s_co_sim_connections; + +#ifdef CO_SIM_IO_EXTERN +extern std::unordered_map> s_co_sim_connections; +#else +std::unordered_map> s_co_sim_connections; +#endif static bool HasIO(const std::string& rConnectionName) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d93c5085..0dbe1a94 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,6 +31,28 @@ if (CO_SIM_IO_ENABLE_MPI) endif() + +add_library (sub1 SHARED co_sim_io/impl/singleton_tests/sub_1.cpp co_sim_io/impl/singleton_tests/sub_12.cpp) +install( TARGETS sub1 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_singleton co_sim_io/impl/singleton_tests/main.cpp co_sim_io/impl/singleton_tests/main2.cpp) +target_link_libraries( main_singleton sub1 ) +install( TARGETS main_singleton DESTINATION ${CMAKE_SOURCE_DIR}/bin ) +set_target_properties(main_singleton PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + + +add_executable ( main_singleton_partner co_sim_io/impl/singleton_tests/main_partner.cpp) +install( TARGETS main_singleton_partner DESTINATION ${CMAKE_SOURCE_DIR}/bin ) +set_target_properties(main_singleton_partner PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + ### C++ tests ### function(add_cpp_executable TEST_SOURCE_FILE) get_filename_component(TEST_FILENAME ${TEST_SOURCE_FILE} NAME) diff --git a/tests/co_sim_io/impl/singleton_tests/main.cpp b/tests/co_sim_io/impl/singleton_tests/main.cpp new file mode 100644 index 00000000..9d83a3c1 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/main.cpp @@ -0,0 +1,47 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// CoSimulation includes +#include "co_sim_io.hpp" +#include "sub_1.hpp" + +#define COSIMIO_CHECK_EQUAL(a, b) \ + if (a != b) { \ + std::cout << "in line " << __LINE__ << " : " << a \ + << " is not equal to " << b << std::endl; \ + return 1; \ + } + +int main() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + COSIMIO_CHECK_EQUAL(info.Get("connection_status"), CoSimIO::ConnectionStatus::Connected); + const std::string connection_name = info.Get("connection_name"); + + + std::cout << "\nHas_io MAIN: "<< CoSimIO::Internals::HasIO(connection_name) << std::endl<< std::endl; + + CheckSub(connection_name); + + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", connection_name); + info = CoSimIO::Disconnect(disconnect_settings); // disconnect afterwards + COSIMIO_CHECK_EQUAL(info.Get("connection_status"), CoSimIO::ConnectionStatus::Disconnected); + + return 0; +} diff --git a/tests/co_sim_io/impl/singleton_tests/main2.cpp b/tests/co_sim_io/impl/singleton_tests/main2.cpp new file mode 100644 index 00000000..a2a92311 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/main2.cpp @@ -0,0 +1,18 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* see "test_include_co_sim_io_1.cpp" for why this file is necessary +*/ + +// Project includes +#define CO_SIM_IO_EXTERN +#include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/main_partner.cpp b/tests/co_sim_io/impl/singleton_tests/main_partner.cpp new file mode 100644 index 00000000..8dc38bbe --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/main_partner.cpp @@ -0,0 +1,41 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// CoSimulation includes +#include "co_sim_io.hpp" + +#define COSIMIO_CHECK_EQUAL(a, b) \ + if (a != b) { \ + std::cout << "in line " << __LINE__ << " : " << a \ + << " is not equal to " << b << std::endl; \ + return 1; \ + } + +int main() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester_partner"); + settings.Set("connect_to", "singleton_tester"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + COSIMIO_CHECK_EQUAL(info.Get("connection_status"), CoSimIO::ConnectionStatus::Connected); + const std::string connection_name = info.Get("connection_name"); + + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", connection_name); + info = CoSimIO::Disconnect(disconnect_settings); // disconnect afterwards + COSIMIO_CHECK_EQUAL(info.Get("connection_status"), CoSimIO::ConnectionStatus::Disconnected); + + return 0; +} diff --git a/tests/co_sim_io/impl/singleton_tests/sub_1.cpp b/tests/co_sim_io/impl/singleton_tests/sub_1.cpp new file mode 100644 index 00000000..0d56386d --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/sub_1.cpp @@ -0,0 +1,28 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +// Project includes +// #define CO_SIM_IO_EXTERN +#include "co_sim_io.hpp" + +bool CheckSub(const std::string& ConnectionName) +{ + std::cout << "\nHas_io: "<< CoSimIO::Internals::HasIO(ConnectionName) << std::endl<< std::endl; + + + + return true; + +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/sub_1.hpp b/tests/co_sim_io/impl/singleton_tests/sub_1.hpp new file mode 100644 index 00000000..8ca83f59 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/sub_1.hpp @@ -0,0 +1,19 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +// Project includes +// #include "co_sim_io.hpp" + +bool CheckSub(const std::string& ConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/sub_12.cpp b/tests/co_sim_io/impl/singleton_tests/sub_12.cpp new file mode 100644 index 00000000..6b857af2 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/sub_12.cpp @@ -0,0 +1,14 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +#define CO_SIM_IO_EXTERN +#include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp index 987a51ef..f6714b4d 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp @@ -16,4 +16,5 @@ the "other" file that includes CoSimIO is "test_include_co_sim_io_2.cpp" */ // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp index d4b64694..a2a92311 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp @@ -14,4 +14,5 @@ */ // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" From e3862bf5bffb5671cfe82cff02331f3c5a122874 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 12:21:25 +0200 Subject: [PATCH 02/32] restructured singleton tests --- tests/CMakeLists.txt | 25 +++---------------- .../impl/singleton_tests/CMakeLists.txt | 11 ++++++++ .../singleton_tests/scenario_1/CMakeLists.txt | 15 +++++++++++ .../{sub_1.cpp => scenario_1/ext_lib.cpp} | 9 ++----- .../{sub_1.hpp => scenario_1/ext_lib.hpp} | 5 +--- .../singleton_tests/{ => scenario_1}/main.cpp | 11 ++++++-- 6 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt rename tests/co_sim_io/impl/singleton_tests/{sub_1.cpp => scenario_1/ext_lib.cpp} (83%) rename tests/co_sim_io/impl/singleton_tests/{sub_1.hpp => scenario_1/ext_lib.hpp} (81%) rename tests/co_sim_io/impl/singleton_tests/{ => scenario_1}/main.cpp (79%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0dbe1a94..a1febae4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -31,27 +31,8 @@ if (CO_SIM_IO_ENABLE_MPI) endif() - -add_library (sub1 SHARED co_sim_io/impl/singleton_tests/sub_1.cpp co_sim_io/impl/singleton_tests/sub_12.cpp) -install( TARGETS sub1 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) - -add_executable ( main_singleton co_sim_io/impl/singleton_tests/main.cpp co_sim_io/impl/singleton_tests/main2.cpp) -target_link_libraries( main_singleton sub1 ) -install( TARGETS main_singleton DESTINATION ${CMAKE_SOURCE_DIR}/bin ) -set_target_properties(main_singleton PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO -) - - -add_executable ( main_singleton_partner co_sim_io/impl/singleton_tests/main_partner.cpp) -install( TARGETS main_singleton_partner DESTINATION ${CMAKE_SOURCE_DIR}/bin ) -set_target_properties(main_singleton_partner PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - CXX_EXTENSIONS NO -) +# singleton tests +add_subdirectory(co_sim_io/impl/singleton_tests) ### C++ tests ### function(add_cpp_executable TEST_SOURCE_FILE) @@ -69,7 +50,7 @@ foreach(cpp_test_file ${cpp_test_files}) add_cpp_executable(${cpp_test_file}) endforeach(cpp_test_file) -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1 & $2) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1 & $2 && echo\ 1) add_test(hello_cpp_test hello_cpp_test) add_test(NAME connect_disconnect_cpp_test COMMAND sh run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt new file mode 100644 index 00000000..f2918780 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -0,0 +1,11 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_executable ( main_singleton_partner main_partner.cpp ) +install( TARGETS main_singleton_partner DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests ) +set_target_properties( main_singleton_partner PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_subdirectory(scenario_1) \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt new file mode 100644 index 00000000..c7743a45 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_1_ext_lib SHARED ext_lib.cpp ) +install( TARGETS singleton_tests_scenario_1_ext_lib DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main main.cpp ) +target_link_libraries( main singleton_tests_scenario_1_ext_lib ) +install( TARGETS main DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_1/ ) +set_target_properties( main PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_1 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/sub_1.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp similarity index 83% rename from tests/co_sim_io/impl/singleton_tests/sub_1.cpp rename to tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp index 0d56386d..f8b3dfa8 100644 --- a/tests/co_sim_io/impl/singleton_tests/sub_1.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp @@ -14,15 +14,10 @@ #include // Project includes -// #define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" -bool CheckSub(const std::string& ConnectionName) +bool CheckExtLibHasConnection(const std::string& ConnectionName) { std::cout << "\nHas_io: "<< CoSimIO::Internals::HasIO(ConnectionName) << std::endl<< std::endl; - - - - return true; - + return CoSimIO::Internals::HasIO(ConnectionName); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/sub_1.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.hpp similarity index 81% rename from tests/co_sim_io/impl/singleton_tests/sub_1.hpp rename to tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.hpp index 8ca83f59..3840e405 100644 --- a/tests/co_sim_io/impl/singleton_tests/sub_1.hpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.hpp @@ -13,7 +13,4 @@ // System includes #include -// Project includes -// #include "co_sim_io.hpp" - -bool CheckSub(const std::string& ConnectionName); +bool CheckExtLibHasConnection(const std::string& ConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp similarity index 79% rename from tests/co_sim_io/impl/singleton_tests/main.cpp rename to tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index 9d83a3c1..caa58d68 100644 --- a/tests/co_sim_io/impl/singleton_tests/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -12,7 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" -#include "sub_1.hpp" +#include "ext_lib.hpp" #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ @@ -21,6 +21,13 @@ return 1; \ } +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " << a \ + << " is not true" << std::endl; \ + return 1; \ + } + int main() { CoSimIO::Info settings; @@ -36,7 +43,7 @@ int main() std::cout << "\nHas_io MAIN: "<< CoSimIO::Internals::HasIO(connection_name) << std::endl<< std::endl; - CheckSub(connection_name); + COSIMIO_CHECK_True(CheckExtLibHasConnection(connection_name)); CoSimIO::Info disconnect_settings; disconnect_settings.Set("connection_name", connection_name); From e5c424865e328ba08965e48e93fc58a8e11c79d2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 12:26:47 +0200 Subject: [PATCH 03/32] minor --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a1febae4..c3a14181 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,7 +50,7 @@ foreach(cpp_test_file ${cpp_test_files}) add_cpp_executable(${cpp_test_file}) endforeach(cpp_test_file) -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1 & $2 && echo\ 1) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1 & $2 && exit\ 1) add_test(hello_cpp_test hello_cpp_test) add_test(NAME connect_disconnect_cpp_test COMMAND sh run.sh $ $) From a940186f121688e88dd8f3a8138f1c625f7c2aa7 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 14:47:55 +0200 Subject: [PATCH 04/32] minor --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c3a14181..5a07d56e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -50,7 +50,7 @@ foreach(cpp_test_file ${cpp_test_files}) add_cpp_executable(${cpp_test_file}) endforeach(cpp_test_file) -file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1 & $2 && exit\ 1) +file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/run.sh $1\ &\ $2 \n exit\ 1) add_test(hello_cpp_test hello_cpp_test) add_test(NAME connect_disconnect_cpp_test COMMAND sh run.sh $ $) From 8224cf56d3448d2e51d10fa2548af669d9879be2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:20:31 +0200 Subject: [PATCH 05/32] removed old files --- tests/co_sim_io/impl/singleton_tests/main2.cpp | 18 ------------------ .../co_sim_io/impl/singleton_tests/sub_12.cpp | 14 -------------- 2 files changed, 32 deletions(-) delete mode 100644 tests/co_sim_io/impl/singleton_tests/main2.cpp delete mode 100644 tests/co_sim_io/impl/singleton_tests/sub_12.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/main2.cpp b/tests/co_sim_io/impl/singleton_tests/main2.cpp deleted file mode 100644 index a2a92311..00000000 --- a/tests/co_sim_io/impl/singleton_tests/main2.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// ______ _____ _ ________ -// / ____/___ / ___/(_)___ ___ / _/ __ | -// / / / __ \\__ \/ / __ `__ \ / // / / / -// / /___/ /_/ /__/ / / / / / / // // /_/ / -// \____/\____/____/_/_/ /_/ /_/___/\____/ -// Kratos CoSimulationApplication -// -// License: BSD License, see license.txt -// -// Main authors: Philipp Bucher (https://github.com/philbucher) -// - -/* see "test_include_co_sim_io_1.cpp" for why this file is necessary -*/ - -// Project includes -#define CO_SIM_IO_EXTERN -#include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/sub_12.cpp b/tests/co_sim_io/impl/singleton_tests/sub_12.cpp deleted file mode 100644 index 6b857af2..00000000 --- a/tests/co_sim_io/impl/singleton_tests/sub_12.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// ______ _____ _ ________ -// / ____/___ / ___/(_)___ ___ / _/ __ | -// / / / __ \\__ \/ / __ `__ \ / // / / / -// / /___/ /_/ /__/ / / / / / / // // /_/ / -// \____/\____/____/_/_/ /_/ /_/___/\____/ -// Kratos CoSimulationApplication -// -// License: BSD License, see license.txt -// -// Main authors: Philipp Bucher (https://github.com/philbucher) -// - -#define CO_SIM_IO_EXTERN -#include "co_sim_io.hpp" From fce152f466c03262e21b59e2c51966078d57ab80 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:22:16 +0200 Subject: [PATCH 06/32] minor cleanup --- tests/co_sim_io/impl/singleton_tests/CMakeLists.txt | 2 +- tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp | 4 ---- tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp | 3 --- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index f2918780..d43a6759 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -8,4 +8,4 @@ set_target_properties( main_singleton_partner PROPERTIES CXX_EXTENSIONS NO ) -add_subdirectory(scenario_1) \ No newline at end of file +add_subdirectory(scenario_1) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp index f8b3dfa8..f57cce0b 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp @@ -10,14 +10,10 @@ // Main authors: Philipp Bucher (https://github.com/philbucher) // -// System includes -#include - // Project includes #include "co_sim_io.hpp" bool CheckExtLibHasConnection(const std::string& ConnectionName) { - std::cout << "\nHas_io: "<< CoSimIO::Internals::HasIO(ConnectionName) << std::endl<< std::endl; return CoSimIO::Internals::HasIO(ConnectionName); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index caa58d68..5c2601dd 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -40,9 +40,6 @@ int main() COSIMIO_CHECK_EQUAL(info.Get("connection_status"), CoSimIO::ConnectionStatus::Connected); const std::string connection_name = info.Get("connection_name"); - - std::cout << "\nHas_io MAIN: "<< CoSimIO::Internals::HasIO(connection_name) << std::endl<< std::endl; - COSIMIO_CHECK_True(CheckExtLibHasConnection(connection_name)); CoSimIO::Info disconnect_settings; From e8eeb859c677fec954d0b28228d393a3b7a9aae5 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:24:56 +0200 Subject: [PATCH 07/32] minor --- tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index 5c2601dd..7a904f16 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -23,8 +23,8 @@ #define COSIMIO_CHECK_True(a) \ if (!a) { \ - std::cout << "in line " << __LINE__ << " : " << a \ - << " is not true" << std::endl; \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ return 1; \ } From 90a2571059ffe97e332990ebb4d2e3d2ebf32100 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:36:50 +0200 Subject: [PATCH 08/32] adding second scenario --- .../impl/singleton_tests/CMakeLists.txt | 1 + .../singleton_tests/scenario_1/CMakeLists.txt | 10 ++-- .../impl/singleton_tests/scenario_1/main.cpp | 7 +++ .../singleton_tests/scenario_2/CMakeLists.txt | 15 ++++++ .../singleton_tests/scenario_2/ext_lib.cpp | 33 +++++++++++++ .../singleton_tests/scenario_2/ext_lib.hpp | 18 +++++++ .../impl/singleton_tests/scenario_2/main.cpp | 47 +++++++++++++++++++ 7 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index d43a6759..104e5f90 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -9,3 +9,4 @@ set_target_properties( main_singleton_partner PROPERTIES ) add_subdirectory(scenario_1) +add_subdirectory(scenario_2) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt index c7743a45..fdfbe567 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/CMakeLists.txt @@ -3,13 +3,13 @@ include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) add_library(singleton_tests_scenario_1_ext_lib SHARED ext_lib.cpp ) install( TARGETS singleton_tests_scenario_1_ext_lib DESTINATION ${CMAKE_SOURCE_DIR}/bin ) -add_executable ( main main.cpp ) -target_link_libraries( main singleton_tests_scenario_1_ext_lib ) -install( TARGETS main DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_1/ ) -set_target_properties( main PROPERTIES +add_executable ( main_scenario_1 main.cpp ) +target_link_libraries( main_scenario_1 singleton_tests_scenario_1_ext_lib ) +install( TARGETS main_scenario_1 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_1/ ) +set_target_properties( main_scenario_1 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO ) -add_test(NAME singleton_tests_scenario_1 COMMAND sh ../../../../run.sh $ $) +add_test(NAME singleton_tests_scenario_1 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index 7a904f16..f12ed3af 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -10,6 +10,13 @@ // Main authors: Philipp Bucher (https://github.com/philbucher) // +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +Connecting and disconnecting is done in the main executable +*/ + // CoSimulation includes #include "co_sim_io.hpp" #include "ext_lib.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt new file mode 100644 index 00000000..96b5f2dc --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_2_ext_lib SHARED ext_lib.cpp ) +install( TARGETS singleton_tests_scenario_2_ext_lib DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_scenario_2 main.cpp ) +target_link_libraries( main_scenario_2 singleton_tests_scenario_2_ext_lib ) +install( TARGETS main_scenario_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_1/ ) +set_target_properties( main_scenario_2 PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_2 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp new file mode 100644 index 00000000..13133012 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp @@ -0,0 +1,33 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" + +std::string ConnectToCoSimIO() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + return info.Get("connection_name"); +} + +void DisconnectFromCoSimIO(const std::string& rConnectionName) +{ + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", rConnectionName); + CoSimIO::Disconnect(disconnect_settings); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.hpp new file mode 100644 index 00000000..2ec1c264 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.hpp @@ -0,0 +1,18 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +std::string ConnectToCoSimIO(); + +void DisconnectFromCoSimIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp new file mode 100644 index 00000000..3826814a --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp @@ -0,0 +1,47 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +Connecting and disconnecting is done in the external library +*/ + +// CoSimulation includes +#include "co_sim_io.hpp" +#include "ext_lib.hpp" + +#define COSIMIO_CHECK_EQUAL(a, b) \ + if (a != b) { \ + std::cout << "in line " << __LINE__ << " : " << a \ + << " is not equal to " << b << std::endl; \ + return 1; \ + } + +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ + return 1; \ + } + +int main() +{ + const std::string connection_name = ConnectToCoSimIO(); + + COSIMIO_CHECK_True(CoSimIO::Internals::HasIO(connection_name)); + + DisconnectFromCoSimIO(connection_name); + + return 0; +} From 14a309e9258f5a49b20a07ee6e55a557b93f079f Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:39:03 +0200 Subject: [PATCH 09/32] missing --- tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt index 96b5f2dc..fe8810ec 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/CMakeLists.txt @@ -5,7 +5,7 @@ install( TARGETS singleton_tests_scenario_2_ext_lib DESTINATION ${CMAKE_SOURCE_D add_executable ( main_scenario_2 main.cpp ) target_link_libraries( main_scenario_2 singleton_tests_scenario_2_ext_lib ) -install( TARGETS main_scenario_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_1/ ) +install( TARGETS main_scenario_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_2/ ) set_target_properties( main_scenario_2 PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES From b44bb76801161328885139f69c3fd5f1da6fe193 Mon Sep 17 00:00:00 2001 From: Philipp Date: Tue, 1 Jun 2021 17:42:05 +0200 Subject: [PATCH 10/32] adding scenario 3 --- .../impl/singleton_tests/CMakeLists.txt | 1 + .../singleton_tests/scenario_1/ext_lib.cpp | 1 + .../singleton_tests/scenario_2/ext_lib.cpp | 1 + .../impl/singleton_tests/scenario_2/main.cpp | 7 --- .../singleton_tests/scenario_3/CMakeLists.txt | 15 ++++++ .../singleton_tests/scenario_3/ext_lib.cpp | 26 ++++++++++ .../singleton_tests/scenario_3/ext_lib.hpp | 21 ++++++++ .../impl/singleton_tests/scenario_3/main.cpp | 48 +++++++++++++++++++ 8 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_3/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index 104e5f90..2abf26f4 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -10,3 +10,4 @@ set_target_properties( main_singleton_partner PROPERTIES add_subdirectory(scenario_1) add_subdirectory(scenario_2) +add_subdirectory(scenario_3) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp index f57cce0b..edde734f 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +#include "ext_lib.hpp" bool CheckExtLibHasConnection(const std::string& ConnectionName) { diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp index 13133012..7eff0a2a 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +#include "ext_lib.hpp" std::string ConnectToCoSimIO() { diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp index 3826814a..46e9a5f0 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp @@ -21,13 +21,6 @@ Connecting and disconnecting is done in the external library #include "co_sim_io.hpp" #include "ext_lib.hpp" -#define COSIMIO_CHECK_EQUAL(a, b) \ - if (a != b) { \ - std::cout << "in line " << __LINE__ << " : " << a \ - << " is not equal to " << b << std::endl; \ - return 1; \ - } - #define COSIMIO_CHECK_True(a) \ if (!a) { \ std::cout << "in line " << __LINE__ << " : " \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_3/CMakeLists.txt new file mode 100644 index 00000000..54bedfed --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_3_ext_lib SHARED ext_lib.cpp ) +install( TARGETS singleton_tests_scenario_3_ext_lib DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_scenario_3 main.cpp ) +target_link_libraries( main_scenario_3 singleton_tests_scenario_3_ext_lib ) +install( TARGETS main_scenario_3 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_3/ ) +set_target_properties( main_scenario_3 PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_3 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.cpp new file mode 100644 index 00000000..7bf50de6 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.cpp @@ -0,0 +1,26 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +#include "ext_lib.hpp" + +std::string ConnectToCoSimIO(CoSimIO::Info& rSettings) +{ + auto info = CoSimIO::Connect(rSettings); + return info.Get("connection_name"); +} + +void DisconnectFromCoSimIO(const std::string& rConnectionName) +{ + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", rConnectionName); + CoSimIO::Disconnect(disconnect_settings); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp new file mode 100644 index 00000000..8e182cf1 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp @@ -0,0 +1,21 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +// Project includes +#include "co_sim_io.hpp" + +std::string ConnectToCoSimIO(CoSimIO::Info& rSettings); + +void DisconnectFromCoSimIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp new file mode 100644 index 00000000..b889f6e2 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp @@ -0,0 +1,48 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +Connecting and disconnecting is done in the external library +Difference to scenario 2: The CoSimIO is also included in the +header of the ext library +*/ + +// CoSimulation includes +#include "co_sim_io.hpp" +#include "ext_lib.hpp" + +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ + return 1; \ + } + +int main() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + const std::string connection_name = ConnectToCoSimIO(settings); + + COSIMIO_CHECK_True(CoSimIO::Internals::HasIO(connection_name)); + + DisconnectFromCoSimIO(connection_name); + + return 0; +} From 5416a64eaa96bb8a94d444566b9f496a15a38532 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 14:53:06 +0200 Subject: [PATCH 11/32] adding scenario 4 --- .../impl/singleton_tests/CMakeLists.txt | 1 + .../singleton_tests/scenario_4/CMakeLists.txt | 18 ++++++++ .../singleton_tests/scenario_4/ext_lib_1.cpp | 34 +++++++++++++++ .../singleton_tests/scenario_4/ext_lib_1.hpp | 18 ++++++++ .../singleton_tests/scenario_4/ext_lib_2.cpp | 24 +++++++++++ .../singleton_tests/scenario_4/ext_lib_2.hpp | 16 +++++++ .../impl/singleton_tests/scenario_4/main.cpp | 43 +++++++++++++++++++ 7 files changed, 154 insertions(+) create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index 2abf26f4..d718597a 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -11,3 +11,4 @@ set_target_properties( main_singleton_partner PROPERTIES add_subdirectory(scenario_1) add_subdirectory(scenario_2) add_subdirectory(scenario_3) +add_subdirectory(scenario_4) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_4/CMakeLists.txt new file mode 100644 index 00000000..0e083f6a --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/CMakeLists.txt @@ -0,0 +1,18 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_4_ext_lib_1 SHARED ext_lib_1.cpp ) +install( TARGETS singleton_tests_scenario_4_ext_lib_1 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_library(singleton_tests_scenario_4_ext_lib_2 SHARED ext_lib_2.cpp ) +install( TARGETS singleton_tests_scenario_4_ext_lib_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_scenario_4 main.cpp ) +target_link_libraries( main_scenario_4 singleton_tests_scenario_4_ext_lib_1 singleton_tests_scenario_4_ext_lib_2 ) +install( TARGETS main_scenario_4 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_4/ ) +set_target_properties( main_scenario_4 PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_4 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp new file mode 100644 index 00000000..02f65418 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp @@ -0,0 +1,34 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_1.hpp" + +std::string ConnectToCoSimIO() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + return info.Get("connection_name"); +} + +void DisconnectFromCoSimIO(const std::string& rConnectionName) +{ + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", rConnectionName); + CoSimIO::Disconnect(disconnect_settings); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.hpp new file mode 100644 index 00000000..2ec1c264 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.hpp @@ -0,0 +1,18 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +std::string ConnectToCoSimIO(); + +void DisconnectFromCoSimIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp new file mode 100644 index 00000000..dc11e8ed --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp @@ -0,0 +1,24 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_2.hpp" + +#include + +bool ExtLib2HasIO(const std::string& rConnectionName) +{ + std::cout << "ExtLib2HasIO: " << std::boolalpha << CoSimIO::Internals::HasIO(rConnectionName) << std::endl; + + return CoSimIO::Internals::HasIO(rConnectionName); +} diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.hpp new file mode 100644 index 00000000..9eb89cc1 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.hpp @@ -0,0 +1,16 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +bool ExtLib2HasIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp new file mode 100644 index 00000000..ea39b5c3 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp @@ -0,0 +1,43 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +Connecting and disconnecting is done in the external library 1 +The it is checked if the connection is also available in library 2 +*/ + +// CoSimulation includes +#include "co_sim_io.hpp" +#include "ext_lib_1.hpp" +#include "ext_lib_2.hpp" + +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ + return 1; \ + } + +int main() +{ + const std::string connection_name = ConnectToCoSimIO(); + + COSIMIO_CHECK_True(CoSimIO::Internals::HasIO(connection_name)); + COSIMIO_CHECK_True(ExtLib2HasIO(connection_name)); + + DisconnectFromCoSimIO(connection_name); + + return 0; +} \ No newline at end of file From 1241e36a81fc9cb1f0453979061517fe64339237 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 14:56:02 +0200 Subject: [PATCH 12/32] adding scenario 5 --- .../impl/singleton_tests/CMakeLists.txt | 1 + .../singleton_tests/scenario_4/ext_lib_2.cpp | 4 -- .../singleton_tests/scenario_5/CMakeLists.txt | 18 ++++++++ .../singleton_tests/scenario_5/ext_lib_1.cpp | 34 ++++++++++++++ .../singleton_tests/scenario_5/ext_lib_1.hpp | 18 ++++++++ .../singleton_tests/scenario_5/ext_lib_2.cpp | 20 +++++++++ .../singleton_tests/scenario_5/ext_lib_2.hpp | 16 +++++++ .../impl/singleton_tests/scenario_5/main.cpp | 45 +++++++++++++++++++ 8 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_5/main.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index d718597a..a7ef47a0 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -12,3 +12,4 @@ add_subdirectory(scenario_1) add_subdirectory(scenario_2) add_subdirectory(scenario_3) add_subdirectory(scenario_4) +add_subdirectory(scenario_5) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp index dc11e8ed..c0169725 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_2.cpp @@ -14,11 +14,7 @@ #include "co_sim_io.hpp" #include "ext_lib_2.hpp" -#include - bool ExtLib2HasIO(const std::string& rConnectionName) { - std::cout << "ExtLib2HasIO: " << std::boolalpha << CoSimIO::Internals::HasIO(rConnectionName) << std::endl; - return CoSimIO::Internals::HasIO(rConnectionName); } diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_5/CMakeLists.txt new file mode 100644 index 00000000..a08e7233 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/CMakeLists.txt @@ -0,0 +1,18 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_5_ext_lib_1 SHARED ext_lib_1.cpp ) +install( TARGETS singleton_tests_scenario_5_ext_lib_1 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_library(singleton_tests_scenario_5_ext_lib_2 SHARED ext_lib_2.cpp ) +install( TARGETS singleton_tests_scenario_5_ext_lib_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_scenario_5 main.cpp ) +target_link_libraries( main_scenario_5 singleton_tests_scenario_5_ext_lib_1 singleton_tests_scenario_5_ext_lib_2 ) +install( TARGETS main_scenario_5 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_5/ ) +set_target_properties( main_scenario_5 PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_5 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp new file mode 100644 index 00000000..02f65418 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp @@ -0,0 +1,34 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_1.hpp" + +std::string ConnectToCoSimIO() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + return info.Get("connection_name"); +} + +void DisconnectFromCoSimIO(const std::string& rConnectionName) +{ + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", rConnectionName); + CoSimIO::Disconnect(disconnect_settings); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.hpp new file mode 100644 index 00000000..2ec1c264 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.hpp @@ -0,0 +1,18 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +std::string ConnectToCoSimIO(); + +void DisconnectFromCoSimIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.cpp new file mode 100644 index 00000000..c0169725 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.cpp @@ -0,0 +1,20 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_2.hpp" + +bool ExtLib2HasIO(const std::string& rConnectionName) +{ + return CoSimIO::Internals::HasIO(rConnectionName); +} diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.hpp new file mode 100644 index 00000000..9eb89cc1 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_2.hpp @@ -0,0 +1,16 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +bool ExtLib2HasIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/main.cpp new file mode 100644 index 00000000..d0a7edfe --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/main.cpp @@ -0,0 +1,45 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +Connecting and disconnecting is done in the external library 1 +The it is checked if the connection is also available in library 2 +Difference to scenario 4 is that the main doesn't include CoSimIO +*/ + +// System includes +#include + +// CoSimulation includes +#include "ext_lib_1.hpp" +#include "ext_lib_2.hpp" + +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ + return 1; \ + } + +int main() +{ + const std::string connection_name = ConnectToCoSimIO(); + + COSIMIO_CHECK_True(ExtLib2HasIO(connection_name)); + + DisconnectFromCoSimIO(connection_name); + + return 0; +} \ No newline at end of file From 4daf91cb611f53f1ae9be1368c2ba23294aae67c Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 15:04:58 +0200 Subject: [PATCH 13/32] adding scenario 6 --- .../impl/singleton_tests/CMakeLists.txt | 1 + .../singleton_tests/scenario_6/CMakeLists.txt | 18 ++++++++ .../singleton_tests/scenario_6/ext_lib_1.hpp | 20 ++++++++ .../singleton_tests/scenario_6/ext_lib_11.cpp | 34 ++++++++++++++ .../singleton_tests/scenario_6/ext_lib_12.cpp | 21 +++++++++ .../singleton_tests/scenario_6/ext_lib_13.cpp | 21 +++++++++ .../singleton_tests/scenario_6/ext_lib_13.hpp | 16 +++++++ .../singleton_tests/scenario_6/ext_lib_2.cpp | 20 ++++++++ .../singleton_tests/scenario_6/ext_lib_2.hpp | 16 +++++++ .../impl/singleton_tests/scenario_6/main.cpp | 46 +++++++++++++++++++ 10 files changed, 213 insertions(+) create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_1.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_11.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/scenario_6/main.cpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index a7ef47a0..25aed1af 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -13,3 +13,4 @@ add_subdirectory(scenario_2) add_subdirectory(scenario_3) add_subdirectory(scenario_4) add_subdirectory(scenario_5) +add_subdirectory(scenario_6) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/scenario_6/CMakeLists.txt new file mode 100644 index 00000000..762e1f4f --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/CMakeLists.txt @@ -0,0 +1,18 @@ +include_directories( ${CMAKE_SOURCE_DIR}/co_sim_io ) + +add_library(singleton_tests_scenario_6_ext_lib_1 SHARED ext_lib_11.cpp ext_lib_12.cpp ext_lib_13.cpp ) +install( TARGETS singleton_tests_scenario_6_ext_lib_1 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_library(singleton_tests_scenario_6_ext_lib_2 SHARED ext_lib_2.cpp ) +install( TARGETS singleton_tests_scenario_6_ext_lib_2 DESTINATION ${CMAKE_SOURCE_DIR}/bin ) + +add_executable ( main_scenario_6 main.cpp ) +target_link_libraries( main_scenario_6 singleton_tests_scenario_6_ext_lib_1 singleton_tests_scenario_6_ext_lib_2 ) +install( TARGETS main_scenario_6 DESTINATION ${CMAKE_SOURCE_DIR}/bin/singleton_tests/scenario_6/ ) +set_target_properties( main_scenario_6 PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES + CXX_EXTENSIONS NO +) + +add_test(NAME singleton_tests_scenario_6 COMMAND sh ../../../../run.sh $ $) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_1.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_1.hpp new file mode 100644 index 00000000..d9af0acf --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_1.hpp @@ -0,0 +1,20 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +std::string ConnectToCoSimIO(); + +void DisconnectFromCoSimIO(const std::string& rConnectionName); + +bool ExtLib1HasIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_11.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_11.cpp new file mode 100644 index 00000000..02f65418 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_11.cpp @@ -0,0 +1,34 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_1.hpp" + +std::string ConnectToCoSimIO() +{ + CoSimIO::Info settings; + settings.Set("my_name", "singleton_tester"); + settings.Set("connect_to", "singleton_tester_partner"); + settings.Set("echo_level", 1); + settings.Set("version", "1.25"); + + auto info = CoSimIO::Connect(settings); + return info.Get("connection_name"); +} + +void DisconnectFromCoSimIO(const std::string& rConnectionName) +{ + CoSimIO::Info disconnect_settings; + disconnect_settings.Set("connection_name", rConnectionName); + CoSimIO::Disconnect(disconnect_settings); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp new file mode 100644 index 00000000..64751411 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp @@ -0,0 +1,21 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#define CO_SIM_IO_EXTERN +#include "co_sim_io.hpp" +#include "ext_lib_1.hpp" + +bool ExtLib1HasIO(const std::string& rConnectionName) +{ + return CoSimIO::Internals::HasIO(rConnectionName); +} diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp new file mode 100644 index 00000000..eeb7a066 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp @@ -0,0 +1,21 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#define CO_SIM_IO_EXTERN +#include "co_sim_io.hpp" +#include "ext_lib_13.hpp" + +bool ExtLib13HasIO(const std::string& rConnectionName) +{ + return CoSimIO::Internals::HasIO(rConnectionName); +} diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.hpp new file mode 100644 index 00000000..dabcf604 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.hpp @@ -0,0 +1,16 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +bool ExtLib13HasIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp new file mode 100644 index 00000000..c0169725 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp @@ -0,0 +1,20 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// Project includes +#include "co_sim_io.hpp" +#include "ext_lib_2.hpp" + +bool ExtLib2HasIO(const std::string& rConnectionName) +{ + return CoSimIO::Internals::HasIO(rConnectionName); +} diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.hpp new file mode 100644 index 00000000..9eb89cc1 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.hpp @@ -0,0 +1,16 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +// System includes +#include + +bool ExtLib2HasIO(const std::string& rConnectionName); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/main.cpp new file mode 100644 index 00000000..ce5079b7 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/main.cpp @@ -0,0 +1,46 @@ +// ______ _____ _ ________ +// / ____/___ / ___/(_)___ ___ / _/ __ | +// / / / __ \\__ \/ / __ `__ \ / // / / / +// / /___/ /_/ /__/ / / / / / / // // /_/ / +// \____/\____/____/_/_/ /_/ /_/___/\____/ +// Kratos CoSimulationApplication +// +// License: BSD License, see license.txt +// +// Main authors: Philipp Bucher (https://github.com/philbucher) +// + +/* +Testing if the CoSimIO can be safely included in complex libraries +In this scenario the CoSimIO is included in the main executable +and in the external library +This is a more elaborate example with a more complex structure +*/ + +// System includes +#include + +// CoSimulation includes +#include "ext_lib_1.hpp" +#include "ext_lib_13.hpp" +#include "ext_lib_2.hpp" + +#define COSIMIO_CHECK_True(a) \ + if (!a) { \ + std::cout << "in line " << __LINE__ << " : " \ + << "false is not true" << std::endl; \ + return 1; \ + } + +int main() +{ + const std::string connection_name = ConnectToCoSimIO(); + + COSIMIO_CHECK_True(ExtLib1HasIO(connection_name)); + COSIMIO_CHECK_True(ExtLib13HasIO(connection_name)); + COSIMIO_CHECK_True(ExtLib2HasIO(connection_name)); + + DisconnectFromCoSimIO(connection_name); + + return 0; +} \ No newline at end of file From e6d206537389e5179d2ffd624025adcc410eda64 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 15:10:04 +0200 Subject: [PATCH 14/32] improve registry --- co_sim_io/impl/co_sim_io_impl.hpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 815a7ab5..1483a8f1 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -29,23 +29,22 @@ This file contains the implementation of the functions defined in "co_sim_io.hpp namespace CoSimIO { namespace Internals { -// TODO make sure this is unique even across compilation units (test somehow) -#ifdef CO_SIM_IO_EXTERN -extern std::unordered_map> s_co_sim_connections; -#else -std::unordered_map> s_co_sim_connections; -#endif +inline std::unordered_map>& GetRegistry() +{ + static std::unordered_map> s_co_sim_connections; + return s_co_sim_connections; +} static bool HasIO(const std::string& rConnectionName) { - return s_co_sim_connections.find(rConnectionName) != s_co_sim_connections.end(); + return GetRegistry().find(rConnectionName) != GetRegistry().end(); } static Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; - return *s_co_sim_connections.at(rConnectionName); + return *GetRegistry().at(rConnectionName); } } // namespace Internals @@ -86,7 +85,7 @@ inline Info Connect(const Info& I_Settings) CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl; - s_co_sim_connections[connection_name] = std::unique_ptr(new Connection(I_Settings)); + GetRegistry()[connection_name] = std::unique_ptr(new Connection(I_Settings)); auto info = GetConnection(connection_name).Connect(I_Settings); info.Set("connection_name", connection_name); @@ -101,7 +100,7 @@ inline Info Disconnect(const Info& I_Info) CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl; auto info = GetConnection(connection_name).Disconnect(I_Info); - s_co_sim_connections.erase(connection_name); + GetRegistry().erase(connection_name); return info; } From 3c80c4be3cc144d2a7b91e003247742bea6151ec Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 15:10:29 +0200 Subject: [PATCH 15/32] extern no longer necessary --- tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp | 1 - tests/co_sim_io/impl/test_include_co_sim_io_1.cpp | 1 - tests/co_sim_io/impl/test_include_co_sim_io_2.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp index 64751411..d13ee2e2 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp @@ -11,7 +11,6 @@ // // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_1.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp index eeb7a066..207495c5 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp @@ -11,7 +11,6 @@ // // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_13.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp index f6714b4d..987a51ef 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp @@ -16,5 +16,4 @@ the "other" file that includes CoSimIO is "test_include_co_sim_io_2.cpp" */ // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp index a2a92311..d4b64694 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp @@ -14,5 +14,4 @@ */ // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" From 2343d8f068e92b4277a85c05620e0a01626db106 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 15:11:11 +0200 Subject: [PATCH 16/32] adding comment --- co_sim_io/impl/co_sim_io_impl.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 1483a8f1..bf9b9b9c 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -30,6 +30,7 @@ namespace CoSimIO { namespace Internals { +// this function makes sure that the registry works correctly also across translation units / libraries inline std::unordered_map>& GetRegistry() { static std::unordered_map> s_co_sim_connections; From 48cf7ebe5d41acaf3013356c92d195858cf94b5e Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 16:19:06 +0200 Subject: [PATCH 17/32] try singleton --- co_sim_io/impl/co_sim_io_impl.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index bf9b9b9c..fbf75b57 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -30,6 +30,19 @@ namespace CoSimIO { namespace Internals { +template +class Singleton +{ +public: + static T& getInstance() + { + static T instance; + return instance; + } +}; + +using maptype = std::unordered_map>; + // this function makes sure that the registry works correctly also across translation units / libraries inline std::unordered_map>& GetRegistry() { @@ -39,13 +52,13 @@ inline std::unordered_map>& GetRegistry static bool HasIO(const std::string& rConnectionName) { - return GetRegistry().find(rConnectionName) != GetRegistry().end(); + return Singleton::getInstance().find(rConnectionName) != Singleton::getInstance().end(); } static Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; - return *GetRegistry().at(rConnectionName); + return *Singleton::getInstance().at(rConnectionName); } } // namespace Internals @@ -86,7 +99,7 @@ inline Info Connect(const Info& I_Settings) CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl; - GetRegistry()[connection_name] = std::unique_ptr(new Connection(I_Settings)); + Singleton::getInstance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); auto info = GetConnection(connection_name).Connect(I_Settings); info.Set("connection_name", connection_name); @@ -101,7 +114,7 @@ inline Info Disconnect(const Info& I_Info) CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl; auto info = GetConnection(connection_name).Disconnect(I_Info); - GetRegistry().erase(connection_name); + Singleton::getInstance().erase(connection_name); return info; } From d5a54f78880d270b1432166149175bfa48fe9bd5 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 16:29:24 +0200 Subject: [PATCH 18/32] last attempt --- co_sim_io/impl/co_sim_io_impl.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index fbf75b57..6bffe5c3 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -36,11 +36,19 @@ class Singleton public: static T& getInstance() { - static T instance; - return instance; + if (!m_instance) { + m_instance = CoSimIO::make_unique(); + } + return *m_instance; } + +private: + static std::unique_ptr m_instance; }; +template +std::unique_ptr Singleton::m_instance = nullptr; + using maptype = std::unordered_map>; // this function makes sure that the registry works correctly also across translation units / libraries From 0f855b5d39911cdca70039188527a2820951f1c0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 13:28:48 +0200 Subject: [PATCH 19/32] using Singleton of Alexandrescu --- co_sim_io/impl/Threads.h | 199 +++++++++++++ co_sim_io/impl/co_sim_io_impl.hpp | 22 +- co_sim_io/impl/singleton.h | 464 ++++++++++++++++++++++++++++++ 3 files changed, 676 insertions(+), 9 deletions(-) create mode 100644 co_sim_io/impl/Threads.h create mode 100644 co_sim_io/impl/singleton.h diff --git a/co_sim_io/impl/Threads.h b/co_sim_io/impl/Threads.h new file mode 100644 index 00000000..59b18bb4 --- /dev/null +++ b/co_sim_io/impl/Threads.h @@ -0,0 +1,199 @@ +#ifndef THREADS_H_ +#define THREADS_H_ + +//////////////////////////////////////////////////////////////////////////////// +// macro DEFAULT_THREADING +// Selects the default threading model for certain components of Loki +// If you don't define it, it defaults to single-threaded +// All classes in Loki have configurable threading model; DEFAULT_THREADING +// affects only default template arguments +//////////////////////////////////////////////////////////////////////////////// + +// Last update: June 20, 2001 + +#ifndef DEFAULT_THREADING +#define DEFAULT_THREADING /**/ ::Loki::SingleThreaded +#endif + +namespace Loki +{ +//////////////////////////////////////////////////////////////////////////////// +// class template SingleThreaded +// Implementation of the ThreadingModel policy used by various classes +// Implements a single-threaded model; no synchronization +//////////////////////////////////////////////////////////////////////////////// + + template + class SingleThreaded + { + public: + struct Lock + { + Lock() {} + explicit Lock(const SingleThreaded&) {} + }; + + typedef Host VolatileType; + + typedef int IntType; + + static IntType AtomicAdd(volatile IntType& lval, IntType val) + { return lval += val; } + + static IntType AtomicSubtract(volatile IntType& lval, IntType val) + { return lval -= val; } + + static IntType AtomicMultiply(volatile IntType& lval, IntType val) + { return lval *= val; } + + static IntType AtomicDivide(volatile IntType& lval, IntType val) + { return lval /= val; } + + static IntType AtomicIncrement(volatile IntType& lval) + { return ++lval; } + + static IntType AtomicDecrement(volatile IntType& lval) + { return --lval; } + + static void AtomicAssign(volatile IntType & lval, IntType val) + { lval = val; } + + static void AtomicAssign(IntType & lval, volatile IntType & val) + { lval = val; } + }; + +#ifdef _WINDOWS_ + +//////////////////////////////////////////////////////////////////////////////// +// class template ObjectLevelLockable +// Implementation of the ThreadingModel policy used by various classes +// Implements a object-level locking scheme +//////////////////////////////////////////////////////////////////////////////// + + template + class ObjectLevelLockable + { + mutable CRITICAL_SECTION mtx_; + + public: + ObjectLevelLockable() + { + ::InitializeCriticalSection(&mtx_); + } + + ~ObjectLevelLockable() + { + ::DeleteCriticalSection(&mtx_); + } + + class Lock; + friend class Lock; + + class Lock + { + ObjectLevelLockable const& host_; + + Lock(const Lock&); + Lock& operator=(const Lock&); + public: + + explicit Lock(const ObjectLevelLockable& host) : host_(host) + { + ::EnterCriticalSection(&host_.mtx_); + } + + ~Lock() + { + ::LeaveCriticalSection(&host_.mtx_); + } + }; + + typedef volatile Host VolatileType; + + typedef LONG IntType; + + static IntType AtomicIncrement(volatile IntType& lval) + { return InterlockedIncrement(&const_cast(lval)); } + + static IntType AtomicDecrement(volatile IntType& lval) + { return InterlockedDecrement(&const_cast(lval)); } + + static void AtomicAssign(volatile IntType& lval, IntType val) + { InterlockedExchange(&const_cast(lval), val); } + + static void AtomicAssign(IntType& lval, volatile IntType& val) + { InterlockedExchange(&lval, val); } + }; + + template + class ClassLevelLockable + { + struct Initializer + { + CRITICAL_SECTION mtx_; + + Initializer() + { + ::InitializeCriticalSection(&mtx_); + } + ~Initializer() + { + ::DeleteCriticalSection(&mtx_); + } + }; + + static Initializer initializer_; + + public: + class Lock; + friend class Lock; + + class Lock + { + Lock(const Lock&); + Lock& operator=(const Lock&); + public: + Lock() + { + ::EnterCriticalSection(&initializer_.mtx_); + } + explicit Lock(const ClassLevelLockable&) + { + ::EnterCriticalSection(&initializer_.mtx_); + } + ~Lock() + { + ::LeaveCriticalSection(&initializer_.mtx_); + } + }; + + typedef volatile Host VolatileType; + + typedef LONG IntType; + + static IntType AtomicIncrement(volatile IntType& lval) + { return InterlockedIncrement(&const_cast(lval)); } + + static IntType AtomicDecrement(volatile IntType& lval) + { return InterlockedDecrement(&const_cast(lval)); } + + static void AtomicAssign(volatile IntType& lval, IntType val) + { InterlockedExchange(&const_cast(lval), val); } + + static void AtomicAssign(IntType& lval, volatile IntType& val) + { InterlockedExchange(&lval, val); } + }; + + template + typename ClassLevelLockable::Initializer + ClassLevelLockable::initializer_; + +#endif +} + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +//////////////////////////////////////////////////////////////////////////////// + +#endif diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 6bffe5c3..5281ad1d 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -26,6 +26,8 @@ This file contains the implementation of the functions defined in "co_sim_io.hpp #include "utilities.hpp" #include "version.hpp" +#include "singleton.h" + namespace CoSimIO { namespace Internals { @@ -51,22 +53,24 @@ std::unique_ptr Singleton::m_instance = nullptr; using maptype = std::unordered_map>; +typedef Loki::SingletonHolder SingleA; + // this function makes sure that the registry works correctly also across translation units / libraries -inline std::unordered_map>& GetRegistry() -{ - static std::unordered_map> s_co_sim_connections; - return s_co_sim_connections; -} +// inline std::unordered_map>& GetRegistry() +// { +// static std::unordered_map> s_co_sim_connections; +// return s_co_sim_connections; +// } static bool HasIO(const std::string& rConnectionName) { - return Singleton::getInstance().find(rConnectionName) != Singleton::getInstance().end(); + return SingleA::Instance().find(rConnectionName) != SingleA::Instance().end(); } static Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; - return *Singleton::getInstance().at(rConnectionName); + return *SingleA::Instance().at(rConnectionName); } } // namespace Internals @@ -107,7 +111,7 @@ inline Info Connect(const Info& I_Settings) CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl; - Singleton::getInstance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); + SingleA::Instance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); auto info = GetConnection(connection_name).Connect(I_Settings); info.Set("connection_name", connection_name); @@ -122,7 +126,7 @@ inline Info Disconnect(const Info& I_Info) CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl; auto info = GetConnection(connection_name).Disconnect(I_Info); - Singleton::getInstance().erase(connection_name); + SingleA::Instance().erase(connection_name); return info; } diff --git a/co_sim_io/impl/singleton.h b/co_sim_io/impl/singleton.h new file mode 100644 index 00000000..f0ba8795 --- /dev/null +++ b/co_sim_io/impl/singleton.h @@ -0,0 +1,464 @@ +//////////////////////////////////////////////////////////////////////////////// +// The Loki Library +// Copyright (c) 2001 by Andrei Alexandrescu +// This code accompanies the book: +// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design +// Patterns Applied". Copyright (c) 2001. Addison-Wesley. +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this +// permission notice appear in supporting documentation. +// The author or Addison-Wesley Longman make no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +//////////////////////////////////////////////////////////////////////////////// + +#ifndef SINGLETON_INC_ +#define SINGLETON_INC_ + +#include "Threads.h" +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#define C_CALLING_CONVENTION_QUALIFIER __cdecl +#else +#define C_CALLING_CONVENTION_QUALIFIER +#endif + +namespace Loki +{ + typedef void (C_CALLING_CONVENTION_QUALIFIER *atexit_pfn_t)(); + + namespace Private + { +//////////////////////////////////////////////////////////////////////////////// +// class LifetimeTracker +// Helper class for SetLongevity +//////////////////////////////////////////////////////////////////////////////// + + class LifetimeTracker + { + public: + LifetimeTracker(unsigned int x) : longevity_(x) + {} + + virtual ~LifetimeTracker() = 0; + + static bool Compare(const LifetimeTracker* lhs, + const LifetimeTracker* rhs) + { + return lhs->longevity_ < rhs->longevity_; + } + + private: + unsigned int longevity_; + }; + + // Definition required + inline LifetimeTracker::~LifetimeTracker() {} + + // Helper data + typedef LifetimeTracker** TrackerArray; + extern TrackerArray pTrackerArray; + extern unsigned int elements; + + // Helper destroyer function + template + struct Deleter + { + static void Delete(T* pObj) + { delete pObj; } + }; + + // Concrete lifetime tracker for objects of type T + template + class ConcreteLifetimeTracker : public LifetimeTracker + { + public: + ConcreteLifetimeTracker(T* p,unsigned int longevity, Destroyer d) + : LifetimeTracker(longevity) + , pTracked_(p) + , destroyer_(d) + {} + + ~ConcreteLifetimeTracker() + { destroyer_(pTracked_); } + + private: + T* pTracked_; + Destroyer destroyer_; + }; + + void C_CALLING_CONVENTION_QUALIFIER AtExitFn(); // declaration needed below + } // namespace Private + +//////////////////////////////////////////////////////////////////////////////// +// function template SetLongevity +// Assigns an object a longevity; ensures ordered destructions of objects +// registered thusly during the exit sequence of the application +//////////////////////////////////////////////////////////////////////////////// + + template + void SetLongevity(T* pDynObject, unsigned int longevity, + Destroyer d = Private::Deleter::Delete) + { + using namespace Private; + + TrackerArray pNewArray = static_cast( + std::realloc(pTrackerArray, + sizeof(*pTrackerArray) * (elements + 1))); + if (!pNewArray) throw std::bad_alloc(); + + // Delayed assignment for exception safety + pTrackerArray = pNewArray; + + LifetimeTracker* p = new ConcreteLifetimeTracker( + pDynObject, longevity, d); + + // Insert a pointer to the object into the queue + TrackerArray pos = std::upper_bound( + pTrackerArray, + pTrackerArray + elements, + p, + LifetimeTracker::Compare); + std::copy_backward( + pos, + pTrackerArray + elements, + pTrackerArray + elements + 1); + *pos = p; + ++elements; + + // Register a call to AtExitFn + std::atexit(Private::AtExitFn); + } + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateUsingNew +// Implementation of the CreationPolicy used by SingletonHolder +// Creates objects using a straight call to the new operator +//////////////////////////////////////////////////////////////////////////////// + + template struct CreateUsingNew + { + static T* Create() + { return new T; } + + static void Destroy(T* p) + { delete p; } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateUsingNew +// Implementation of the CreationPolicy used by SingletonHolder +// Creates objects using a call to std::malloc, followed by a call to the +// placement new operator +//////////////////////////////////////////////////////////////////////////////// + + template struct CreateUsingMalloc + { + static T* Create() + { + void* p = std::malloc(sizeof(T)); + if (!p) return 0; + return new(p) T; + } + + static void Destroy(T* p) + { + p->~T(); + std::free(p); + } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template CreateStatic +// Implementation of the CreationPolicy used by SingletonHolder +// Creates an object in static memory +// Implementation is slightly nonportable because it uses the MaxAlign trick +// (an union of all types to ensure proper memory alignment). This trick is +// nonportable in theory but highly portable in practice. +//////////////////////////////////////////////////////////////////////////////// + + template struct CreateStatic + { +#if defined(_MSC_VER) && _MSC_VER >= 1300 +#pragma warning( push ) + // alignment of a member was sensitive to packing +#pragma warning( disable : 4121 ) +#endif // _MSC_VER + union MaxAlign + { + char t_[sizeof(T)]; + short int shortInt_; + int int_; + long int longInt_; + float float_; + double double_; + long double longDouble_; + struct Test; + int Test::* pMember_; + int (Test::*pMemberFn_)(int); + }; +#if defined(_MSC_VER) && _MSC_VER >= 1300 +#pragma warning( pop ) +#endif // _MSC_VER + + static T* Create() + { + static MaxAlign staticMemory_; + return new(&staticMemory_) T; + } + + static void Destroy(T* p) + { + p->~T(); + } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template DefaultLifetime +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction as per C++ rules +// Forwards to std::atexit +//////////////////////////////////////////////////////////////////////////////// + + template + struct DefaultLifetime + { + static void ScheduleDestruction(T*, atexit_pfn_t pFun) + { std::atexit(pFun); } + + static void OnDeadReference() + { throw std::logic_error("Dead Reference Detected"); } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template PhoenixSingleton +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction as per C++ rules, and it allows object +// recreation by not throwing an exception from OnDeadReference +//////////////////////////////////////////////////////////////////////////////// + + template + class PhoenixSingleton + { + public: + static void ScheduleDestruction(T*, atexit_pfn_t pFun) + { +#ifndef ATEXIT_FIXED + if (!destroyedOnce_) +#endif + std::atexit(pFun); + } + + static void OnDeadReference() + { +#ifndef ATEXIT_FIXED + destroyedOnce_ = true; +#endif + } + + private: +#ifndef ATEXIT_FIXED + static bool destroyedOnce_; +#endif + }; + +#ifndef ATEXIT_FIXED + template bool PhoenixSingleton::destroyedOnce_ = false; +#endif + +//////////////////////////////////////////////////////////////////////////////// +// class template Adapter +// Helper for SingletonWithLongevity below +//////////////////////////////////////////////////////////////////////////////// + + namespace Private + { + template + struct Adapter + { + void operator()(T*) { return pFun_(); } + atexit_pfn_t pFun_; + }; + } + +//////////////////////////////////////////////////////////////////////////////// +// class template SingletonWithLongevity +// Implementation of the LifetimePolicy used by SingletonHolder +// Schedules an object's destruction in order of their longevities +// Assumes a visible function GetLongevity(T*) that returns the longevity of the +// object +//////////////////////////////////////////////////////////////////////////////// + + template + class SingletonWithLongevity + { + public: + static void ScheduleDestruction(T* pObj, atexit_pfn_t pFun) + { + Private::Adapter adapter = { pFun }; + SetLongevity(pObj, GetLongevity(pObj), adapter); + } + + static void OnDeadReference() + { throw std::logic_error("Dead Reference Detected"); } + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template NoDestroy +// Implementation of the LifetimePolicy used by SingletonHolder +// Never destroys the object +//////////////////////////////////////////////////////////////////////////////// + + template + struct NoDestroy + { + static void ScheduleDestruction(T*, atexit_pfn_t pFun) + {} + + static void OnDeadReference() + {} + }; + +//////////////////////////////////////////////////////////////////////////////// +// class template SingletonHolder +// Provides Singleton amenities for a type T +// To protect that type from spurious instantiations, you have to protect it +// yourself. +//////////////////////////////////////////////////////////////////////////////// + + template + < + typename T, + template class CreationPolicy = CreateUsingNew, + template class LifetimePolicy = DefaultLifetime, + template class ThreadingModel = SingleThreaded + > + class SingletonHolder + { + public: + static T& Instance(); + + private: + // Helpers + static void MakeInstance(); + static void C_CALLING_CONVENTION_QUALIFIER DestroySingleton(); + + // Protection + SingletonHolder(); + + // Data + typedef typename ThreadingModel::VolatileType PtrInstanceType; + static PtrInstanceType pInstance_; + static bool destroyed_; + }; + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder's data +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + template class C, + template class L, + template class M + > + typename SingletonHolder::PtrInstanceType + SingletonHolder::pInstance_; + + template + < + class T, + template class C, + template class L, + template class M + > + bool SingletonHolder::destroyed_; + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder::Instance +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + template class CreationPolicy, + template class LifetimePolicy, + template class ThreadingModel + > + inline T& SingletonHolder::Instance() + { + if (!pInstance_) + { + MakeInstance(); + } + return *pInstance_; + } + +//////////////////////////////////////////////////////////////////////////////// +// SingletonHolder::MakeInstance (helper for Instance) +//////////////////////////////////////////////////////////////////////////////// + + template + < + class T, + template class CreationPolicy, + template class LifetimePolicy, + template class ThreadingModel + > + void SingletonHolder::MakeInstance() + { + typename ThreadingModel::Lock guard; + (void)guard; + + if (!pInstance_) + { + if (destroyed_) + { + LifetimePolicy::OnDeadReference(); + destroyed_ = false; + } + pInstance_ = CreationPolicy::Create(); + LifetimePolicy::ScheduleDestruction(pInstance_, + &DestroySingleton); + } + } + + template + < + class T, + template class CreationPolicy, + template class L, + template class M + > + void C_CALLING_CONVENTION_QUALIFIER + SingletonHolder::DestroySingleton() + { + assert(!destroyed_); + CreationPolicy::Destroy(pInstance_); + pInstance_ = 0; + destroyed_ = true; + } +} // namespace Loki + +//////////////////////////////////////////////////////////////////////////////// +// Change log: +// May 21, 2001: Correct the volatile qualifier - credit due to Darin Adler +// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! +// January 08, 2002: Fixed bug in call to realloc - credit due to Nigel Gent and +// Eike Petersen +// March 08, 2002: moved the assignment to pTrackerArray in SetLongevity to fix +// exception safety issue. Credit due to Kari Hoijarvi +// May 09, 2002: Fixed bug in Compare that caused longevities to act backwards. +// Credit due to Scott McDonald. +//////////////////////////////////////////////////////////////////////////////// + +#endif // SINGLETON_INC_ From efc5167994b7a56cc3ca99c35d6ed1ae82c1adb2 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 14:42:44 +0200 Subject: [PATCH 20/32] another test --- co_sim_io/impl/co_sim_io_impl.hpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 5281ad1d..439ffa8b 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -51,9 +51,29 @@ class Singleton template std::unique_ptr Singleton::m_instance = nullptr; +template +class Singleton2 { +public: + static T& Instance(); + + Singleton2(const Singleton2&) = delete; + Singleton2& operator= (const Singleton2) = delete; + +protected: + Singleton2() {} +}; + +template +T& Singleton2::Instance() +{ + static const std::unique_ptr instance{new T{}}; + return *instance; +} + using maptype = std::unordered_map>; typedef Loki::SingletonHolder SingleA; +typedef Singleton2 SingleB; // this function makes sure that the registry works correctly also across translation units / libraries // inline std::unordered_map>& GetRegistry() @@ -64,13 +84,13 @@ typedef Loki::SingletonHolder SingleA; static bool HasIO(const std::string& rConnectionName) { - return SingleA::Instance().find(rConnectionName) != SingleA::Instance().end(); + return SingleB::Instance().find(rConnectionName) != SingleB::Instance().end(); } static Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; - return *SingleA::Instance().at(rConnectionName); + return *SingleB::Instance().at(rConnectionName); } } // namespace Internals @@ -111,7 +131,7 @@ inline Info Connect(const Info& I_Settings) CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl; - SingleA::Instance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); + SingleB::Instance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); auto info = GetConnection(connection_name).Connect(I_Settings); info.Set("connection_name", connection_name); @@ -126,7 +146,7 @@ inline Info Disconnect(const Info& I_Info) CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl; auto info = GetConnection(connection_name).Disconnect(I_Info); - SingleA::Instance().erase(connection_name); + SingleB::Instance().erase(connection_name); return info; } From c27eecd86d9610c955ed42a31b5bf65eff1a7528 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 2 Jun 2021 15:10:29 +0200 Subject: [PATCH 21/32] Revert "extern no longer necessary" This reverts commit 3c80c4be3cc144d2a7b91e003247742bea6151ec. --- tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp | 1 + tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp | 1 + tests/co_sim_io/impl/test_include_co_sim_io_1.cpp | 1 + tests/co_sim_io/impl/test_include_co_sim_io_2.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp index d13ee2e2..64751411 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp @@ -11,6 +11,7 @@ // // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_1.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp index 207495c5..eeb7a066 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp @@ -11,6 +11,7 @@ // // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_13.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp index 987a51ef..f6714b4d 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp @@ -16,4 +16,5 @@ the "other" file that includes CoSimIO is "test_include_co_sim_io_2.cpp" */ // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp index d4b64694..a2a92311 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp @@ -14,4 +14,5 @@ */ // Project includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" From f56a01255964e55f9a5ac6b6e380419bdaaeb83f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 15:16:31 +0200 Subject: [PATCH 22/32] simplified --- co_sim_io/impl/co_sim_io_impl.hpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 439ffa8b..a5721ad1 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -66,14 +66,17 @@ class Singleton2 { template T& Singleton2::Instance() { - static const std::unique_ptr instance{new T{}}; - return *instance; +// #ifdef CO_SIM_IO_EXTERN +// extern T t; +// #else + static T t; +// #endif + return t; } using maptype = std::unordered_map>; typedef Loki::SingletonHolder SingleA; -typedef Singleton2 SingleB; // this function makes sure that the registry works correctly also across translation units / libraries // inline std::unordered_map>& GetRegistry() @@ -82,15 +85,23 @@ typedef Singleton2 SingleB; // return s_co_sim_connections; // } +using CoSimIOSingletonType = Singleton2; + +#ifdef CO_SIM_IO_EXTERN +extern maptype registry_map; +#else +maptype registry_map; +#endif + static bool HasIO(const std::string& rConnectionName) { - return SingleB::Instance().find(rConnectionName) != SingleB::Instance().end(); + return registry_map.find(rConnectionName) != registry_map.end(); } static Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; - return *SingleB::Instance().at(rConnectionName); + return *registry_map.at(rConnectionName); } } // namespace Internals @@ -131,7 +142,7 @@ inline Info Connect(const Info& I_Settings) CO_SIM_IO_ERROR_IF(HasIO(connection_name)) << "A connection from \"" << my_name << "\" to \"" << connect_to << "\"already exists!" << std::endl; - SingleB::Instance()[connection_name] = std::unique_ptr(new Connection(I_Settings)); + registry_map[connection_name] = std::unique_ptr(new Connection(I_Settings)); auto info = GetConnection(connection_name).Connect(I_Settings); info.Set("connection_name", connection_name); @@ -146,7 +157,7 @@ inline Info Disconnect(const Info& I_Info) CO_SIM_IO_ERROR_IF_NOT(HasIO(connection_name)) << "Trying to disconnect connection \"" << connection_name << "\" which does not exist!" << std::endl; auto info = GetConnection(connection_name).Disconnect(I_Info); - SingleB::Instance().erase(connection_name); + registry_map.erase(connection_name); return info; } From d7acf10b759ff801ca49a6495534e8824ac3236e Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 15:38:11 +0200 Subject: [PATCH 23/32] try sth --- co_sim_io/impl/co_sim_io_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index a5721ad1..36d7603f 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -93,12 +93,12 @@ extern maptype registry_map; maptype registry_map; #endif -static bool HasIO(const std::string& rConnectionName) +inline bool HasIO(const std::string& rConnectionName) { return registry_map.find(rConnectionName) != registry_map.end(); } -static Connection& GetConnection(const std::string& rConnectionName) +inline Connection& GetConnection(const std::string& rConnectionName) { CO_SIM_IO_ERROR_IF_NOT(HasIO(rConnectionName)) << "Trying to use connection \"" << rConnectionName << "\" which does not exist!" << std::endl; return *registry_map.at(rConnectionName); From d6a4fac997adf4adcbeaef1b41887e5b0ae1944f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 15:41:44 +0200 Subject: [PATCH 24/32] missing extern --- tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index f12ed3af..69455dde 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -18,6 +18,7 @@ Connecting and disconnecting is done in the main executable */ // CoSimulation includes +#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib.hpp" From a47034945e6a5e8ac3fe7301b4229bbc226ebbe3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 16:12:27 +0200 Subject: [PATCH 25/32] removed all CO_SIM_IO_EXTERN --- tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp | 1 - tests/co_sim_io/impl/test_include_co_sim_io_1.cpp | 1 - tests/co_sim_io/impl/test_include_co_sim_io_2.cpp | 1 - 5 files changed, 5 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index 69455dde..f12ed3af 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -18,7 +18,6 @@ Connecting and disconnecting is done in the main executable */ // CoSimulation includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp index 64751411..d13ee2e2 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_12.cpp @@ -11,7 +11,6 @@ // // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_1.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp index eeb7a066..207495c5 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_13.cpp @@ -11,7 +11,6 @@ // // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" #include "ext_lib_13.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp index f6714b4d..987a51ef 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp @@ -16,5 +16,4 @@ the "other" file that includes CoSimIO is "test_include_co_sim_io_2.cpp" */ // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp index a2a92311..d4b64694 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_2.cpp @@ -14,5 +14,4 @@ */ // Project includes -#define CO_SIM_IO_EXTERN #include "co_sim_io.hpp" From 6cbca806c33a7fbb69c4b598c677cd1a33db64f0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 16:24:56 +0200 Subject: [PATCH 26/32] this is promissing --- co_sim_io/impl/co_sim_io_impl.hpp | 32 +++++++++++-------- .../impl/singleton_tests/main_partner.cpp | 1 + .../impl/singleton_tests/scenario_1/main.cpp | 1 + .../impl/singleton_tests/scenario_2/main.cpp | 1 + .../impl/singleton_tests/scenario_3/main.cpp | 1 + .../impl/singleton_tests/scenario_4/main.cpp | 1 + .../singleton_tests/scenario_5/ext_lib_1.cpp | 1 + .../singleton_tests/scenario_6/ext_lib_2.cpp | 1 + .../impl/test_include_co_sim_io_1.cpp | 1 + .../cpp/connect_disconnect_a.cpp | 1 + .../cpp/connect_disconnect_b.cpp | 1 + .../cpp/data_exchange.cpp | 1 + .../integration_tutorials/cpp/export_data.cpp | 1 + .../integration_tutorials/cpp/export_info.cpp | 1 + .../integration_tutorials/cpp/export_mesh.cpp | 1 + tests/integration_tutorials/cpp/hello.cpp | 1 + .../integration_tutorials/cpp/import_data.cpp | 1 + .../integration_tutorials/cpp/import_info.cpp | 1 + .../integration_tutorials/cpp/import_mesh.cpp | 1 + .../cpp/mesh_exchange.cpp | 1 + tests/integration_tutorials/cpp/run.cpp | 1 + tests/integration_tutorials/cpp/runner.cpp | 1 + 22 files changed, 39 insertions(+), 14 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 36d7603f..943d0ee5 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -28,6 +28,10 @@ This file contains the implementation of the functions defined in "co_sim_io.hpp #include "singleton.h" +using maptype = std::unordered_map>; + +extern maptype registry_map; + namespace CoSimIO { namespace Internals { @@ -74,24 +78,20 @@ T& Singleton2::Instance() return t; } -using maptype = std::unordered_map>; +// using maptype = std::unordered_map>; -typedef Loki::SingletonHolder SingleA; +// typedef Loki::SingletonHolder SingleA; -// this function makes sure that the registry works correctly also across translation units / libraries -// inline std::unordered_map>& GetRegistry() -// { -// static std::unordered_map> s_co_sim_connections; -// return s_co_sim_connections; -// } +// // this function makes sure that the registry works correctly also across translation units / libraries +// // inline std::unordered_map>& GetRegistry() +// // { +// // static std::unordered_map> s_co_sim_connections; +// // return s_co_sim_connections; +// // } -using CoSimIOSingletonType = Singleton2; +// using CoSimIOSingletonType = Singleton2; -#ifdef CO_SIM_IO_EXTERN -extern maptype registry_map; -#else -maptype registry_map; -#endif +// extern maptype registry_map; inline bool HasIO(const std::string& rConnectionName) { @@ -275,4 +275,8 @@ inline Info Register( } // namespace CoSimIO + + +#define DEFINE_SINGLETON_MAIN( ) maptype registry_map + #endif // CO_SIM_IO_IMPL_INCLUDED diff --git a/tests/co_sim_io/impl/singleton_tests/main_partner.cpp b/tests/co_sim_io/impl/singleton_tests/main_partner.cpp index 8dc38bbe..da7a3c71 100644 --- a/tests/co_sim_io/impl/singleton_tests/main_partner.cpp +++ b/tests/co_sim_io/impl/singleton_tests/main_partner.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index f12ed3af..95255a54 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -19,6 +19,7 @@ Connecting and disconnecting is done in the main executable // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_EQUAL(a, b) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp index 46e9a5f0..8d23b708 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp @@ -19,6 +19,7 @@ Connecting and disconnecting is done in the external library // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_True(a) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp index b889f6e2..21f91b37 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp @@ -21,6 +21,7 @@ header of the ext library // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_True(a) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp index ea39b5c3..19040b57 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp @@ -20,6 +20,7 @@ The it is checked if the connection is also available in library 2 // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib_1.hpp" #include "ext_lib_2.hpp" diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp index 02f65418..29b4b0f4 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_5/ext_lib_1.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib_1.hpp" std::string ConnectToCoSimIO() diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp index c0169725..59d8e07f 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_6/ext_lib_2.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib_2.hpp" bool ExtLib2HasIO(const std::string& rConnectionName) diff --git a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp index 987a51ef..3d5b516a 100644 --- a/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp +++ b/tests/co_sim_io/impl/test_include_co_sim_io_1.cpp @@ -17,3 +17,4 @@ the "other" file that includes CoSimIO is "test_include_co_sim_io_2.cpp" // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); diff --git a/tests/integration_tutorials/cpp/connect_disconnect_a.cpp b/tests/integration_tutorials/cpp/connect_disconnect_a.cpp index e29b88ea..24449e62 100644 --- a/tests/integration_tutorials/cpp/connect_disconnect_a.cpp +++ b/tests/integration_tutorials/cpp/connect_disconnect_a.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/connect_disconnect_b.cpp b/tests/integration_tutorials/cpp/connect_disconnect_b.cpp index 4596b41d..555f8562 100644 --- a/tests/integration_tutorials/cpp/connect_disconnect_b.cpp +++ b/tests/integration_tutorials/cpp/connect_disconnect_b.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/data_exchange.cpp b/tests/integration_tutorials/cpp/data_exchange.cpp index e0f7360a..c843f49c 100644 --- a/tests/integration_tutorials/cpp/data_exchange.cpp +++ b/tests/integration_tutorials/cpp/data_exchange.cpp @@ -15,6 +15,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/export_data.cpp b/tests/integration_tutorials/cpp/export_data.cpp index 442b500a..8dfb1e6d 100644 --- a/tests/integration_tutorials/cpp/export_data.cpp +++ b/tests/integration_tutorials/cpp/export_data.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/export_info.cpp b/tests/integration_tutorials/cpp/export_info.cpp index 4e1f97ac..c0072a85 100644 --- a/tests/integration_tutorials/cpp/export_info.cpp +++ b/tests/integration_tutorials/cpp/export_info.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/export_mesh.cpp b/tests/integration_tutorials/cpp/export_mesh.cpp index d683059d..27c82f0c 100644 --- a/tests/integration_tutorials/cpp/export_mesh.cpp +++ b/tests/integration_tutorials/cpp/export_mesh.cpp @@ -16,6 +16,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/hello.cpp b/tests/integration_tutorials/cpp/hello.cpp index 39d091ec..89e4f894 100644 --- a/tests/integration_tutorials/cpp/hello.cpp +++ b/tests/integration_tutorials/cpp/hello.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/import_data.cpp b/tests/integration_tutorials/cpp/import_data.cpp index be0e1159..1aeec29c 100644 --- a/tests/integration_tutorials/cpp/import_data.cpp +++ b/tests/integration_tutorials/cpp/import_data.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/import_info.cpp b/tests/integration_tutorials/cpp/import_info.cpp index fe64abb8..785a6955 100644 --- a/tests/integration_tutorials/cpp/import_info.cpp +++ b/tests/integration_tutorials/cpp/import_info.cpp @@ -12,6 +12,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/import_mesh.cpp b/tests/integration_tutorials/cpp/import_mesh.cpp index 213941a5..4a855f09 100644 --- a/tests/integration_tutorials/cpp/import_mesh.cpp +++ b/tests/integration_tutorials/cpp/import_mesh.cpp @@ -16,6 +16,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/mesh_exchange.cpp b/tests/integration_tutorials/cpp/mesh_exchange.cpp index 7a5f1e7f..6c88f92c 100644 --- a/tests/integration_tutorials/cpp/mesh_exchange.cpp +++ b/tests/integration_tutorials/cpp/mesh_exchange.cpp @@ -15,6 +15,7 @@ // CoSimulation includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/run.cpp b/tests/integration_tutorials/cpp/run.cpp index 22de9ecb..fb3706ff 100644 --- a/tests/integration_tutorials/cpp/run.cpp +++ b/tests/integration_tutorials/cpp/run.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/runner.cpp b/tests/integration_tutorials/cpp/runner.cpp index fdfc7544..d182a66b 100644 --- a/tests/integration_tutorials/cpp/runner.cpp +++ b/tests/integration_tutorials/cpp/runner.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_TRUE(a) \ if (!(a)) { \ From 05e703b5ff5d2d651ecd9959eb35a226774dc1d6 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 16:29:04 +0200 Subject: [PATCH 27/32] missing updates --- co_sim_io/c/co_sim_io_c.cpp | 1 + co_sim_io/python/co_sim_io_python.cpp | 1 + tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_a.cpp | 1 + tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_b.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/co_sim_io/c/co_sim_io_c.cpp b/co_sim_io/c/co_sim_io_c.cpp index 9cee1c3e..feb6d2fc 100644 --- a/co_sim_io/c/co_sim_io_c.cpp +++ b/co_sim_io/c/co_sim_io_c.cpp @@ -15,6 +15,7 @@ extern "C" { #include "co_sim_io_c.h" } #include "../co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); namespace { // get C Info from C++ Info diff --git a/co_sim_io/python/co_sim_io_python.cpp b/co_sim_io/python/co_sim_io_python.cpp index 683b6457..09bfd063 100644 --- a/co_sim_io/python/co_sim_io_python.cpp +++ b/co_sim_io/python/co_sim_io_python.cpp @@ -31,6 +31,7 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, CoSimIO::intrusive_ptr) // CoSimIO includes #include "../co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "info_to_python.hpp" #include "model_part_to_python.hpp" #include "vector_to_python.hpp" diff --git a/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_a.cpp b/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_a.cpp index 28971df3..b49c4cbe 100644 --- a/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_a.cpp +++ b/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_a.cpp @@ -15,6 +15,7 @@ // CoSimulation includes #include "co_sim_io_mpi.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ diff --git a/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_b.cpp b/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_b.cpp index ab8dba4e..c5823383 100644 --- a/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_b.cpp +++ b/tests/integration_tutorials/cpp/mpi/connect_disconnect_mpi_b.cpp @@ -15,6 +15,7 @@ // CoSimulation includes #include "co_sim_io_mpi.hpp" +DEFINE_SINGLETON_MAIN( ); #define COSIMIO_CHECK_EQUAL(a, b) \ if (a != b) { \ From 4ca4642c8869666162ca27e2e01a3441b7d892c0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 16:40:23 +0200 Subject: [PATCH 28/32] moving definition --- tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp | 1 + tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp | 1 + tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp | 1 + tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp | 1 - tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp | 1 + tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp | 1 - 8 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp index edde734f..1ed94749 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/ext_lib.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" bool CheckExtLibHasConnection(const std::string& ConnectionName) diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp index 95255a54..f12ed3af 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_1/main.cpp @@ -19,7 +19,6 @@ Connecting and disconnecting is done in the main executable // CoSimulation includes #include "co_sim_io.hpp" -DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_EQUAL(a, b) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp index 7eff0a2a..cd5614e7 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/ext_lib.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" std::string ConnectToCoSimIO() diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp index 8d23b708..46e9a5f0 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_2/main.cpp @@ -19,7 +19,6 @@ Connecting and disconnecting is done in the external library // CoSimulation includes #include "co_sim_io.hpp" -DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_True(a) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp index 8e182cf1..1835147f 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/ext_lib.hpp @@ -15,6 +15,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); std::string ConnectToCoSimIO(CoSimIO::Info& rSettings); diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp index 21f91b37..b889f6e2 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_3/main.cpp @@ -21,7 +21,6 @@ header of the ext library // CoSimulation includes #include "co_sim_io.hpp" -DEFINE_SINGLETON_MAIN( ); #include "ext_lib.hpp" #define COSIMIO_CHECK_True(a) \ diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp index 02f65418..29b4b0f4 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/ext_lib_1.cpp @@ -12,6 +12,7 @@ // Project includes #include "co_sim_io.hpp" +DEFINE_SINGLETON_MAIN( ); #include "ext_lib_1.hpp" std::string ConnectToCoSimIO() diff --git a/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp index 19040b57..ea39b5c3 100644 --- a/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/scenario_4/main.cpp @@ -20,7 +20,6 @@ The it is checked if the connection is also available in library 2 // CoSimulation includes #include "co_sim_io.hpp" -DEFINE_SINGLETON_MAIN( ); #include "ext_lib_1.hpp" #include "ext_lib_2.hpp" From 830e39b4f549c8d50bcc69a00c38d063dbee3259 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 17:03:19 +0200 Subject: [PATCH 29/32] maybe wrong place? --- co_sim_io/impl/co_sim_io_impl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/co_sim_io/impl/co_sim_io_impl.hpp b/co_sim_io/impl/co_sim_io_impl.hpp index 943d0ee5..dbf2d86e 100644 --- a/co_sim_io/impl/co_sim_io_impl.hpp +++ b/co_sim_io/impl/co_sim_io_impl.hpp @@ -32,6 +32,8 @@ using maptype = std::unordered_map Date: Mon, 21 Jun 2021 17:07:30 +0200 Subject: [PATCH 30/32] adding Philipps example --- .../impl/singleton_tests/CMakeLists.txt | 13 ++++---- .../singleton_tests/source/CMakeLists.txt | 18 +++++++++++ .../source/lib1/lib1header.hpp | 2 ++ .../source/lib1/lib1source1.cpp | 9 ++++++ .../source/lib1/lib1source2.cpp | 7 +++++ .../source/lib2/lib2header.hpp | 2 ++ .../source/lib2/lib2source1.cpp | 9 ++++++ .../source/lib2/lib2source2.cpp | 7 +++++ .../impl/singleton_tests/source/main.cpp | 30 +++++++++++++++++++ .../singleton_tests/source/singleheader.hpp | 22 ++++++++++++++ 10 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/source/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib1/lib1header.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib2/lib2header.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/main.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source/singleheader.hpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index 25aed1af..6a6ce6ae 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -8,9 +8,10 @@ set_target_properties( main_singleton_partner PROPERTIES CXX_EXTENSIONS NO ) -add_subdirectory(scenario_1) -add_subdirectory(scenario_2) -add_subdirectory(scenario_3) -add_subdirectory(scenario_4) -add_subdirectory(scenario_5) -add_subdirectory(scenario_6) +# add_subdirectory(scenario_1) +# add_subdirectory(scenario_2) +# add_subdirectory(scenario_3) +# add_subdirectory(scenario_4) +# add_subdirectory(scenario_5) +# add_subdirectory(scenario_6) +add_subdirectory(source) diff --git a/tests/co_sim_io/impl/singleton_tests/source/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/source/CMakeLists.txt new file mode 100644 index 00000000..8b00449b --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/CMakeLists.txt @@ -0,0 +1,18 @@ + +cmake_minimum_required( VERSION 3.12 ) + +project( test LANGUAGES CXX ) + +set( WINDOWS_EXPORT_ALL_SYMBOLS ON ) + +add_library( library1 lib1/lib1source1.cpp lib1/lib1source2.cpp lib1/lib1header.hpp ) +add_library( library2 lib2/lib2source1.cpp lib2/lib2source2.cpp lib2/lib2header.hpp ) + +target_include_directories( library1 PUBLIC . lib1 ) +target_include_directories( library2 PUBLIC . lib2 ) + +add_executable( exe main.cpp ) + +target_link_libraries( exe library1 library2 ) + +add_test(singleton_philipp exe) diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1header.hpp b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1header.hpp new file mode 100644 index 00000000..6da90601 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1header.hpp @@ -0,0 +1,2 @@ +void lib1function1( ); +void lib1function2( ); \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source1.cpp b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source1.cpp new file mode 100644 index 00000000..5b300717 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source1.cpp @@ -0,0 +1,9 @@ +#include "lib1header.hpp" +#include "singleheader.hpp" + +#include + +void lib1function2( ) +{ + singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source2.cpp b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source2.cpp new file mode 100644 index 00000000..f8e8c44a --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib1/lib1source2.cpp @@ -0,0 +1,7 @@ +#include "lib1header.hpp" +#include "singleheader.hpp" + +void lib1function1( ) +{ + singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2header.hpp b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2header.hpp new file mode 100644 index 00000000..00fd131b --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2header.hpp @@ -0,0 +1,2 @@ +void lib2function1( ); +void lib2function2( ); \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source1.cpp b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source1.cpp new file mode 100644 index 00000000..4a4feef7 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source1.cpp @@ -0,0 +1,9 @@ +#include "lib2header.hpp" +#include "singleheader.hpp" + +#include + +void lib2function2( ) +{ + singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source2.cpp b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source2.cpp new file mode 100644 index 00000000..8829c945 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/lib2/lib2source2.cpp @@ -0,0 +1,7 @@ +#include "lib2header.hpp" +#include "singleheader.hpp" + +void lib2function1( ) +{ + singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/main.cpp b/tests/co_sim_io/impl/singleton_tests/source/main.cpp new file mode 100644 index 00000000..bb054c49 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/main.cpp @@ -0,0 +1,30 @@ +#include +#include "lib1header.hpp" +#include "lib2header.hpp" + +#include "singleheader.hpp" + +DEFINE_SINGLETON_MAIN( ); + +int main( ) +{ + lib1function1( ); + lib2function1( ); + + singleton.increment( ); + + lib1function2( ); + lib2function2( ); + + lib1function1( ); + lib2function1( ); + + singleton.increment( ); + + lib1function2( ); + lib2function2( ); + + std::cout << "Final count: " << singleton.count( ) << std::endl; + + return singleton.count( ) != 10; +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source/singleheader.hpp b/tests/co_sim_io/impl/singleton_tests/source/singleheader.hpp new file mode 100644 index 00000000..5e9cbaf8 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source/singleheader.hpp @@ -0,0 +1,22 @@ +class Singleton +{ + int count_; + +public: + Singleton( ) : count_( 0 ) { } + + void increment( ) + { + count_++; + } + + int count( ) + { + return count_; + } +}; + +extern Singleton singleton; + +#define DEFINE_SINGLETON_MAIN( ) Singleton singleton + From 1536b1cbea6d74acc19c51a4a708488a37202eda Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 17:25:11 +0200 Subject: [PATCH 31/32] philipps example with CoSimIO --- .../impl/singleton_tests/CMakeLists.txt | 3 +- .../source_cosimio/CMakeLists.txt | 18 +++++++++++ .../source_cosimio/lib1/lib1header.hpp | 2 ++ .../source_cosimio/lib1/lib1source1.cpp | 9 ++++++ .../source_cosimio/lib1/lib1source2.cpp | 7 +++++ .../source_cosimio/lib2/lib2header.hpp | 2 ++ .../source_cosimio/lib2/lib2source1.cpp | 9 ++++++ .../source_cosimio/lib2/lib2source2.cpp | 7 +++++ .../singleton_tests/source_cosimio/main.cpp | 30 +++++++++++++++++++ .../source_cosimio/singleheader.hpp | 22 ++++++++++++++ 10 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/CMakeLists.txt create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1header.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2header.hpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp create mode 100644 tests/co_sim_io/impl/singleton_tests/source_cosimio/singleheader.hpp diff --git a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt index 6a6ce6ae..7bd6b431 100644 --- a/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt +++ b/tests/co_sim_io/impl/singleton_tests/CMakeLists.txt @@ -14,4 +14,5 @@ set_target_properties( main_singleton_partner PROPERTIES # add_subdirectory(scenario_4) # add_subdirectory(scenario_5) # add_subdirectory(scenario_6) -add_subdirectory(source) +# add_subdirectory(source) +add_subdirectory(source_cosimio) diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/CMakeLists.txt b/tests/co_sim_io/impl/singleton_tests/source_cosimio/CMakeLists.txt new file mode 100644 index 00000000..8b00449b --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/CMakeLists.txt @@ -0,0 +1,18 @@ + +cmake_minimum_required( VERSION 3.12 ) + +project( test LANGUAGES CXX ) + +set( WINDOWS_EXPORT_ALL_SYMBOLS ON ) + +add_library( library1 lib1/lib1source1.cpp lib1/lib1source2.cpp lib1/lib1header.hpp ) +add_library( library2 lib2/lib2source1.cpp lib2/lib2source2.cpp lib2/lib2header.hpp ) + +target_include_directories( library1 PUBLIC . lib1 ) +target_include_directories( library2 PUBLIC . lib2 ) + +add_executable( exe main.cpp ) + +target_link_libraries( exe library1 library2 ) + +add_test(singleton_philipp exe) diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1header.hpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1header.hpp new file mode 100644 index 00000000..6da90601 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1header.hpp @@ -0,0 +1,2 @@ +void lib1function1( ); +void lib1function2( ); \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp new file mode 100644 index 00000000..2371a379 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp @@ -0,0 +1,9 @@ +#include "lib1header.hpp" +#include "co_sim_io.hpp" + +#include + +void lib1function2( ) +{ + // singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp new file mode 100644 index 00000000..10dbb04f --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp @@ -0,0 +1,7 @@ +#include "lib1header.hpp" +#include "co_sim_io.hpp" + +void lib1function1( ) +{ + // singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2header.hpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2header.hpp new file mode 100644 index 00000000..00fd131b --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2header.hpp @@ -0,0 +1,2 @@ +void lib2function1( ); +void lib2function2( ); \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp new file mode 100644 index 00000000..d6c8ba23 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp @@ -0,0 +1,9 @@ +#include "lib2header.hpp" +#include "co_sim_io.hpp" + +#include + +void lib2function2( ) +{ + // singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp new file mode 100644 index 00000000..93385c28 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp @@ -0,0 +1,7 @@ +#include "lib2header.hpp" +#include "co_sim_io.hpp" + +void lib2function1( ) +{ + // singleton.increment( ); +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp new file mode 100644 index 00000000..acc19350 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp @@ -0,0 +1,30 @@ +#include +#include "lib1header.hpp" +#include "lib2header.hpp" + +#include "co_sim_io.hpp" + +DEFINE_SINGLETON_MAIN( ); + +int main( ) +{ + // lib1function1( ); + // lib2function1( ); + + // singleton.increment( ); + + // lib1function2( ); + // lib2function2( ); + + // lib1function1( ); + // lib2function1( ); + + // singleton.increment( ); + + // lib1function2( ); + // lib2function2( ); + + // std::cout << "Final count: " << singleton.count( ) << std::endl; + + // return singleton.count( ) != 10; +} \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/singleheader.hpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/singleheader.hpp new file mode 100644 index 00000000..5e9cbaf8 --- /dev/null +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/singleheader.hpp @@ -0,0 +1,22 @@ +class Singleton +{ + int count_; + +public: + Singleton( ) : count_( 0 ) { } + + void increment( ) + { + count_++; + } + + int count( ) + { + return count_; + } +}; + +extern Singleton singleton; + +#define DEFINE_SINGLETON_MAIN( ) Singleton singleton + From c1dd8772009c7516f2ef4e5f7f477c66cc6ce0fb Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 21 Jun 2021 17:31:07 +0200 Subject: [PATCH 32/32] calling CoSimIO --- .../impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp | 3 ++- .../impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp | 3 ++- .../impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp | 3 ++- .../impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp | 3 ++- tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp index 2371a379..ebcaddeb 100644 --- a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source1.cpp @@ -5,5 +5,6 @@ void lib1function2( ) { - // singleton.increment( ); + CoSimIO::Info info; + CoSimIO::Connect(info); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp index 10dbb04f..0c3bb0ad 100644 --- a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib1/lib1source2.cpp @@ -3,5 +3,6 @@ void lib1function1( ) { - // singleton.increment( ); + CoSimIO::Info info; + CoSimIO::Connect(info); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp index d6c8ba23..695e26a6 100644 --- a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source1.cpp @@ -5,5 +5,6 @@ void lib2function2( ) { - // singleton.increment( ); + CoSimIO::Info info; + CoSimIO::Connect(info); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp index 93385c28..37eaf2e8 100644 --- a/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/lib2/lib2source2.cpp @@ -3,5 +3,6 @@ void lib2function1( ) { - // singleton.increment( ); + CoSimIO::Info info; + CoSimIO::Connect(info); } \ No newline at end of file diff --git a/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp b/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp index acc19350..131d58b5 100644 --- a/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp +++ b/tests/co_sim_io/impl/singleton_tests/source_cosimio/main.cpp @@ -8,6 +8,8 @@ DEFINE_SINGLETON_MAIN( ); int main( ) { + CoSimIO::Info info; + CoSimIO::Connect(info); // lib1function1( ); // lib2function1( );