diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fd164a..656de95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # Copyright dSPACE GmbH. All rights reserved. -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.15) project(DsVeosCoSim VERSION 1.0) @@ -11,43 +11,28 @@ option(DSVEOSCOSIM_BUILD_BENCHMARKS "Create benchmarks for dSPACE VEOS CoSim" OF set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DWIN32 /D_WINDOWS /Zm1000 /EHsc /GR /W4 /wd4324 /wd4459") - string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - add_compile_options(/Zi /external:anglebrackets /external:W0) -else() - add_compile_options(-Wall -Wextra -pedantic) - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options(-Wno-stringop-overflow) - endif() -endif() - set(DSVEOSCOSIM_TYPE STATIC) if(BUILD_SHARED_LIBS) set(DSVEOSCOSIM_TYPE SHARED) endif() -add_subdirectory(shared) add_subdirectory(src) + +if(DSVEOSCOSIM_BUILD_TESTS OR DSVEOSCOSIM_BUILD_BENCHMARKS) +add_subdirectory(shared) add_subdirectory(third_party) -add_subdirectory(third_party/fmt) -add_subdirectory(utilities/PerformanceTestClient) -add_subdirectory(utilities/PerformanceTestServer) -add_subdirectory(utilities/TestClient) -add_subdirectory(utilities/TestServer) +endif() + if(DSVEOSCOSIM_BUILD_TESTS) - set(INSTALL_GTEST OFF) - set(gtest_force_shared_crt ON) - add_subdirectory(third_party/googletest) add_subdirectory(test) + add_subdirectory(utilities/TestClient) + add_subdirectory(utilities/TestServer) endif() + if(DSVEOSCOSIM_BUILD_BENCHMARKS) - set(BENCHMARK_ENABLE_INSTALL OFF) - set(BENCHMARK_INSTALL_DOCS OFF) - set(BENCHMARK_ENABLE_GTEST_TESTS OFF) - set(BENCHMARK_USE_BUNDLED_GTEST OFF) - add_subdirectory(third_party/benchmark) add_subdirectory(benchmark) + add_subdirectory(utilities/PerformanceTestClient) + add_subdirectory(utilities/PerformanceTestServer) endif() install(EXPORT DsVeosCoSimTargets diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index af08da8..62b7bd7 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,7 +1,12 @@ # Copyright dSPACE GmbH. All rights reserved. add_executable( - ${PROJECT_NAME}Benchmark + DsVeosCoSimBenchmark +) + +target_sources( + DsVeosCoSimBenchmark + PRIVATE Communication/BenchmarkChannel.cpp OsAbstraction/BenchmarkNamedEvent.cpp OsAbstraction/BenchmarkSocket.cpp @@ -11,8 +16,8 @@ add_executable( ) target_link_libraries( - ${PROJECT_NAME}Benchmark - ${PROJECT_NAME} + DsVeosCoSimBenchmark + DsVeosCoSim shared benchmark::benchmark ) diff --git a/clean.cmd b/clean.cmd index 9561d88..fb945a9 100644 --- a/clean.cmd +++ b/clean.cmd @@ -8,6 +8,7 @@ set currentDir=%~dp0. echo Cleaning ... +rmdir /s /q "%currentDir%\obj" >nul 2>&1 rmdir /s /q "%currentDir%\tmpwin" >nul 2>&1 echo Cleaning finished successfully. diff --git a/clean.sh b/clean.sh index 2c1fb3e..1a44c6b 100755 --- a/clean.sh +++ b/clean.sh @@ -7,6 +7,7 @@ currentDir=$(dirname "$scriptFile")/. echo Cleaning ... +rm -rf "$currentDir/obj" rm -rf "$currentDir/tmplin" echo Cleaning finished successfully. diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 3c99e0f..cb2556a 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -3,6 +3,11 @@ add_library( shared STATIC +) + +target_sources( + shared + PRIVATE BackgroundService.cpp ClientServerTestHelper.cpp Generator.cpp @@ -21,15 +26,17 @@ target_include_directories( $ ) +if(WIN32) target_compile_definitions( shared PUBLIC _CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN ) +endif() target_link_libraries( shared - ${PROJECT_NAME} + DsVeosCoSim fmt::fmt ) diff --git a/shared/ClientServerTestHelper.cpp b/shared/ClientServerTestHelper.cpp index 0497bf7..c743844 100644 --- a/shared/ClientServerTestHelper.cpp +++ b/shared/ClientServerTestHelper.cpp @@ -2,6 +2,8 @@ #include "ClientServerTestHelper.h" +#include + #include "BusBuffer.h" #include "CoSimHelper.h" #include "Generator.h" @@ -16,7 +18,7 @@ bool g_sendEthMessages; bool g_sendLinMessages; void PrintStatus(bool value, std::string_view what) { - LogInfo("{} sending {}.", value ? "Enabled" : "Disabled", what); + LogInfo(fmt::format("{} sending {}.", value ? "Enabled" : "Disabled", what)); } } // namespace diff --git a/shared/Generator.cpp b/shared/Generator.cpp index 85114b8..da10d9b 100644 --- a/shared/Generator.cpp +++ b/shared/Generator.cpp @@ -2,6 +2,8 @@ #include "Generator.h" +#include + using namespace DsVeosCoSim; int32_t Random(int32_t min, int32_t max) { diff --git a/shared/LogHelper.cpp b/shared/LogHelper.cpp index ad734cb..e3a48ae 100644 --- a/shared/LogHelper.cpp +++ b/shared/LogHelper.cpp @@ -96,7 +96,7 @@ void InitializeOutput() { DWORD dwMode = 0; if (::GetConsoleMode(console, &dwMode) != 0) { dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; - ::SetConsoleMode(console, dwMode); + (void)::SetConsoleMode(console, dwMode); } #endif diff --git a/shared/LogHelper.h b/shared/LogHelper.h index 158c9de..a1372dd 100644 --- a/shared/LogHelper.h +++ b/shared/LogHelper.h @@ -2,13 +2,35 @@ #pragma once +#include #include #include +#include "CoSimHelper.h" #include "DsVeosCoSim/DsVeosCoSim.h" void InitializeOutput(); +template +void LogError(fmt::format_string format, T&&... args) { + DsVeosCoSim::LogError(fmt::vformat(format, fmt::make_format_args(args...))); +} + +template +void LogWarning(fmt::format_string format, T&&... args) { + DsVeosCoSim::LogWarning(fmt::vformat(format, fmt::make_format_args(args...))); +} + +template +void LogInfo(fmt::format_string format, T&&... args) { + DsVeosCoSim::LogInfo(fmt::vformat(format, fmt::make_format_args(args...))); +} + +template +void LogTrace(fmt::format_string format, T&&... args) { + DsVeosCoSim::LogTrace(fmt::vformat(format, fmt::make_format_args(args...))); +} + void OnLogCallback(DsVeosCoSim_Severity severity, std::string_view message); void LogIoSignal(const DsVeosCoSim_IoSignal& ioSignal); diff --git a/src/BusBuffer.cpp b/src/BusBuffer.cpp index 6886ddb..063b4eb 100644 --- a/src/BusBuffer.cpp +++ b/src/BusBuffer.cpp @@ -198,15 +198,15 @@ BusBuffer::BusBuffer(CoSimType coSimType, } #endif - std::string_view suffixForTransmit = coSimType == CoSimType::Client ? "Transmit" : "Receive"; - std::string_view suffixForReceive = coSimType == CoSimType::Client ? "Receive" : "Transmit"; - - _canTransmitBuffer->Initialize(coSimType, fmt::format("{}.Can.{}", name, suffixForTransmit), canControllers); - _ethTransmitBuffer->Initialize(coSimType, fmt::format("{}.Eth.{}", name, suffixForTransmit), ethControllers); - _linTransmitBuffer->Initialize(coSimType, fmt::format("{}.Lin.{}", name, suffixForTransmit), linControllers); - _canReceiveBuffer->Initialize(coSimType, fmt::format("{}.Can.{}", name, suffixForReceive), canControllers); - _ethReceiveBuffer->Initialize(coSimType, fmt::format("{}.Eth.{}", name, suffixForReceive), ethControllers); - _linReceiveBuffer->Initialize(coSimType, fmt::format("{}.Lin.{}", name, suffixForReceive), linControllers); + std::string suffixForTransmit = coSimType == CoSimType::Client ? "Transmit" : "Receive"; + std::string suffixForReceive = coSimType == CoSimType::Client ? "Receive" : "Transmit"; + + _canTransmitBuffer->Initialize(coSimType, std::string(name) + ".Can." + suffixForTransmit, canControllers); + _ethTransmitBuffer->Initialize(coSimType, std::string(name) + ".Eth." + suffixForTransmit, ethControllers); + _linTransmitBuffer->Initialize(coSimType, std::string(name) + ".Lin." + suffixForTransmit, linControllers); + _canReceiveBuffer->Initialize(coSimType, std::string(name) + ".Can." + suffixForReceive, canControllers); + _ethReceiveBuffer->Initialize(coSimType, std::string(name) + ".Eth." + suffixForReceive, ethControllers); + _linReceiveBuffer->Initialize(coSimType, std::string(name) + ".Lin." + suffixForReceive, linControllers); } BusBuffer::BusBuffer(CoSimType coSimType, diff --git a/src/BusBuffer.h b/src/BusBuffer.h index 0f1aa43..6427545 100644 --- a/src/BusBuffer.h +++ b/src/BusBuffer.h @@ -2,10 +2,10 @@ #pragma once -#include #include #include #include +#include #include #include #include @@ -135,7 +135,7 @@ class BusProtocolBufferBase { for (const auto& controller : controllers) { const auto search = _controllers.find(controller.id); if (search != _controllers.end()) { - throw CoSimException(fmt::format("Duplicated controller id {}.", controller.id)); + throw CoSimException("Duplicated controller id " + std::to_string(controller.id) + "."); } ControllerExtension extension{}; @@ -215,7 +215,7 @@ class BusProtocolBufferBase { return search->second; } - throw CoSimException(fmt::format("Controller id {} is unknown.", controllerId)); + throw CoSimException("Controller id " + std::to_string(controllerId) + " is unknown."); } std::unordered_map _controllers; @@ -263,7 +263,8 @@ class RemoteBusProtocolBuffer final : public BusProtocolBufferBase ) target_include_directories( - ${PROJECT_NAME} + DsVeosCoSim PRIVATE ./ Communication/ @@ -37,20 +49,34 @@ target_include_directories( ) target_compile_definitions( - ${PROJECT_NAME} + DsVeosCoSim PRIVATE - _CRT_SECURE_NO_WARNINGS DSVEOSCOSIM_EXPORT +) + +if(WIN32) +target_compile_definitions( + DsVeosCoSim + PRIVATE + _CRT_SECURE_NO_WARNINGS WIN32_LEAN_AND_MEAN ) +endif() +if(WIN32) target_link_libraries( - ${PROJECT_NAME} - fmt::fmt + DsVeosCoSim + WS2_32 ) +endif() install( - TARGETS ${PROJECT_NAME} + TARGETS DsVeosCoSim EXPORT DsVeosCoSimTargets - DESTINATION lib) -install(FILES ../include/DsVeosCoSim/DsVeosCoSim.h DESTINATION include) + DESTINATION lib +) + +install( + FILES ../include/DsVeosCoSim/DsVeosCoSim.h + DESTINATION include +) diff --git a/src/CoSimClient.cpp b/src/CoSimClient.cpp index 8a6e68e..dfc741f 100644 --- a/src/CoSimClient.cpp +++ b/src/CoSimClient.cpp @@ -21,7 +21,7 @@ namespace { constexpr uint32_t ClientTimeoutInMilliseconds = 1000; -} +} // namespace bool CoSimClient::Connect(const ConnectConfig& connectConfig) { if (connectConfig.serverName.empty() && (connectConfig.remotePort == 0)) { @@ -247,7 +247,7 @@ void CoSimClient::Terminate(DsVeosCoSim_TerminateReason terminateReason) { _nextCommand.exchange(Command::Terminate); break; default: // NOLINT(clang-diagnostic-covered-switch-default) - throw CoSimException(fmt::format("Unknown terminate reason {}.", ToString(terminateReason))); + throw CoSimException("Unknown terminate reason " + ToString(terminateReason) + "."); } } @@ -418,7 +418,7 @@ bool CoSimClient::LocalConnect() { #ifdef _WIN32 std::optional channel = TryConnectToLocalChannel(_serverName); if (!channel) { - LogTrace("Could not connect to local dSPACE VEOS CoSim server '{}'.", _serverName); + LogTrace("Could not connect to local dSPACE VEOS CoSim server '" + _serverName + "'."); return false; } @@ -426,7 +426,7 @@ bool CoSimClient::LocalConnect() { #else std::optional channel = TryConnectToUdsChannel(_serverName); if (!channel) { - LogTrace("Could not connect to local dSPACE VEOS CoSim server '{}'.", _serverName); + LogTrace("Could not connect to local dSPACE VEOS CoSim server '" + _serverName + "'."); return false; } @@ -439,15 +439,17 @@ bool CoSimClient::LocalConnect() { bool CoSimClient::RemoteConnect() { if (_remotePort == 0) { - LogInfo("Obtaining TCP port of dSPACE VEOS CoSim server '{}' at {} ...", _serverName, _remoteIpAddress); + LogInfo("Obtaining TCP port of dSPACE VEOS CoSim server '" + _serverName + "' at " + _remoteIpAddress + " ..."); CheckResultWithMessage(PortMapper_GetPort(_remoteIpAddress, _serverName, _remotePort), "Could not get port from port mapper."); } if (_serverName.empty()) { - LogInfo("Connecting to dSPACE VEOS CoSim server at {}:{} ...", _remoteIpAddress, _remotePort); + LogInfo("Connecting to dSPACE VEOS CoSim server at " + _remoteIpAddress + ":" + std::to_string(_remotePort) + + "..."); } else { - LogInfo("Connecting to dSPACE VEOS CoSim server '{}' at {}:{} ...", _serverName, _remoteIpAddress, _remotePort); + LogInfo("Connecting to dSPACE VEOS CoSim server '" + _serverName + "' at " + _remoteIpAddress + ":" + + std::to_string(_remotePort) + "..."); } std::optional channel = @@ -491,12 +493,14 @@ bool CoSimClient::OnConnectOk() { _linControllersExtern = Convert(_linControllers); if (_connectionKind == ConnectionKind::Local) { - LogInfo("Connected to local dSPACE VEOS CoSim server '{}'.", _serverName); + LogInfo("Connected to local dSPACE VEOS CoSim server '" + _serverName + "'."); } else { if (_serverName.empty()) { - LogInfo("Connected to dSPACE VEOS CoSim server at {}:{}.", _remoteIpAddress, _remotePort); + LogInfo("Connected to dSPACE VEOS CoSim server at " + _remoteIpAddress + ":" + std::to_string(_remotePort) + + "."); } else { - LogInfo("Connected to dSPACE VEOS CoSim server '{}' at {}:{}.", _serverName, _remoteIpAddress, _remotePort); + LogInfo("Connected to dSPACE VEOS CoSim server '" + _serverName + "' at " + _remoteIpAddress + ":" + + std::to_string(_remotePort) + "."); } } @@ -537,7 +541,7 @@ bool CoSimClient::ReceiveConnectResponse() { CheckResultWithMessage(OnConnectError(), "Could not handle connect error."); return true; default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -609,7 +613,7 @@ bool CoSimClient::RunCallbackBasedCoSimulationInternal() { break; } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -652,7 +656,7 @@ bool CoSimClient::PollCommandInternal(DsVeosCoSim_SimulationTime& simulationTime _currentCommand = Command::Ping; break; default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } if (returnOnPing || (_currentCommand != Command::Ping)) { diff --git a/src/CoSimServer.cpp b/src/CoSimServer.cpp index cf1185d..aa53a3e 100644 --- a/src/CoSimServer.cpp +++ b/src/CoSimServer.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include "CoSimServer.h" + #include #include @@ -66,7 +67,8 @@ void CoSimServer::Start(DsVeosCoSim_SimulationTime simulationTime) { return; } - LogInfo("Waiting for dSPACE VEOS CoSim client to connect to dSPACE VEOS CoSim server '{}' ...", _serverName); + LogInfo("Waiting for dSPACE VEOS CoSim client to connect to dSPACE VEOS CoSim server '" + _serverName + + "' ..."); while (!AcceptChannel()) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); @@ -290,8 +292,9 @@ void CoSimServer::StartAccepting() { } } - std::string_view localIpAddress = _enableRemoteAccess ? "0.0.0.0" : "127.0.0.1"; - LogInfo("dSPACE VEOS CoSim server '{}' is listening on {}:{}.", _serverName, localIpAddress, port); + std::string localIpAddress = _enableRemoteAccess ? "0.0.0.0" : "127.0.0.1"; + LogInfo("dSPACE VEOS CoSim server '" + _serverName + "' is listening on " + localIpAddress + ":" + + std::to_string(port) + "."); } } @@ -394,18 +397,17 @@ bool CoSimServer::OnHandleConnect() { if (_connectionKind == ConnectionKind::Remote) { SocketAddress socketAddress = reinterpret_cast(_channel.get())->GetRemoteAddress(); if (clientName.empty()) { - LogInfo("dSPACE VEOS CoSim client at {}:{} connected.", socketAddress.ipAddress, socketAddress.port); + LogInfo("dSPACE VEOS CoSim client at " + socketAddress.ipAddress + ":" + + std::to_string(socketAddress.port) + " connected."); } else { - LogInfo("dSPACE VEOS CoSim client '{}' at {}:{} connected.", - clientName, - socketAddress.ipAddress, - socketAddress.port); + LogInfo("dSPACE VEOS CoSim client '" + clientName + "' at " + socketAddress.ipAddress + ":" + + std::to_string(socketAddress.port) + " connected."); } } else { if (clientName.empty()) { LogInfo("Local dSPACE VEOS CoSim client connected."); } else { - LogInfo("Local dSPACE VEOS CoSim client '{}' connected.", clientName); + LogInfo("Local dSPACE VEOS CoSim client '" + clientName + "' connected."); } } @@ -426,7 +428,7 @@ bool CoSimServer::WaitForOkFrame() const { throw CoSimException(errorMessage); } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -440,7 +442,7 @@ bool CoSimServer::WaitForPingOkFrame(Command& command) const { "Could not read ping ok frame."); return true; default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -457,7 +459,7 @@ bool CoSimServer::WaitForConnectFrame(uint32_t& version, std::string& clientName return true; } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -482,7 +484,7 @@ bool CoSimServer::WaitForStepOkFrame(DsVeosCoSim_SimulationTime& simulationTime, throw CoSimException(errorMessage); } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } diff --git a/src/CoSimTypes.h b/src/CoSimTypes.h index e54198c..b64c106 100644 --- a/src/CoSimTypes.h +++ b/src/CoSimTypes.h @@ -22,7 +22,7 @@ enum class CoSimType { Server }; -[[nodiscard]] inline std::string_view ToString(CoSimType coSimType) { +[[nodiscard]] inline std::string ToString(CoSimType coSimType) { switch (coSimType) { case CoSimType::Client: return "Client"; @@ -103,7 +103,7 @@ enum class Command { return ""; } -[[nodiscard]] inline std::string_view ToString(DsVeosCoSim_TerminateReason terminateReason) { +[[nodiscard]] inline std::string ToString(DsVeosCoSim_TerminateReason terminateReason) { switch (terminateReason) { case DsVeosCoSim_TerminateReason_Finished: return "Finished"; @@ -153,7 +153,7 @@ enum class Command { return 0; } -[[nodiscard]] inline std::string_view ToString(DsVeosCoSim_DataType dataType) { +[[nodiscard]] inline std::string ToString(DsVeosCoSim_DataType dataType) { switch (dataType) { case DsVeosCoSim_DataType_Bool: return "Bool"; @@ -184,7 +184,7 @@ enum class Command { return ""; } -[[nodiscard]] inline std::string_view ToString(DsVeosCoSim_SizeKind sizeKind) { +[[nodiscard]] inline std::string ToString(DsVeosCoSim_SizeKind sizeKind) { switch (sizeKind) { case DsVeosCoSim_SizeKind_Fixed: return "Fixed"; diff --git a/src/Communication/LocalChannel.cpp b/src/Communication/LocalChannel.cpp index 20ff735..13a9225 100644 --- a/src/Communication/LocalChannel.cpp +++ b/src/Communication/LocalChannel.cpp @@ -4,7 +4,6 @@ #include "LocalChannel.h" -#include #include #include @@ -19,17 +18,17 @@ namespace { constexpr uint32_t ServerSharedMemorySize = 4; constexpr uint32_t BufferSize = 64 * 1024; -std::string_view ServerToClientPostFix = "ServerToClient"; -std::string_view ClientToServerPostFix = "ClientToServer"; +std::string ServerToClientPostFix = "ServerToClient"; +std::string ClientToServerPostFix = "ClientToServer"; std::string GetWriterName(std::string_view name, bool isServer) { - std::string_view postfix = isServer ? ServerToClientPostFix : ClientToServerPostFix; - return fmt::format("{}.{}", name, postfix); + std::string postfix = isServer ? ServerToClientPostFix : ClientToServerPostFix; + return std::string(name) + "." + postfix; } std::string GetReaderName(std::string_view name, bool isServer) { - std::string_view postfix = isServer ? ClientToServerPostFix : ServerToClientPostFix; - return fmt::format("{}.{}", name, postfix); + std::string postfix = isServer ? ClientToServerPostFix : ServerToClientPostFix; + return std::string(name) + "." + postfix; } constexpr uint32_t MaskIndex(uint32_t index) noexcept { @@ -45,9 +44,9 @@ LocalChannelBase::LocalChannelBase(std::string_view name, bool isServer) { bool initShm{}; - const std::string dataName = fmt::format("{}.Data", name); - const std::string newDataName = fmt::format("{}.NewData", name); - const std::string newSpaceName = fmt::format("{}.NewSpace", name); + const std::string dataName = std::string(name) + ".Data"; + const std::string newDataName = std::string(name) + ".NewData"; + const std::string newSpaceName = std::string(name) + ".NewSpace"; uint32_t totalSize = BufferSize + sizeof(Header); @@ -148,7 +147,8 @@ bool LocalChannelBase::CheckIfConnectionIsAlive() { return false; } - CheckResultWithMessage(IsProcessRunning(counterpartPid), fmt::format("Process with id {} exited.", counterpartPid)); + CheckResultWithMessage(IsProcessRunning(counterpartPid), + "Process with id " + std::to_string(counterpartPid) + " exited."); return true; } @@ -306,7 +306,7 @@ std::optional TryConnectToLocalChannel(std::string_view name) { auto& counter = *static_cast*>(sharedMemory->data()); const int32_t currentCounter = counter.fetch_add(1); - const std::string specificName = fmt::format("{}.{}", name, currentCounter); + const std::string specificName = std::string(name) + "." + std::to_string(currentCounter); return LocalChannel(specificName, false); } @@ -324,7 +324,7 @@ LocalChannelServer::LocalChannelServer(std::string_view name) : _name(name) { std::optional LocalChannelServer::TryAccept() { const int32_t currentCounter = _counter->load(); if (currentCounter > _lastCounter) { - const std::string specificName = fmt::format("{}.{}", _name, _lastCounter); + const std::string specificName = std::string(_name) + "." + std::to_string(_lastCounter); _lastCounter++; return LocalChannel(specificName, true); } diff --git a/src/Communication/LocalChannel.h b/src/Communication/LocalChannel.h index 4c0d531..89181a7 100644 --- a/src/Communication/LocalChannel.h +++ b/src/Communication/LocalChannel.h @@ -5,6 +5,9 @@ #ifdef _WIN32 #include +#include +#include +#include #include #include diff --git a/src/Communication/SocketChannel.h b/src/Communication/SocketChannel.h index aecacd1..c0b605a 100644 --- a/src/Communication/SocketChannel.h +++ b/src/Communication/SocketChannel.h @@ -2,6 +2,10 @@ #pragma once +#include +#include +#include +#include #include #include "Channel.h" diff --git a/src/Helpers/CoSimHelper.cpp b/src/Helpers/CoSimHelper.cpp index 4733229..306ba66 100644 --- a/src/Helpers/CoSimHelper.cpp +++ b/src/Helpers/CoSimHelper.cpp @@ -2,6 +2,8 @@ #include "CoSimHelper.h" +#include + namespace DsVeosCoSim { namespace { @@ -43,7 +45,7 @@ void LogTrace(std::string_view message) { } std::string GetSystemErrorMessage(int32_t errorCode) { - return fmt::format("Error code: {}. {}", errorCode, std::system_category().message(errorCode)); + return "Error code: " + std::to_string(errorCode) + ". " + std::system_category().message(errorCode); } } // namespace DsVeosCoSim diff --git a/src/Helpers/CoSimHelper.h b/src/Helpers/CoSimHelper.h index a2481b5..9ef459a 100644 --- a/src/Helpers/CoSimHelper.h +++ b/src/Helpers/CoSimHelper.h @@ -2,7 +2,7 @@ #pragma once -#include +#include #include "CoSimTypes.h" @@ -15,26 +15,6 @@ void LogWarning(std::string_view message); void LogInfo(std::string_view message); void LogTrace(std::string_view message); -template -void LogError(fmt::format_string format, T&&... args) { - LogError(vformat(format, fmt::make_format_args(args...))); -} - -template -void LogWarning(fmt::format_string format, T&&... args) { - LogWarning(vformat(format, fmt::make_format_args(args...))); -} - -template -void LogInfo(fmt::format_string format, T&&... args) { - LogInfo(vformat(format, fmt::make_format_args(args...))); -} - -template -void LogTrace(fmt::format_string format, T&&... args) { - LogTrace(vformat(format, fmt::make_format_args(args...))); -} - #define CheckResultWithMessage(result, message) \ do { \ if (!(result)) [[unlikely]] { \ @@ -58,7 +38,7 @@ class CoSimException final : public std::runtime_error { } CoSimException(std::string_view message, int32_t errorCode) - : std::runtime_error(fmt::format("{} {}", message, GetSystemErrorMessage(errorCode))) { + : std::runtime_error(std::string(message) + " " + GetSystemErrorMessage(errorCode)) { } }; diff --git a/src/IoBuffer.cpp b/src/IoBuffer.cpp index bd69a32..8f63bed 100644 --- a/src/IoBuffer.cpp +++ b/src/IoBuffer.cpp @@ -2,7 +2,6 @@ #include "IoBuffer.h" -#include #include #include "CoSimHelper.h" @@ -13,13 +12,13 @@ namespace DsVeosCoSim { namespace { -void CheckSizeKind(DsVeosCoSim_SizeKind sizeKind, std::string_view name) { +void CheckSizeKind(DsVeosCoSim_SizeKind sizeKind, const std::string& name) { switch (sizeKind) { // NOLINT case DsVeosCoSim_SizeKind_Fixed: case DsVeosCoSim_SizeKind_Variable: return; default: - throw CoSimException(fmt::format("Unknown size kind '{}' for IO signal '{}'.", ToString(sizeKind), name)); + throw CoSimException("Unknown size kind '" + ToString(sizeKind) + "' for IO signal '" + name + "'."); } } @@ -32,19 +31,20 @@ IoPartBufferBase::IoPartBufferBase(CoSimType coSimType, const std::vectorsecond; } - throw CoSimException(fmt::format("IO signal id {} is unknown.", signalId)); + throw CoSimException("IO signal id " + std::to_string(signalId) + " is unknown."); } RemoteIoPartBuffer::RemoteIoPartBuffer(CoSimType coSimType, @@ -164,8 +164,8 @@ void RemoteIoPartBuffer::WriteInternal(DsVeosCoSim_IoSignalId signalId, uint32_t if (metaData.info.sizeKind == DsVeosCoSim_SizeKind_Variable) { if (length > metaData.info.length) { - throw CoSimException( - fmt::format("Length of variable sized IO signal '{}' exceeds max size.", metaData.info.name)); + throw CoSimException("Length of variable sized IO signal '" + std::string(metaData.info.name) + + "' exceeds max size."); } if (data.currentLength != length) { @@ -178,10 +178,8 @@ void RemoteIoPartBuffer::WriteInternal(DsVeosCoSim_IoSignalId signalId, uint32_t data.currentLength = length; } else { if (length != metaData.info.length) { - throw CoSimException(fmt::format("Length of fixed sized IO signal '{}' must be {} but was {}.", - metaData.info.name, - metaData.info.length, - length)); + throw CoSimException("Length of fixed sized IO signal '" + std::string(metaData.info.name) + "' must be " + + std::to_string(metaData.info.length) + " but was " + std::to_string(length) + "."); } } @@ -259,8 +257,8 @@ bool RemoteIoPartBuffer::DeserializeInternal(ChannelReader& reader, uint32_t length = 0; CheckResultWithMessage(reader.Read(length), "Could not read current signal length."); if (length > metaData.info.length) { - throw CoSimException( - fmt::format("Length of variable sized IO signal '{}' exceeds max size.", metaData.info.name)); + throw CoSimException("Length of variable sized IO signal '" + std::string(metaData.info.name) + + "' exceeds max size."); } data.currentLength = length; @@ -355,17 +353,15 @@ void LocalIoPartBuffer::WriteInternal(DsVeosCoSim_IoSignalId signalId, uint32_t bool currentLengthChanged{}; if (metaData.info.sizeKind == DsVeosCoSim_SizeKind_Variable) { if (length > metaData.info.length) { - throw CoSimException( - fmt::format("Length of variable sized IO signal '{}' exceeds max size.", metaData.info.name)); + throw CoSimException("Length of variable sized IO signal '" + std::string(metaData.info.name) + + "' exceeds max size."); } currentLengthChanged = dataBuffer->currentLength != length; } else { if (length != metaData.info.length) { - throw CoSimException(fmt::format("Length of fixed sized IO signal '{}' must be {} but was {}.", - metaData.info.name, - metaData.info.length, - length)); + throw CoSimException("Length of fixed sized IO signal '" + std::string(metaData.info.name) + "' must be " + + std::to_string(metaData.info.length) + " but was " + std::to_string(length) + "."); } } @@ -473,8 +469,8 @@ IoBuffer::IoBuffer(CoSimType coSimType, std::string_view name, const std::vector& incomingSignals, const std::vector& outgoingSignals) { - std::string outgoingName = fmt::format("{}.Outgoing", name); - std::string incomingName = fmt::format("{}.Incoming", name); + std::string outgoingName = std::string(name) + ".Outgoing"; + std::string incomingName = std::string(name) + ".Incoming"; const std::vector* writeSignals = &outgoingSignals; const std::vector* readSignals = &incomingSignals; if (coSimType == CoSimType::Server) { diff --git a/src/OsAbstraction/Handle.cpp b/src/OsAbstraction/Handle.cpp index 3b2d05b..9f75ce0 100644 --- a/src/OsAbstraction/Handle.cpp +++ b/src/OsAbstraction/Handle.cpp @@ -5,7 +5,6 @@ #include "Handle.h" #include -#include #include "CoSimHelper.h" #include "OsUtilities.h" @@ -52,7 +51,7 @@ bool Handle::Wait(uint32_t milliseconds) const { case WAIT_FAILED: throw CoSimException("Could not wait for handle.", GetLastWindowsError()); default: - throw CoSimException(fmt::format("Could not wait for handle. Invalid result: {}.", result)); + throw CoSimException("Could not wait for handle. Invalid result: " + std::to_string(result) + "."); } } @@ -67,7 +66,8 @@ bool SignalAndWait(const Handle& toSignal, const Handle& toWait, uint32_t millis case WAIT_FAILED: throw CoSimException("Could not signal and wait for handle.", GetLastWindowsError()); default: - throw CoSimException(fmt::format("Could not signal and wait for handle. Invalid result: {}.", result)); + throw CoSimException("Could not signal and wait for handle. Invalid result: " + std::to_string(result) + + "."); } } diff --git a/src/OsAbstraction/NamedEvent.cpp b/src/OsAbstraction/NamedEvent.cpp index 34c9acc..dcf29b3 100644 --- a/src/OsAbstraction/NamedEvent.cpp +++ b/src/OsAbstraction/NamedEvent.cpp @@ -5,7 +5,6 @@ #include "NamedEvent.h" #include -#include #include "CoSimHelper.h" #include "OsUtilities.h" @@ -15,7 +14,7 @@ namespace DsVeosCoSim { namespace { [[nodiscard]] std::wstring GetFullNamedEventName(std::string_view name) { - return Utf8ToWide(fmt::format("Local\\dSPACE.VEOS.CoSim.Event.{}", name)); + return Utf8ToWide("Local\\dSPACE.VEOS.CoSim.Event." + std::string(name)); } } // namespace @@ -27,7 +26,7 @@ NamedEvent NamedEvent::CreateOrOpen(std::string_view name) { std::wstring fullName = GetFullNamedEventName(name); void* handle = ::CreateEventW(nullptr, FALSE, FALSE, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not create event '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not create event '" + std::string(name) + "'.", GetLastWindowsError()); } return NamedEvent(handle); @@ -37,7 +36,7 @@ NamedEvent NamedEvent::OpenExisting(std::string_view name) { std::wstring fullName = GetFullNamedEventName(name); void* handle = ::OpenEventW(EVENT_ALL_ACCESS, FALSE, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not open event '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not open event '" + std::string(name) + "'.", GetLastWindowsError()); } return NamedEvent(handle); diff --git a/src/OsAbstraction/NamedEvent.h b/src/OsAbstraction/NamedEvent.h index 1539068..37d6e1d 100644 --- a/src/OsAbstraction/NamedEvent.h +++ b/src/OsAbstraction/NamedEvent.h @@ -4,6 +4,7 @@ #ifdef _WIN32 +#include #include #include diff --git a/src/OsAbstraction/NamedMutex.cpp b/src/OsAbstraction/NamedMutex.cpp index a293103..239371b 100644 --- a/src/OsAbstraction/NamedMutex.cpp +++ b/src/OsAbstraction/NamedMutex.cpp @@ -5,7 +5,6 @@ #include "NamedMutex.h" #include -#include #include "CoSimHelper.h" #include "OsUtilities.h" @@ -15,7 +14,7 @@ namespace DsVeosCoSim { namespace { [[nodiscard]] std::wstring GetFullNamedMutexName(std::string_view name) { - return Utf8ToWide(fmt::format("Local\\dSPACE.VEOS.CoSim.Mutex.{}", name)); + return Utf8ToWide("Local\\dSPACE.VEOS.CoSim.Mutex." + std::string(name)); } } // namespace @@ -27,7 +26,7 @@ NamedMutex NamedMutex::CreateOrOpen(std::string_view name) { std::wstring fullName = GetFullNamedMutexName(name); void* handle = ::CreateMutexW(nullptr, FALSE, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not create or open mutex '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not create or open mutex '" + std::string(name) + "'.", GetLastWindowsError()); } return NamedMutex(handle); @@ -37,7 +36,7 @@ NamedMutex NamedMutex::OpenExisting(std::string_view name) { std::wstring fullName = GetFullNamedMutexName(name); void* handle = ::OpenMutexW(MUTEX_ALL_ACCESS, FALSE, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not open mutex '{}'", name), GetLastWindowsError()); + throw CoSimException("Could not open mutex '" + std::string(name) + "'.", GetLastWindowsError()); } return NamedMutex(handle); diff --git a/src/OsAbstraction/NamedMutex.h b/src/OsAbstraction/NamedMutex.h index 8a4e237..300c686 100644 --- a/src/OsAbstraction/NamedMutex.h +++ b/src/OsAbstraction/NamedMutex.h @@ -4,6 +4,7 @@ #ifdef _WIN32 +#include #include #include diff --git a/src/OsAbstraction/OsUtilities.cpp b/src/OsAbstraction/OsUtilities.cpp index c5bda71..1c824f7 100644 --- a/src/OsAbstraction/OsUtilities.cpp +++ b/src/OsAbstraction/OsUtilities.cpp @@ -5,7 +5,9 @@ #include "OsUtilities.h" #include -#include +#include +#include +#include namespace DsVeosCoSim { diff --git a/src/OsAbstraction/OsUtilities.h b/src/OsAbstraction/OsUtilities.h index 4c200d8..0ff1749 100644 --- a/src/OsAbstraction/OsUtilities.h +++ b/src/OsAbstraction/OsUtilities.h @@ -4,6 +4,7 @@ #ifdef _WIN32 +#include #include #include diff --git a/src/OsAbstraction/SharedMemory.cpp b/src/OsAbstraction/SharedMemory.cpp index 8473d7e..cbbfdc7 100644 --- a/src/OsAbstraction/SharedMemory.cpp +++ b/src/OsAbstraction/SharedMemory.cpp @@ -5,7 +5,9 @@ #include "SharedMemory.h" #include -#include +#include +#include +#include #include "CoSimHelper.h" #include "OsUtilities.h" @@ -15,7 +17,7 @@ namespace DsVeosCoSim { namespace { [[nodiscard]] std::wstring GetFullSharedMemoryName(std::string_view name) { - return Utf8ToWide(fmt::format("Local\\dSPACE.VEOS.CoSim.SharedMemory.{}", name)); + return Utf8ToWide("Local\\dSPACE.VEOS.CoSim.SharedMemory." + std::string(name)); } } // namespace @@ -25,7 +27,7 @@ SharedMemory::SharedMemory(std::string_view name, size_t size, Handle handle) _data = ::MapViewOfFile(_handle, FILE_MAP_ALL_ACCESS, 0, 0, _size); if (!_data) { (void)::CloseHandle(_handle); - throw CoSimException(fmt::format("Could not map view of shared memory '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not map view of shared memory '" + std::string(name) + "'.", GetLastWindowsError()); } } @@ -56,7 +58,8 @@ SharedMemory SharedMemory::CreateOrOpen(std::string_view name, size_t size) { void* handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, sizeHigh, sizeLow, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not create or open shared memory '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not create or open shared memory '" + std::string(name) + "'.", + GetLastWindowsError()); } return {name, size, handle}; @@ -66,7 +69,7 @@ SharedMemory SharedMemory::OpenExisting(std::string_view name, size_t size) { std::wstring fullName = GetFullSharedMemoryName(name); void* handle = ::OpenFileMappingW(FILE_MAP_WRITE, FALSE, fullName.c_str()); if (!handle) { - throw CoSimException(fmt::format("Could not open shared memory '{}'.", name), GetLastWindowsError()); + throw CoSimException("Could not open shared memory '" + std::string(name) + "'.", GetLastWindowsError()); } return {name, size, handle}; diff --git a/src/OsAbstraction/SharedMemory.h b/src/OsAbstraction/SharedMemory.h index 9ca8aa8..78c5b68 100644 --- a/src/OsAbstraction/SharedMemory.h +++ b/src/OsAbstraction/SharedMemory.h @@ -4,6 +4,7 @@ #ifdef _WIN32 +#include #include #include diff --git a/src/OsAbstraction/Socket.cpp b/src/OsAbstraction/Socket.cpp index 17aa070..2b8c9ea 100644 --- a/src/OsAbstraction/Socket.cpp +++ b/src/OsAbstraction/Socket.cpp @@ -28,10 +28,6 @@ #include #endif -#ifdef _MSC_VER -#pragma comment(lib, "WS2_32.Lib") -#endif - #ifdef _WIN32 namespace fs = std::filesystem; #endif @@ -61,10 +57,10 @@ constexpr int32_t ErrorCodeConnectionReset = ECONNRESET; [[nodiscard]] std::string GetUdsPath(std::string_view name) { #ifdef _WIN32 fs::path tempDir = fs::temp_directory_path(); - fs::path fileDir = tempDir / fmt::format("dSPACE.VEOS.CoSim.{}", name); + fs::path fileDir = tempDir / ("dSPACE.VEOS.CoSim." + std::string(name)); return fileDir.string(); #else - return fmt::format("dSPACE.VEOS.CoSim.{}", name); + return "dSPACE.VEOS.CoSim." + std::string(name); #endif } @@ -724,7 +720,7 @@ bool Socket::Receive(void* destination, int32_t size, int32_t& receivedSize) con return false; } - LogError("Could not receive from remote endpoint. {}", GetSystemErrorMessage(errorCode)); + LogError("Could not receive from remote endpoint. " + GetSystemErrorMessage(errorCode)); return false; } @@ -755,7 +751,7 @@ bool Socket::Send(const void* source, int32_t size, int32_t& sentSize) const { return false; } - LogError("Could not send to remote endpoint. {}", GetSystemErrorMessage(errorCode)); + LogError("Could not send to remote endpoint. " + GetSystemErrorMessage(errorCode)); return false; } diff --git a/src/OsAbstraction/Socket.h b/src/OsAbstraction/Socket.h index a28be6e..68b8586 100644 --- a/src/OsAbstraction/Socket.h +++ b/src/OsAbstraction/Socket.h @@ -2,6 +2,7 @@ #pragma once +#include #include #include #include @@ -16,6 +17,19 @@ enum class AddressFamily { Ipv6 = 23 }; +[[nodiscard]] inline std::string_view ToString(AddressFamily addressFamily) { + switch (addressFamily) { + case DsVeosCoSim::AddressFamily::Ipv4: + return "Ipv4"; + case DsVeosCoSim::AddressFamily::Ipv6: + return "Ipv6"; + case DsVeosCoSim::AddressFamily::Uds: + return "Uds"; + } + + return ""; +} + #ifdef _WIN32 using socket_t = uintptr_t; constexpr socket_t InvalidSocket = UINTPTR_MAX; @@ -90,17 +104,4 @@ class Socket { std::string _path; }; -[[nodiscard]] inline std::string_view format_as(DsVeosCoSim::AddressFamily addressFamily) { - switch (addressFamily) { - case DsVeosCoSim::AddressFamily::Ipv4: - return "Ipv4"; - case DsVeosCoSim::AddressFamily::Ipv6: - return "Ipv6"; - case DsVeosCoSim::AddressFamily::Uds: - return "Uds"; - } - - return ""; -} - } // namespace DsVeosCoSim diff --git a/src/PortMapper.cpp b/src/PortMapper.cpp index 8461434..8894c29 100644 --- a/src/PortMapper.cpp +++ b/src/PortMapper.cpp @@ -81,7 +81,7 @@ void PortMapperServer::RunPortMapperServer() { } } } catch (const std::exception& e) { - LogError("The following exception occurred in port mapper thread: {}", e.what()); + LogError("The following exception occurred in port mapper thread: " + std::string(e.what())); } } } @@ -101,7 +101,7 @@ bool PortMapperServer::HandleClient(Channel& channel) { CheckResultWithMessage(HandleUnsetPort(channel), "Could not handle unset port request."); return true; default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -110,15 +110,14 @@ bool PortMapperServer::HandleGetPort(Channel& channel) { CheckResultWithMessage(Protocol::ReadGetPort(channel.GetReader(), name), "Could not read get port frame."); if (IsPortMapperServerVerbose()) { - LogTrace("Get '{}'", name); + LogTrace("Get '" + name + "'"); } const auto search = _ports.find(name); if (search == _ports.end()) { - CheckResultWithMessage( - Protocol::SendError(channel.GetWriter(), - fmt::format("Could not find port for dSPACE VEOS CoSim server '{}'.", name)), - "Could not send error frame."); + CheckResultWithMessage(Protocol::SendError(channel.GetWriter(), + "Could not find port for dSPACE VEOS CoSim server '" + name + "'."), + "Could not send error frame."); return true; } @@ -133,7 +132,7 @@ bool PortMapperServer::HandleSetPort(Channel& channel) { CheckResultWithMessage(Protocol::ReadSetPort(channel.GetReader(), name, port), "Could not read set port frame."); if (IsPortMapperServerVerbose()) { - LogTrace("Set '{}':{}", name, port); + LogTrace("Set '" + name + "':" + std::to_string(port)); } _ports[name] = port; @@ -151,7 +150,7 @@ bool PortMapperServer::HandleUnsetPort(Channel& channel) { CheckResultWithMessage(Protocol::ReadUnsetPort(channel.GetReader(), name), "Could not read unset port frame."); if (IsPortMapperServerVerbose()) { - LogTrace("Unset '{}'", name); + LogTrace("Unset '" + name + "'"); } _ports.erase(name); @@ -171,14 +170,15 @@ void PortMapperServer::DumpEntries() { LogTrace("PortMapper Ports:"); for (auto& [name, port] : _ports) { - LogTrace(" '{}': {}", name, port); + LogTrace(" '" + name + "': {}" + std::to_string(port)); } } } bool PortMapper_GetPort(std::string_view ipAddress, std::string_view serverName, uint16_t& port) { if (IsPortMapperClientVerbose()) { - LogTrace("PortMapper_GetPort(ipAddress: '{}', serverName: '{}')", ipAddress, serverName); + LogTrace("PortMapper_GetPort(ipAddress: '" + std::string(ipAddress) + "', serverName: '" + + std::string(serverName) + "')"); } std::optional channel = @@ -203,7 +203,7 @@ bool PortMapper_GetPort(std::string_view ipAddress, std::string_view serverName, throw CoSimException(errorMessage); } default: - throw CoSimException(fmt::format("PortMapper_GetPort: Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("PortMapper_GetPort: Received unexpected frame " + ToString(frameKind) + "."); } } @@ -227,7 +227,7 @@ bool PortMapper_SetPort(std::string_view name, uint16_t port) { throw CoSimException(errorString); } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } @@ -251,7 +251,7 @@ bool PortMapper_UnsetPort(std::string_view name) { throw CoSimException(errorString); } default: - throw CoSimException(fmt::format("Received unexpected frame {}.", ToString(frameKind))); + throw CoSimException("Received unexpected frame " + ToString(frameKind) + "."); } } diff --git a/src/Protocol.h b/src/Protocol.h index b1263b6..6ca48d1 100644 --- a/src/Protocol.h +++ b/src/Protocol.h @@ -2,6 +2,8 @@ #pragma once +#include + #include "BusBuffer.h" #include "Channel.h" #include "CoSimTypes.h" @@ -36,7 +38,7 @@ enum class FrameKind { UnsetPort }; -[[nodiscard]] inline std::string_view ToString(const FrameKind& frameKind) { +[[nodiscard]] inline std::string ToString(const FrameKind& frameKind) { switch (frameKind) { case FrameKind::Ping: return "Ping"; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a6a9a2e..b94515d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,12 @@ # Copyright dSPACE GmbH. All rights reserved. add_executable( - ${PROJECT_NAME}Test + DsVeosCoSimTest +) + +target_sources( + DsVeosCoSimTest + PRIVATE Communication/TestLocalChannel.cpp Communication/TestTcpChannel.cpp Communication/TestUdsChannel.cpp @@ -20,22 +25,22 @@ add_executable( ) target_include_directories( - ${PROJECT_NAME}Test + DsVeosCoSimTest PRIVATE Helpers ) if(${CMAKE_BUILD_TYPE} STREQUAL "Release") target_compile_definitions( - ${PROJECT_NAME}Test + DsVeosCoSimTest PRIVATE EXCEPTION_TESTS ) endif() target_link_libraries( - ${PROJECT_NAME}Test - ${PROJECT_NAME} + DsVeosCoSimTest + DsVeosCoSim shared GTest::gtest GTest::gmock diff --git a/test/Communication/TestLocalChannel.cpp b/test/Communication/TestLocalChannel.cpp index b6068f0..d23c6a6 100644 --- a/test/Communication/TestLocalChannel.cpp +++ b/test/Communication/TestLocalChannel.cpp @@ -4,6 +4,11 @@ #include #include +#include +#include +#include +#include +#include #include "Generator.h" #include "Helper.h" diff --git a/test/Communication/TestTcpChannel.cpp b/test/Communication/TestTcpChannel.cpp index 7f61b51..c58c741 100644 --- a/test/Communication/TestTcpChannel.cpp +++ b/test/Communication/TestTcpChannel.cpp @@ -2,7 +2,13 @@ #include #include +#include +#include +#include +#include +#include #include +#include #include "Generator.h" #include "Helper.h" @@ -39,7 +45,7 @@ INSTANTIATE_TEST_SUITE_P(, TestTcpChannel, testing::ValuesIn(GetValues()), [](const testing::TestParamInfo& info) { - return std::string(format_as(info.param.addressFamily)); + return std::string(ToString(info.param.addressFamily)); }); TEST_F(TestTcpChannel, StartServer) { diff --git a/test/Communication/TestUdsChannel.cpp b/test/Communication/TestUdsChannel.cpp index dac7219..43d3c55 100644 --- a/test/Communication/TestUdsChannel.cpp +++ b/test/Communication/TestUdsChannel.cpp @@ -2,6 +2,10 @@ #include #include +#include +#include +#include +#include #include #include "Generator.h" diff --git a/test/Helpers/TestHelper.h b/test/Helpers/TestHelper.h index ad77bab..1c336d0 100644 --- a/test/Helpers/TestHelper.h +++ b/test/Helpers/TestHelper.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include #include diff --git a/test/OsAbstraction/TestTcpSocket.cpp b/test/OsAbstraction/TestTcpSocket.cpp index be2b3da..d0754ad 100644 --- a/test/OsAbstraction/TestTcpSocket.cpp +++ b/test/OsAbstraction/TestTcpSocket.cpp @@ -1,6 +1,7 @@ // Copyright dSPACE GmbH. All rights reserved. #include +#include #include #include "Generator.h" @@ -39,7 +40,7 @@ INSTANTIATE_TEST_SUITE_P(, testing::ValuesIn(GetValues()), [](const testing::TestParamInfo& info) { std::string access = info.param.enableRemoteAccess ? "Remote" : "Local"; - return fmt::format("{}_{}", info.param.addressFamily, access); + return fmt::format("{}_{}", ToString(info.param.addressFamily), access); }); TEST_P(TestTcpSocket, Create) { diff --git a/test/TestPortMapper.cpp b/test/TestPortMapper.cpp index 09d4ddc..4fecf56 100644 --- a/test/TestPortMapper.cpp +++ b/test/TestPortMapper.cpp @@ -1,5 +1,6 @@ // Copyright dSPACE GmbH. All rights reserved. +#include #include #include diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index f6a87d2..d5de8cb 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -1,3 +1,16 @@ +# Copyright dSPACE GmbH. All rights reserved. + +if(DSVEOSCOSIM_BUILD_TESTS OR DSVEOSCOSIM_BUILD_BENCHMARKS) + add_subdirectory(fmt) +endif() + +if(DSVEOSCOSIM_BUILD_TESTS) + set(INSTALL_GTEST OFF) + set(gtest_force_shared_crt ON) + add_subdirectory(googletest) +endif() + +if(DSVEOSCOSIM_BUILD_BENCHMARKS) add_library( asio STATIC @@ -29,3 +42,19 @@ if(WIN32 AND CMAKE_SYSTEM_VERSION) -D_WIN32_WINNT=${version} ) endif() + +if(WIN32) +target_link_libraries( + asio + bcrypt + mswsock +) +endif() + +set(BENCHMARK_ENABLE_INSTALL OFF) +set(BENCHMARK_INSTALL_DOCS OFF) +set(BENCHMARK_ENABLE_GTEST_TESTS OFF) +set(BENCHMARK_USE_BUNDLED_GTEST OFF) + +add_subdirectory(benchmark) +endif() diff --git a/utilities/PerformanceTestClient/CMakeLists.txt b/utilities/PerformanceTestClient/CMakeLists.txt index c771ed8..87befd0 100644 --- a/utilities/PerformanceTestClient/CMakeLists.txt +++ b/utilities/PerformanceTestClient/CMakeLists.txt @@ -2,6 +2,11 @@ add_executable( PerformanceTestClient +) + +target_sources( + PerformanceTestClient + PRIVATE ClientAsioBlocking.cpp ClientCoSimCallbackBased.cpp ClientCoSimPollingBased.cpp @@ -24,7 +29,7 @@ target_include_directories( target_link_libraries( PerformanceTestClient - ${PROJECT_NAME} + DsVeosCoSim shared asio ) diff --git a/utilities/PerformanceTestClient/ClientAsioBlocking.cpp b/utilities/PerformanceTestClient/ClientAsioBlocking.cpp index b02fe9a..ee2bb8b 100644 --- a/utilities/PerformanceTestClient/ClientAsioBlocking.cpp +++ b/utilities/PerformanceTestClient/ClientAsioBlocking.cpp @@ -4,6 +4,7 @@ #include #include "CoSimHelper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientCoSimCallbackBased.cpp b/utilities/PerformanceTestClient/ClientCoSimCallbackBased.cpp index 77fa3df..b60b1c2 100644 --- a/utilities/PerformanceTestClient/ClientCoSimCallbackBased.cpp +++ b/utilities/PerformanceTestClient/ClientCoSimCallbackBased.cpp @@ -6,6 +6,7 @@ #include "CoSimClient.h" #include "CoSimTypes.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientCoSimPollingBased.cpp b/utilities/PerformanceTestClient/ClientCoSimPollingBased.cpp index 83af046..0c5926b 100644 --- a/utilities/PerformanceTestClient/ClientCoSimPollingBased.cpp +++ b/utilities/PerformanceTestClient/ClientCoSimPollingBased.cpp @@ -7,6 +7,7 @@ #include "CoSimClient.h" #include "CoSimTypes.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientEvents.cpp b/utilities/PerformanceTestClient/ClientEvents.cpp index c2a7fca..d54a7c2 100644 --- a/utilities/PerformanceTestClient/ClientEvents.cpp +++ b/utilities/PerformanceTestClient/ClientEvents.cpp @@ -2,6 +2,7 @@ #ifdef _WIN32 #include "CoSimHelper.h" +#include "LogHelper.h" #include "NamedEvent.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientLocalCommunication.cpp b/utilities/PerformanceTestClient/ClientLocalCommunication.cpp index 2af8012..5725f99 100644 --- a/utilities/PerformanceTestClient/ClientLocalCommunication.cpp +++ b/utilities/PerformanceTestClient/ClientLocalCommunication.cpp @@ -2,6 +2,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientPipe.cpp b/utilities/PerformanceTestClient/ClientPipe.cpp index 7b56616..5527460 100644 --- a/utilities/PerformanceTestClient/ClientPipe.cpp +++ b/utilities/PerformanceTestClient/ClientPipe.cpp @@ -2,6 +2,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "OsAbstractionTestHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientRemoteCommunication.cpp b/utilities/PerformanceTestClient/ClientRemoteCommunication.cpp index 9aec6a5..111696c 100644 --- a/utilities/PerformanceTestClient/ClientRemoteCommunication.cpp +++ b/utilities/PerformanceTestClient/ClientRemoteCommunication.cpp @@ -4,6 +4,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" #include "SocketChannel.h" diff --git a/utilities/PerformanceTestClient/ClientTcp.cpp b/utilities/PerformanceTestClient/ClientTcp.cpp index 5d668f3..dee5742 100644 --- a/utilities/PerformanceTestClient/ClientTcp.cpp +++ b/utilities/PerformanceTestClient/ClientTcp.cpp @@ -4,6 +4,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" #include "Socket.h" diff --git a/utilities/PerformanceTestClient/ClientUdp.cpp b/utilities/PerformanceTestClient/ClientUdp.cpp index aa510d9..56600f4 100644 --- a/utilities/PerformanceTestClient/ClientUdp.cpp +++ b/utilities/PerformanceTestClient/ClientUdp.cpp @@ -4,6 +4,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "OsAbstractionTestHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" diff --git a/utilities/PerformanceTestClient/ClientUds.cpp b/utilities/PerformanceTestClient/ClientUds.cpp index dc0d2d3..bff12e2 100644 --- a/utilities/PerformanceTestClient/ClientUds.cpp +++ b/utilities/PerformanceTestClient/ClientUds.cpp @@ -4,6 +4,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "RunPerformanceTest.h" #include "Socket.h" diff --git a/utilities/PerformanceTestClient/RunPerformanceTest.cpp b/utilities/PerformanceTestClient/RunPerformanceTest.cpp index 19fe6da..1c1db50 100644 --- a/utilities/PerformanceTestClient/RunPerformanceTest.cpp +++ b/utilities/PerformanceTestClient/RunPerformanceTest.cpp @@ -6,9 +6,9 @@ #include #include -#include "CoSimHelper.h" #include "Event.h" #include "Helper.h" +#include "LogHelper.h" using namespace DsVeosCoSim; diff --git a/utilities/PerformanceTestServer/CMakeLists.txt b/utilities/PerformanceTestServer/CMakeLists.txt index f83e1cb..29ea01d 100644 --- a/utilities/PerformanceTestServer/CMakeLists.txt +++ b/utilities/PerformanceTestServer/CMakeLists.txt @@ -2,6 +2,11 @@ add_executable( PerformanceTestServer +) + +target_sources( + PerformanceTestServer + PRIVATE Program.cpp ServerAsioBlocking.cpp ServerCoSim.cpp @@ -16,7 +21,7 @@ add_executable( target_link_libraries( PerformanceTestServer - ${PROJECT_NAME} + DsVeosCoSim shared asio ) diff --git a/utilities/PerformanceTestServer/ServerAsioBlocking.cpp b/utilities/PerformanceTestServer/ServerAsioBlocking.cpp index 21b6e3f..fb5896d 100644 --- a/utilities/PerformanceTestServer/ServerAsioBlocking.cpp +++ b/utilities/PerformanceTestServer/ServerAsioBlocking.cpp @@ -1,10 +1,10 @@ // Copyright dSPACE GmbH. All rights reserved. -#include #include #include #include "CoSimHelper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" using namespace DsVeosCoSim; diff --git a/utilities/PerformanceTestServer/ServerEvents.cpp b/utilities/PerformanceTestServer/ServerEvents.cpp index f9a2bcd..fd7076d 100644 --- a/utilities/PerformanceTestServer/ServerEvents.cpp +++ b/utilities/PerformanceTestServer/ServerEvents.cpp @@ -3,7 +3,7 @@ #ifdef _WIN32 #include -#include "CoSimHelper.h" +#include "LogHelper.h" #include "NamedEvent.h" #include "PerformanceTestHelper.h" #include "SharedMemory.h" diff --git a/utilities/PerformanceTestServer/ServerLocalCommunication.cpp b/utilities/PerformanceTestServer/ServerLocalCommunication.cpp index e8c30f5..0de769f 100644 --- a/utilities/PerformanceTestServer/ServerLocalCommunication.cpp +++ b/utilities/PerformanceTestServer/ServerLocalCommunication.cpp @@ -4,6 +4,7 @@ #include #include "CoSimHelper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #ifdef _WIN32 diff --git a/utilities/PerformanceTestServer/ServerPipe.cpp b/utilities/PerformanceTestServer/ServerPipe.cpp index 60fcb94..ce8bc91 100644 --- a/utilities/PerformanceTestServer/ServerPipe.cpp +++ b/utilities/PerformanceTestServer/ServerPipe.cpp @@ -2,12 +2,10 @@ #include -#include "CoSimHelper.h" +#include "LogHelper.h" #include "OsAbstractionTestHelper.h" #include "PerformanceTestHelper.h" -using namespace DsVeosCoSim; - namespace { void PipeServerRun() { diff --git a/utilities/PerformanceTestServer/ServerRemoteCommunication.cpp b/utilities/PerformanceTestServer/ServerRemoteCommunication.cpp index 7e5aef5..c568631 100644 --- a/utilities/PerformanceTestServer/ServerRemoteCommunication.cpp +++ b/utilities/PerformanceTestServer/ServerRemoteCommunication.cpp @@ -4,6 +4,7 @@ #include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "SocketChannel.h" diff --git a/utilities/PerformanceTestServer/ServerTcp.cpp b/utilities/PerformanceTestServer/ServerTcp.cpp index b8d9125..ed1a833 100644 --- a/utilities/PerformanceTestServer/ServerTcp.cpp +++ b/utilities/PerformanceTestServer/ServerTcp.cpp @@ -2,8 +2,8 @@ #include -#include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "Socket.h" diff --git a/utilities/PerformanceTestServer/ServerUdp.cpp b/utilities/PerformanceTestServer/ServerUdp.cpp index b19d346..4a2fc10 100644 --- a/utilities/PerformanceTestServer/ServerUdp.cpp +++ b/utilities/PerformanceTestServer/ServerUdp.cpp @@ -2,12 +2,10 @@ #include -#include "CoSimHelper.h" +#include "LogHelper.h" #include "OsAbstractionTestHelper.h" #include "PerformanceTestHelper.h" -using namespace DsVeosCoSim; - namespace { void UdpServerRun() { diff --git a/utilities/PerformanceTestServer/ServerUds.cpp b/utilities/PerformanceTestServer/ServerUds.cpp index d4484cb..a68db25 100644 --- a/utilities/PerformanceTestServer/ServerUds.cpp +++ b/utilities/PerformanceTestServer/ServerUds.cpp @@ -2,8 +2,8 @@ #include -#include "CoSimHelper.h" #include "Helper.h" +#include "LogHelper.h" #include "PerformanceTestHelper.h" #include "Socket.h" diff --git a/utilities/TestClient/CMakeLists.txt b/utilities/TestClient/CMakeLists.txt index 84ba874..7f06915 100644 --- a/utilities/TestClient/CMakeLists.txt +++ b/utilities/TestClient/CMakeLists.txt @@ -2,11 +2,16 @@ add_executable( TestClient +) + +target_sources( + TestClient + PRIVATE Program.cpp ) target_link_libraries( TestClient - ${PROJECT_NAME} + DsVeosCoSim shared ) diff --git a/utilities/TestServer/CMakeLists.txt b/utilities/TestServer/CMakeLists.txt index cb10066..adf3e79 100644 --- a/utilities/TestServer/CMakeLists.txt +++ b/utilities/TestServer/CMakeLists.txt @@ -2,11 +2,16 @@ add_executable( TestServer +) + +target_sources( + TestServer + PRIVATE Program.cpp ) target_link_libraries( TestServer - ${PROJECT_NAME} + DsVeosCoSim shared ) diff --git a/utilities/TestServer/Program.cpp b/utilities/TestServer/Program.cpp index 75cbbc9..04b249c 100644 --- a/utilities/TestServer/Program.cpp +++ b/utilities/TestServer/Program.cpp @@ -42,7 +42,7 @@ State g_state; std::thread::id g_simulationThreadId; -std::string format_as(State state) { +[[nodiscard]] std::string ToString(State state) { switch (state) { case State::Unloaded: return "Unloaded"; @@ -54,9 +54,9 @@ std::string format_as(State state) { return "Paused"; case State::Terminated: return "Terminated"; - default: // NOLINT(clang-diagnostic-covered-switch-default) - return "Unknown"; } + + return ""; } void DoSimulation() { @@ -111,7 +111,7 @@ void StartSimulation() { } if (g_state != State::Stopped) { - LogError("Could not start in state {}.", format_as(g_state)); + LogError("Could not start in state {}.", ToString(g_state)); return; } @@ -133,7 +133,7 @@ void StopSimulation() { } if ((g_state != State::Running) && (g_state != State::Paused)) { - LogError("Could not stop in state {}.", g_state); + LogError("Could not stop in state {}.", ToString(g_state)); return; } @@ -152,7 +152,7 @@ void PauseSimulation() { } if (g_state != State::Running) { - LogError("Could not pause in state {}.", g_state); + LogError("Could not pause in state {}.", ToString(g_state)); return; } @@ -171,7 +171,7 @@ void ContinueSimulation() { } if (g_state != State::Paused) { - LogError("Could not start in state {}.", g_state); + LogError("Could not start in state {}.", ToString(g_state)); return; } @@ -190,7 +190,7 @@ void TerminateSimulation() { } if (g_state == State::Unloaded) { - LogError("Could not terminate in state {}.", g_state); + LogError("Could not terminate in state {}.", ToString(g_state)); return; } @@ -234,7 +234,7 @@ void LoadSimulation(bool isClientOptional, std::string_view name) { LogInfo("Loading ..."); if (g_state != State::Unloaded) { - LogError("Could not load in state {}.", g_state); + LogError("Could not load in state {}.", ToString(g_state)); return; }