From fc5e554a87380930c3a196b91cad4aa3aa0fe8f8 Mon Sep 17 00:00:00 2001 From: Juan Lopez Fernandez Date: Thu, 19 Dec 2024 11:42:20 +0100 Subject: [PATCH] Add auxiliar InternalWriter Signed-off-by: Juan Lopez Fernandez --- .../reader/auxiliar/InternalReader.hpp | 1 + .../writer/auxiliar/InternalWriter.hpp | 48 +++++++++++++++++++ .../cpp/writer/auxiliar/InternalWriter.cpp | 38 +++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 ddspipe_participants/include/ddspipe_participants/writer/auxiliar/InternalWriter.hpp create mode 100644 ddspipe_participants/src/cpp/writer/auxiliar/InternalWriter.cpp diff --git a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/InternalReader.hpp b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/InternalReader.hpp index eae4791c..3d947d94 100644 --- a/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/InternalReader.hpp +++ b/ddspipe_participants/include/ddspipe_participants/reader/auxiliar/InternalReader.hpp @@ -26,6 +26,7 @@ #include #include +#include #include namespace eprosima { diff --git a/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/InternalWriter.hpp b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/InternalWriter.hpp new file mode 100644 index 00000000..cef7d113 --- /dev/null +++ b/ddspipe_participants/include/ddspipe_participants/writer/auxiliar/InternalWriter.hpp @@ -0,0 +1,48 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { + +/** + * Writer implementation that allow to register a callback to be executed with each data received. + */ +class InternalWriter : public BaseWriter +{ +public: + + DDSPIPE_PARTICIPANTS_DllAPI + InternalWriter( + const core::types::ParticipantId& participant_id, + const std::function& callback); + +protected: + + virtual utils::ReturnCode write_nts_( + core::IRoutingData& data) noexcept override; + + const std::function callback_; +}; + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_participants/src/cpp/writer/auxiliar/InternalWriter.cpp b/ddspipe_participants/src/cpp/writer/auxiliar/InternalWriter.cpp new file mode 100644 index 00000000..2e97e60e --- /dev/null +++ b/ddspipe_participants/src/cpp/writer/auxiliar/InternalWriter.cpp @@ -0,0 +1,38 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +namespace eprosima { +namespace ddspipe { +namespace participants { + +InternalWriter::InternalWriter( + const core::types::ParticipantId& participant_id, + const std::function& callback) + : BaseWriter(participant_id) + , callback_(callback) +{ + // Do nothing +} + +utils::ReturnCode InternalWriter::write_nts_( + core::IRoutingData& data) noexcept +{ + return callback_(data); +} + +} /* namespace participants */ +} /* namespace ddspipe */ +} /* namespace eprosima */