From b91044f04a950a44ca3036ac9bbb186dd2007ab5 Mon Sep 17 00:00:00 2001 From: KonradBkd <117755498+KonradBkd@users.noreply.github.com> Date: Fri, 11 Oct 2024 09:31:05 +0200 Subject: [PATCH] dev: Add missing controllerType in ServiceDescriptor of SimulatedController (#128) * dev: Add missing controllerType in ServiceDescriptor of SimulatedController * dev: Update Changelog --- .../source/core/internal/ServiceDescriptor.hpp | 2 +- .../netsim/SimulatedNetworkInternal.cpp | 17 +++++++++++++++-- .../netsim/SimulatedNetworkInternal.hpp | 2 ++ .../netsim/SimulatedNetworkRouter.cpp | 7 +++++-- .../netsim/SimulatedNetworkRouter.hpp | 1 + docs/CHANGELOG.rst | 5 +++++ 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/SilKit/source/core/internal/ServiceDescriptor.hpp b/SilKit/source/core/internal/ServiceDescriptor.hpp index ec747f3ef..22d375747 100644 --- a/SilKit/source/core/internal/ServiceDescriptor.hpp +++ b/SilKit/source/core/internal/ServiceDescriptor.hpp @@ -289,7 +289,7 @@ std::string ServiceDescriptor::to_string() const case ServiceType::SimulatedController: if (!GetSupplementalDataItem(SilKit::Core::Discovery::controllerType, controllerTypeName)) { - throw LogicError("supplementalData.size() > 0"); + throw LogicError("ServiceDescriptor::to_string() failed: No controller type defined in supplemental data."); } ss << separator << controllerTypeName << separator << GetNetworkName() << separator << GetServiceName(); diff --git a/SilKit/source/experimental/netsim/SimulatedNetworkInternal.cpp b/SilKit/source/experimental/netsim/SimulatedNetworkInternal.cpp index afeb8b67d..75ec411c8 100644 --- a/SilKit/source/experimental/netsim/SimulatedNetworkInternal.cpp +++ b/SilKit/source/experimental/netsim/SimulatedNetworkInternal.cpp @@ -8,6 +8,7 @@ #include "eventproducers/FlexRayEventProducer.hpp" #include "eventproducers/EthernetEventProducer.hpp" #include "eventproducers/LinEventProducer.hpp" +#include "ServiceConfigKeys.hpp" namespace SilKit { namespace Experimental { @@ -57,13 +58,23 @@ void SimulatedNetworkInternal::CreateAndSetEventProducer() } } +auto SimulatedNetworkInternal::ExtractControllerTypeName(const SilKit::Core::ServiceDescriptor& serviceDescriptor) + -> std::string +{ + std::string controllerTypeName = ""; + if (!serviceDescriptor.GetSupplementalDataItem(SilKit::Core::Discovery::controllerType, controllerTypeName)) + { + throw LogicError("No controller type defined in supplemental data."); + } + return controllerTypeName; +} + void SimulatedNetworkInternal::AddSimulatedController(const SilKit::Core::ServiceDescriptor& serviceDescriptor, ControllerDescriptor controllerDescriptor) { auto controllerName = serviceDescriptor.GetServiceName(); auto fromParticipantName = serviceDescriptor.GetParticipantName(); auto serviceId = serviceDescriptor.GetServiceId(); - auto serviceDescriptorStr = serviceDescriptor.to_string(); _controllerDescriptors[fromParticipantName][serviceId] = controllerDescriptor; @@ -71,7 +82,9 @@ void SimulatedNetworkInternal::AddSimulatedController(const SilKit::Core::Servic if (userSimulatedController) { - _simulatedNetworkRouter->AddSimulatedController(fromParticipantName, controllerName, serviceId, + std::string controllerTypeName = ExtractControllerTypeName(serviceDescriptor); + _simulatedNetworkRouter->AddSimulatedController(fromParticipantName, controllerName, + controllerTypeName, serviceId, controllerDescriptor, userSimulatedController); } else diff --git a/SilKit/source/experimental/netsim/SimulatedNetworkInternal.hpp b/SilKit/source/experimental/netsim/SimulatedNetworkInternal.hpp index 75b253eb0..b47f0c324 100644 --- a/SilKit/source/experimental/netsim/SimulatedNetworkInternal.hpp +++ b/SilKit/source/experimental/netsim/SimulatedNetworkInternal.hpp @@ -35,6 +35,8 @@ class SimulatedNetworkInternal Core::EndpointId serviceId) -> std::pair; void RemoveControllerDescriptor(const std::string& fromParticipantName, Core::EndpointId serviceId); + auto ExtractControllerTypeName(const SilKit::Core::ServiceDescriptor& serviceDescriptor) -> std::string; + Core::IParticipantInternal* _participant = nullptr; SilKit::Services::Logging::ILogger* _logger; diff --git a/SilKit/source/experimental/netsim/SimulatedNetworkRouter.cpp b/SilKit/source/experimental/netsim/SimulatedNetworkRouter.cpp index 0e45f7b93..cdd6421f2 100644 --- a/SilKit/source/experimental/netsim/SimulatedNetworkRouter.cpp +++ b/SilKit/source/experimental/netsim/SimulatedNetworkRouter.cpp @@ -7,6 +7,7 @@ #include "NetworkSimulatorDatatypesInternal.hpp" #include "Configuration.hpp" #include "silkit/experimental/netsim/string_utils.hpp" +#include "ServiceConfigKeys.hpp" namespace SilKit { namespace Experimental { @@ -52,7 +53,8 @@ bool SimulatedNetworkRouter::AllowReception(const SilKit::Core::IServiceEndpoint } void SimulatedNetworkRouter::AddSimulatedController(const std::string& fromParticipantName, - const std::string& controllerName, Core::EndpointId serviceId, + const std::string& controllerName, + const std::string& controllerTypeName, Core::EndpointId serviceId, ControllerDescriptor controllerDescriptor, ISimulatedController* userSimulatedController) { @@ -65,7 +67,8 @@ void SimulatedNetworkRouter::AddSimulatedController(const std::string& fromParti fromCopy.SetServiceId(serviceId); fromCopy.SetServiceType(Core::ServiceType::SimulatedController); fromCopy.SetServiceName(controllerName); - + fromCopy.SetSupplementalDataItem(SilKit::Core::Discovery::controllerType, controllerTypeName); + targetController->SetServiceDescriptor(std::move(fromCopy)); _targetControllers.insert({controllerDescriptor, std::move(targetController)}); } diff --git a/SilKit/source/experimental/netsim/SimulatedNetworkRouter.hpp b/SilKit/source/experimental/netsim/SimulatedNetworkRouter.hpp index 8bc48113f..4aec310d1 100644 --- a/SilKit/source/experimental/netsim/SimulatedNetworkRouter.hpp +++ b/SilKit/source/experimental/netsim/SimulatedNetworkRouter.hpp @@ -93,6 +93,7 @@ class SimulatedNetworkRouter : public Core::ISimulator inline auto GetServiceDescriptor() const -> const Core::ServiceDescriptor& override; void AddSimulatedController(const std::string& fromParticipantName, const std::string& controllerName, + const std::string& controllerTypeName, Core::EndpointId serviceId, ControllerDescriptor controllerDescriptor, ISimulatedController* userSimulatedController); void RemoveSimulatedController(const std::string& fromParticipantName, Core::EndpointId serviceId, diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index b755e50d1..2f201b4a6 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -32,6 +32,11 @@ Fixed - If using the ``SimStepHandlerAsync``, the log message that reports the end of the simulation step is now printed after the call to ``CompleteSimulationStep``. +Fixed +~~~~~ + +- Fixed an issue with the NetSim API that caused an exception when used with log level `trace`. + [4.0.52] - 2024-09-02 ---------------------