From f6b6f419ace061c81abaf1a0d281a41506f82f49 Mon Sep 17 00:00:00 2001 From: jparisu Date: Thu, 29 Jun 2023 08:41:27 +0200 Subject: [PATCH] Another idea to implement RPC based in more specific interfaces Signed-off-by: jparisu --- .../ddspipe_core/interface/IClient.hpp | 82 +++++++++++++++++++ .../ddspipe_core/interface/IParticipant.hpp | 15 ++-- .../ddspipe_core/interface/IReader.hpp | 23 ------ .../ddspipe_core/interface/IRpcTopic.hpp | 36 ++++++++ .../ddspipe_core/interface/IServer.hpp | 82 +++++++++++++++++++ 5 files changed, 210 insertions(+), 28 deletions(-) create mode 100644 ddspipe_core/include/ddspipe_core/interface/IClient.hpp create mode 100644 ddspipe_core/include/ddspipe_core/interface/IRpcTopic.hpp create mode 100644 ddspipe_core/include/ddspipe_core/interface/IServer.hpp diff --git a/ddspipe_core/include/ddspipe_core/interface/IClient.hpp b/ddspipe_core/include/ddspipe_core/interface/IClient.hpp new file mode 100644 index 00000000..641e1c04 --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/interface/IClient.hpp @@ -0,0 +1,82 @@ +// Copyright 2021 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 + +namespace eprosima { +namespace ddspipe { +namespace core { + +/** + * Interface that represents a generic Writer as part of a DdsPipe. + * + * This class manages the sending of data to remote endpoints in a specific topic. + * + * @note In order to implement new Writers, create a subclass of this Interface and implement every method. + * @note Also it is needed to add the creation of the Writer in the Participant required. + * + * Writers will start being disabled. + */ +class IClient +{ +public: + + /** + * @brief Virtual dtor to allow inheritance. + */ + DDSPIPE_CORE_DllAPI + virtual ~IClient() = default; + + /** + * @brief Enable Writer + * + * A Writer enabled can send messages. + * + * By default the Writer is disabled. Call this method to activate it. + */ + DDSPIPE_CORE_DllAPI + virtual void enable() noexcept = 0; + + /** + * @brief Disable Writer + * + * A Writer disabled does not send data. + * @note Method \c write should never be called from a disabled writer + */ + DDSPIPE_CORE_DllAPI + virtual void disable() noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual utils::ReturnCode send_request( + IRoutingData& data) noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual void set_on_reply_callback( + std::function on_reply_lambda) noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual void unset_on_reply_callback() noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual utils::ReturnCode take( + std::unique_ptr& data) noexcept = 0; +}; + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp index 6e5a5b39..e846476a 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IParticipant.hpp @@ -17,7 +17,8 @@ #include #include #include -#include +#include +#include namespace eprosima { namespace ddspipe { @@ -51,10 +52,6 @@ class IParticipant DDSPIPE_CORE_DllAPI virtual types::ParticipantId id() const noexcept = 0; - //! Whether this participant is RTPS - DDSPIPE_CORE_DllAPI - virtual bool is_rtps_kind() const noexcept = 0; - /** * @brief Whether this Participant requires to connect ist own readers with its own writers. */ @@ -92,6 +89,14 @@ class IParticipant DDSPIPE_CORE_DllAPI virtual std::shared_ptr create_reader( const ITopic& topic) = 0; + + DDSPIPE_CORE_DllAPI + virtual std::shared_ptr create_client( + const IRpcTopic& topic) = 0; + + DDSPIPE_CORE_DllAPI + virtual std::shared_ptr create_server( + const IRpcTopic& topic) = 0; }; } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp index 71153ef9..b1a79413 100644 --- a/ddspipe_core/include/ddspipe_core/interface/IReader.hpp +++ b/ddspipe_core/include/ddspipe_core/interface/IReader.hpp @@ -110,29 +110,6 @@ class IReader virtual utils::ReturnCode take( std::unique_ptr& data) noexcept = 0; - ///////////////////////// - // RPC REQUIRED METHODS - ///////////////////////// - // TODO remove these methods once the double reference is solved - - //! Get GUID of internal RTPS reader - DDSPIPE_CORE_DllAPI - virtual core::types::Guid guid() const = 0; - - //! Get internal RTPS reader mutex - DDSPIPE_CORE_DllAPI - virtual fastrtps::RecursiveTimedMutex& get_rtps_mutex() const = 0; - - //! Get number of unread cache changes in internal RTPS reader - DDSPIPE_CORE_DllAPI - virtual uint64_t get_unread_count() const = 0; - - DDSPIPE_CORE_DllAPI - virtual types::DdsTopic topic() const = 0; - - DDSPIPE_CORE_DllAPI - virtual types::ParticipantId participant_id() const = 0; - ///////////////////////// }; } /* namespace core */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IRpcTopic.hpp b/ddspipe_core/include/ddspipe_core/interface/IRpcTopic.hpp new file mode 100644 index 00000000..01bdb7c9 --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/interface/IRpcTopic.hpp @@ -0,0 +1,36 @@ +// Copyright 2021 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 +#include + +namespace eprosima { +namespace ddspipe { +namespace core { + +/** + * Generic data struct that represents an ITopic of data flow in the Router. + */ +class IRpcTopic : public ITopic +{ +}; + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */ diff --git a/ddspipe_core/include/ddspipe_core/interface/IServer.hpp b/ddspipe_core/include/ddspipe_core/interface/IServer.hpp new file mode 100644 index 00000000..23b3db5a --- /dev/null +++ b/ddspipe_core/include/ddspipe_core/interface/IServer.hpp @@ -0,0 +1,82 @@ +// Copyright 2021 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 + +namespace eprosima { +namespace ddspipe { +namespace core { + +/** + * Interface that represents a generic Writer as part of a DdsPipe. + * + * This class manages the sending of data to remote endpoints in a specific topic. + * + * @note In order to implement new Writers, create a subclass of this Interface and implement every method. + * @note Also it is needed to add the creation of the Writer in the Participant required. + * + * Writers will start being disabled. + */ +class IServer +{ +public: + + /** + * @brief Virtual dtor to allow inheritance. + */ + DDSPIPE_CORE_DllAPI + virtual ~IServer() = default; + + /** + * @brief Enable Writer + * + * A Writer enabled can send messages. + * + * By default the Writer is disabled. Call this method to activate it. + */ + DDSPIPE_CORE_DllAPI + virtual void enable() noexcept = 0; + + /** + * @brief Disable Writer + * + * A Writer disabled does not send data. + * @note Method \c write should never be called from a disabled writer + */ + DDSPIPE_CORE_DllAPI + virtual void disable() noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual utils::ReturnCode send_reply( + IRoutingData& data) noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual void set_on_request_callback( + std::function on_request_lambda) noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual void unset_on_request_callback() noexcept = 0; + + DDSPIPE_CORE_DllAPI + virtual utils::ReturnCode take( + std::unique_ptr& data) noexcept = 0; +}; + +} /* namespace core */ +} /* namespace ddspipe */ +} /* namespace eprosima */