From 52ec5d8ed535c136e5bbcb40442baa43f9b98803 Mon Sep 17 00:00:00 2001 From: VeithMetro Date: Tue, 8 Oct 2024 11:48:32 +0200 Subject: [PATCH 1/6] Make sure to only open a channel if the network subsystem is already active --- MessageControl/MessageControl.cpp | 2 +- MessageControl/MessageOutput.cpp | 46 +++++++++++++++++++++++--- MessageControl/MessageOutput.h | 55 +++++++++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 8 deletions(-) diff --git a/MessageControl/MessageControl.cpp b/MessageControl/MessageControl.cpp index 02774b3..0f0cf43 100644 --- a/MessageControl/MessageControl.cpp +++ b/MessageControl/MessageControl.cpp @@ -114,7 +114,7 @@ namespace Thunder { Announce(new Publishers::FileOutput(abbreviate, _config.FileName.Value())); } if ((_config.Remote.Binding.Value().empty() == false) && (_config.Remote.Port.Value() != 0)) { - Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()))); + Announce(new Publishers::UDPOutput(abbreviate, Core::NodeId(_config.Remote.NodeId()), _service)); } _webSocketExporter.Initialize(service, _config.MaxExportConnections.Value()); diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index 8cf00a0..ede2bac 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -116,8 +116,11 @@ namespace Publishers { { ::memset(_sendBuffer, 0, sizeof(_sendBuffer)); } - UDPOutput::Channel::~Channel() { - Close(Core::infinite); + UDPOutput::Channel::~Channel() + { + if (IsOpen() == true) { + Close(Core::infinite); + } } uint16_t UDPOutput::Channel::SendData(uint8_t* dataFrame, const uint16_t maxSendSize) @@ -160,16 +163,49 @@ namespace Publishers { Trigger(); } - UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId) + UDPOutput::UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service) : _convertor(abbreviate) , _output(nodeId) + , _notification(*this) + , _subSystem(service->SubSystems()) + { + ASSERT(_subSystem != nullptr); + + if (_subSystem != nullptr) { + _subSystem->AddRef(); + _subSystem->Register(&_notification); + + if (_subSystem->IsActive(PluginHost::ISubSystem::NETWORK)) { + OpenUDPOutputChannel(); + } + } + } + + PluginHost::ISubSystem* UDPOutput::SubSystem() const { - _output.Open(0); + return (_subSystem); + } + + void UDPOutput::OpenUDPOutputChannel() + { + if (_output.IsOpen() == false) { + _output.Open(0); + } + ASSERT(_output.IsOpen() == true); + } + + void UDPOutput::CloseUDPOutputChannel() + { + if (_output.IsOpen() == true) { + _output.Close(Core::infinite); + } } void UDPOutput::Message(const Core::Messaging::MessageInfo& metadata, const string& text) /* override */ { - _output.Output(_convertor.Convert(metadata, text)); + if (_output.IsOpen() == true) { + _output.Output(_convertor.Convert(metadata, text)); + } } } // namespace Publishers diff --git a/MessageControl/MessageOutput.h b/MessageControl/MessageOutput.h index b414f8d..0cc72dc 100644 --- a/MessageControl/MessageOutput.h +++ b/MessageControl/MessageOutput.h @@ -333,19 +333,70 @@ namespace Publishers { Core::CriticalSection _adminLock; }; + class Notification : public PluginHost::ISubSystem::INotification, public RPC::IRemoteConnection::INotification { + public: + Notification() = delete; + Notification(const Notification&) = delete; + Notification& operator=(const Notification&) = delete; + + explicit Notification(UDPOutput& parent) + : _parent(parent) { + } + ~Notification() = default; + + public: + void Updated() override + { + if (_parent.SubSystem()->IsActive(PluginHost::ISubSystem::NETWORK)) { + _parent.OpenUDPOutputChannel(); + } + else { + _parent.CloseUDPOutputChannel(); + } + } + void Activated(RPC::IRemoteConnection* /* connection */) override { + } + void Deactivated(RPC::IRemoteConnection* /* connection */) override { + } + void Terminated(RPC::IRemoteConnection* /* connection */) override { + } + + BEGIN_INTERFACE_MAP(Notification) + INTERFACE_ENTRY(PluginHost::ISubSystem::INotification) + INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) + END_INTERFACE_MAP + + private: + UDPOutput& _parent; + }; + public: UDPOutput() = delete; UDPOutput(const UDPOutput&) = delete; UDPOutput& operator=(const UDPOutput&) = delete; - explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId); - ~UDPOutput() = default; + explicit UDPOutput(const Core::Messaging::MessageInfo::abbreviate abbreviate, const Core::NodeId& nodeId, PluginHost::IShell* service); + + ~UDPOutput() override + { + if (_subSystem != nullptr) { + _subSystem->Unregister(&_notification); + _subSystem->Release(); + _subSystem = nullptr; + } + } + + PluginHost::ISubSystem* SubSystem() const; + void OpenUDPOutputChannel(); + void CloseUDPOutputChannel(); void Message(const Core::Messaging::MessageInfo& metadata, const string& text); private: Text _convertor; Channel _output; + Core::SinkType _notification; + PluginHost::ISubSystem* _subSystem; }; class WebSocketOutput : public IPublish { From 06ea8990dab728a0c64bbed718b29bdb27fda591 Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:36:56 +0200 Subject: [PATCH 2/6] Delete move constructor and operator --- MessageControl/MessageOutput.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/MessageControl/MessageOutput.h b/MessageControl/MessageOutput.h index 0cc72dc..7bf59c3 100644 --- a/MessageControl/MessageOutput.h +++ b/MessageControl/MessageOutput.h @@ -333,11 +333,13 @@ namespace Publishers { Core::CriticalSection _adminLock; }; - class Notification : public PluginHost::ISubSystem::INotification, public RPC::IRemoteConnection::INotification { + class Notification : public PluginHost::ISubSystem::INotification { public: Notification() = delete; Notification(const Notification&) = delete; + Notification(Notification&&) = delete; Notification& operator=(const Notification&) = delete; + Notification& operator=(Notification&&) = delete; explicit Notification(UDPOutput& parent) : _parent(parent) { @@ -354,16 +356,9 @@ namespace Publishers { _parent.CloseUDPOutputChannel(); } } - void Activated(RPC::IRemoteConnection* /* connection */) override { - } - void Deactivated(RPC::IRemoteConnection* /* connection */) override { - } - void Terminated(RPC::IRemoteConnection* /* connection */) override { - } BEGIN_INTERFACE_MAP(Notification) INTERFACE_ENTRY(PluginHost::ISubSystem::INotification) - INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) END_INTERFACE_MAP private: From 197dcf7207156cdc99bcadbb8356e5b4ef010d0d Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:38:55 +0200 Subject: [PATCH 3/6] Updated is called automatically after Register --- MessageControl/MessageOutput.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index ede2bac..932a241 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -174,10 +174,6 @@ namespace Publishers { if (_subSystem != nullptr) { _subSystem->AddRef(); _subSystem->Register(&_notification); - - if (_subSystem->IsActive(PluginHost::ISubSystem::NETWORK)) { - OpenUDPOutputChannel(); - } } } From 88db24190a062e1548d5e7124ecae6cd0e4b09bb Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:10:36 +0200 Subject: [PATCH 4/6] Add a new method UpdateChannel and call it in the Notification --- MessageControl/MessageOutput.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/MessageControl/MessageOutput.h b/MessageControl/MessageOutput.h index 7bf59c3..2e80f52 100644 --- a/MessageControl/MessageOutput.h +++ b/MessageControl/MessageOutput.h @@ -349,12 +349,7 @@ namespace Publishers { public: void Updated() override { - if (_parent.SubSystem()->IsActive(PluginHost::ISubSystem::NETWORK)) { - _parent.OpenUDPOutputChannel(); - } - else { - _parent.CloseUDPOutputChannel(); - } + _parent.UpdateChannel(); } BEGIN_INTERFACE_MAP(Notification) @@ -381,10 +376,7 @@ namespace Publishers { } } - PluginHost::ISubSystem* SubSystem() const; - void OpenUDPOutputChannel(); - void CloseUDPOutputChannel(); - + void UpdateChannel(); void Message(const Core::Messaging::MessageInfo& metadata, const string& text); private: From 96887307c59ac7d6b2c3ed40684cd40ae3a0d936 Mon Sep 17 00:00:00 2001 From: Mateusz Daniluk <121170681+VeithMetro@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:13:00 +0200 Subject: [PATCH 5/6] Add an implementation of UpdateChannel --- MessageControl/MessageOutput.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index 932a241..bd6d14e 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -177,23 +177,18 @@ namespace Publishers { } } - PluginHost::ISubSystem* UDPOutput::SubSystem() const + void UDPOutput::UpdateChannel() { - return (_subSystem); - } - - void UDPOutput::OpenUDPOutputChannel() - { - if (_output.IsOpen() == false) { - _output.Open(0); + if (_subSystem->IsActive(PluginHost::ISubSystem::NETWORK)) { + if (_output.IsOpen() == false) { + _output.Open(0); + } + ASSERT(_output.IsOpen() == true); } - ASSERT(_output.IsOpen() == true); - } - - void UDPOutput::CloseUDPOutputChannel() - { - if (_output.IsOpen() == true) { - _output.Close(Core::infinite); + else { + if (_output.IsOpen() == true) { + _output.Close(Core::infinite); + } } } From 58925dade99d9448d5004da2c00dbdae4acd4d0a Mon Sep 17 00:00:00 2001 From: VeithMetro Date: Thu, 24 Oct 2024 14:34:52 +0200 Subject: [PATCH 6/6] Remove unnecessary check whether the channel is open before closing --- MessageControl/MessageOutput.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/MessageControl/MessageOutput.cpp b/MessageControl/MessageOutput.cpp index bd6d14e..0b153fc 100644 --- a/MessageControl/MessageOutput.cpp +++ b/MessageControl/MessageOutput.cpp @@ -118,9 +118,7 @@ namespace Publishers { } UDPOutput::Channel::~Channel() { - if (IsOpen() == true) { - Close(Core::infinite); - } + Close(Core::infinite); } uint16_t UDPOutput::Channel::SendData(uint8_t* dataFrame, const uint16_t maxSendSize) @@ -186,9 +184,7 @@ namespace Publishers { ASSERT(_output.IsOpen() == true); } else { - if (_output.IsOpen() == true) { - _output.Close(Core::infinite); - } + _output.Close(Core::infinite); } }