Skip to content

Commit

Permalink
dev: Add missing controllerType in ServiceDescriptor of SimulatedCont…
Browse files Browse the repository at this point in the history
…roller (#128)

* dev: Add missing controllerType in ServiceDescriptor of SimulatedController

* dev: Update Changelog
  • Loading branch information
KonradBkd authored Oct 11, 2024
1 parent f132f96 commit b91044f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion SilKit/source/core/internal/ServiceDescriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 15 additions & 2 deletions SilKit/source/experimental/netsim/SimulatedNetworkInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "eventproducers/FlexRayEventProducer.hpp"
#include "eventproducers/EthernetEventProducer.hpp"
#include "eventproducers/LinEventProducer.hpp"
#include "ServiceConfigKeys.hpp"

namespace SilKit {
namespace Experimental {
Expand Down Expand Up @@ -57,21 +58,33 @@ 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;

auto userSimulatedController = _userSimulatedNetwork->ProvideSimulatedController(controllerDescriptor);

if (userSimulatedController)
{
_simulatedNetworkRouter->AddSimulatedController(fromParticipantName, controllerName, serviceId,
std::string controllerTypeName = ExtractControllerTypeName(serviceDescriptor);
_simulatedNetworkRouter->AddSimulatedController(fromParticipantName, controllerName,
controllerTypeName, serviceId,
controllerDescriptor, userSimulatedController);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class SimulatedNetworkInternal
Core::EndpointId serviceId) -> std::pair<bool, ControllerDescriptor>;
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;

Expand Down
7 changes: 5 additions & 2 deletions SilKit/source/experimental/netsim/SimulatedNetworkRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "NetworkSimulatorDatatypesInternal.hpp"
#include "Configuration.hpp"
#include "silkit/experimental/netsim/string_utils.hpp"
#include "ServiceConfigKeys.hpp"

namespace SilKit {
namespace Experimental {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------

Expand Down

0 comments on commit b91044f

Please sign in to comment.