From 723ae393979c7642edb959aa3069f923f05ccb6d Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Mon, 10 Feb 2025 15:54:09 +0100 Subject: [PATCH] Support interfaces for RPC generated code (#5622) * Refs #22722. Add RpcException class. Signed-off-by: Miguel Company * Refs #22722. Add RpcTimeoutException class. Signed-off-by: Miguel Company * Refs #22722. Add RpcBrokenPipeException class. * Refs #22722. Add RpcOperationError class. Signed-off-by: Miguel Company * Refs #22722. Add utility include for exceptions. Signed-off-by: Miguel Company * Refs #22722. Add RpcServerReader template interface. Signed-off-by: Miguel Company * Refs #22722. Add RpcClientReader template interface. Signed-off-by: Miguel Company * Refs #22722. Add RpcServerWriter template interface. Signed-off-by: Miguel Company * Refs #22722. Add RpcClientWriter template interface. Signed-off-by: Miguel Company * Refs #22722. Add RpcInputFeedCancelledException. Signed-off-by: Miguel Company * Refs #22722. Add RpcFuture template. Signed-off-by: Miguel Company * Refs #22722. Rename `RpcInputFeedCancelledException` -> `RpcFeedCancelledException` Signed-off-by: Miguel Company * Refs #22722. `RpcServerWriter` operations can throw `RpcFeedCancelledException` Signed-off-by: Miguel Company * Refs #22722. Improve documentation of `RpcClientReader` Signed-off-by: Miguel Company * Refs #22722. Improve documentation of `RpcClientWriter` Signed-off-by: Miguel Company * Refs #22722. Avoid DSO export warning on Windows Signed-off-by: Miguel Company * Refs #22722. Add utility include for interfaces. Signed-off-by: Miguel Company * Refs #22722. Add missing argument on doxygen documentation. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company --- include/fastdds/dds/rpc/exceptions.hpp | 28 ++++++ .../rpc/exceptions/RpcBrokenPipeException.hpp | 71 ++++++++++++++ .../dds/rpc/exceptions/RpcException.hpp | 98 +++++++++++++++++++ .../exceptions/RpcFeedCancelledException.hpp | 74 ++++++++++++++ .../dds/rpc/exceptions/RpcOperationError.hpp | 82 ++++++++++++++++ .../rpc/exceptions/RpcTimeoutException.hpp | 70 +++++++++++++ include/fastdds/dds/rpc/interfaces.hpp | 29 ++++++ .../dds/rpc/interfaces/RpcClientReader.hpp | 93 ++++++++++++++++++ .../dds/rpc/interfaces/RpcClientWriter.hpp | 98 +++++++++++++++++++ .../fastdds/dds/rpc/interfaces/RpcFuture.hpp | 37 +++++++ .../dds/rpc/interfaces/RpcServerReader.hpp | 84 ++++++++++++++++ .../dds/rpc/interfaces/RpcServerWriter.hpp | 79 +++++++++++++++ .../dds/rpc/interfaces/RpcStatusCode.hpp | 44 +++++++++ 13 files changed, 887 insertions(+) create mode 100644 include/fastdds/dds/rpc/exceptions.hpp create mode 100644 include/fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp create mode 100644 include/fastdds/dds/rpc/exceptions/RpcException.hpp create mode 100644 include/fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp create mode 100644 include/fastdds/dds/rpc/exceptions/RpcOperationError.hpp create mode 100644 include/fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp create mode 100644 include/fastdds/dds/rpc/interfaces.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcClientReader.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcClientWriter.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcFuture.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcServerReader.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcServerWriter.hpp create mode 100644 include/fastdds/dds/rpc/interfaces/RpcStatusCode.hpp diff --git a/include/fastdds/dds/rpc/exceptions.hpp b/include/fastdds/dds/rpc/exceptions.hpp new file mode 100644 index 00000000000..4990c91a348 --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions.hpp @@ -0,0 +1,28 @@ +// Copyright 2025 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. + +/** + * @file exceptions.hpp + */ + +#ifndef FASTDDS_DDS_RPC__EXCEPTIONS_HPP +#define FASTDDS_DDS_RPC__EXCEPTIONS_HPP + +#include +#include +#include +#include +#include + +#endif // FASTDDS_DDS_RPC__EXCEPTIONS_HPP diff --git a/include/fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp b/include/fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp new file mode 100644 index 00000000000..6a7bb1e6f5a --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp @@ -0,0 +1,71 @@ +// Copyright 2025 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. + +/** + * @file RpcBrokenPipeException.hpp + */ + +#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP +#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Exception thrown by the RPC API when the communication with the remote endpoint breaks. + */ +class FASTDDS_EXPORTED_API RpcBrokenPipeException : public RpcException +{ + +public: + + /** + * Constructor. + */ + RpcBrokenPipeException( + bool local_is_server) + : RpcException(local_is_server ? "Communication lost with the client" : "Communication lost with the server") + { + } + + /** + * Copy constructor. + */ + RpcBrokenPipeException( + const RpcBrokenPipeException& other) noexcept = default; + + /** + * Copy assignment. + */ + RpcBrokenPipeException& operator =( + const RpcBrokenPipeException& other) noexcept = default; + + /** + * Destructor. + */ + virtual ~RpcBrokenPipeException() noexcept = default; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCBROKENPIPEEXCEPTION_HPP diff --git a/include/fastdds/dds/rpc/exceptions/RpcException.hpp b/include/fastdds/dds/rpc/exceptions/RpcException.hpp new file mode 100644 index 00000000000..6cebe56a072 --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions/RpcException.hpp @@ -0,0 +1,98 @@ +// Copyright 2025 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. + +/** + * @file RpcException.hpp + */ + +#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP +#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP + +#include +#include + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Base class for all exceptions thrown by the RPC API. + */ +class FASTDDS_EXPORTED_API RpcException +{ + +public: + + /** + * Constructor. + * + * @param message The exception message. + */ + explicit RpcException( + const std::string& message) + : logic_error_(message) + { + } + + /** + * Constructor. + * + * @param message The exception message. + */ + explicit RpcException( + const char* message) + : logic_error_(message) + { + } + + /** + * Copy constructor. + */ + RpcException( + const RpcException& other) noexcept = default; + + /** + * Copy assignment. + */ + RpcException& operator =( + const RpcException& other) noexcept = default; + + /** + * Destructor. + */ + virtual ~RpcException() noexcept = default; + + /** + * Returns the explanatory string. + */ + const char* what() const noexcept + { + return logic_error_.what(); + } + +private: + + std::logic_error logic_error_; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCEXCEPTION_HPP diff --git a/include/fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp b/include/fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp new file mode 100644 index 00000000000..0fd704279a8 --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp @@ -0,0 +1,74 @@ +// Copyright 2025 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. + +/** + * @file RpcFeedCancelledException.hpp + */ + +#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP +#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP + +#include + +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Exception thrown by the RPC API when the client cancels an input feed. + */ +class FASTDDS_EXPORTED_API RpcFeedCancelledException : public RpcException +{ + +public: + + /** + * Constructor. + */ + RpcFeedCancelledException( + RpcStatusCode reason) + : RpcException("Input feed cancelled with reason '" + std::to_string(reason) + "'") + { + } + + /** + * Copy constructor. + */ + RpcFeedCancelledException( + const RpcFeedCancelledException& other) noexcept = default; + + /** + * Copy assignment. + */ + RpcFeedCancelledException& operator =( + const RpcFeedCancelledException& other) noexcept = default; + + /** + * Destructor. + */ + virtual ~RpcFeedCancelledException() noexcept = default; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCINPUTFEEDCANCELLEDEXCEPTION_HPP diff --git a/include/fastdds/dds/rpc/exceptions/RpcOperationError.hpp b/include/fastdds/dds/rpc/exceptions/RpcOperationError.hpp new file mode 100644 index 00000000000..36db18524c7 --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions/RpcOperationError.hpp @@ -0,0 +1,82 @@ +// Copyright 2025 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. + +/** + * @file RpcOperationError.hpp + */ + +#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP +#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP + +#include + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Base class for exceptions thrown by the RPC API when the server communicates an error. + */ +class FASTDDS_EXPORTED_API RpcOperationError : public RpcException +{ + +public: + + /** + * Constructor. + */ + RpcOperationError( + const std::string& message) + : RpcException(message) + { + } + + /** + * Constructor. + */ + RpcOperationError( + const char* message) + : RpcException(message) + { + } + + /** + * Copy constructor. + */ + RpcOperationError( + const RpcOperationError& other) noexcept = default; + + /** + * Copy assignment. + */ + RpcOperationError& operator =( + const RpcOperationError& other) noexcept = default; + + /** + * Destructor. + */ + virtual ~RpcOperationError() noexcept = default; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCOPERATIONERROR_HPP diff --git a/include/fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp b/include/fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp new file mode 100644 index 00000000000..6fdc49f9285 --- /dev/null +++ b/include/fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp @@ -0,0 +1,70 @@ +// Copyright 2025 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. + +/** + * @file RpcTimeoutException.hpp + */ + +#ifndef FASTDDS_DDS_RPC_EXCEPTIONS__RPCTIMEOUTEXCEPTION_HPP +#define FASTDDS_DDS_RPC_EXCEPTIONS__RPCTIMEOUTEXCEPTION_HPP + +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Exception thrown by the RPC API when an operation times out. + */ +class FASTDDS_EXPORTED_API RpcTimeoutException : public RpcException +{ + +public: + + /** + * Constructor. + */ + RpcTimeoutException() + : RpcException("The RPC operation timed out") + { + } + + /** + * Copy constructor. + */ + RpcTimeoutException( + const RpcTimeoutException& other) noexcept = default; + + /** + * Copy assignment. + */ + RpcTimeoutException& operator =( + const RpcTimeoutException& other) noexcept = default; + + /** + * Destructor. + */ + virtual ~RpcTimeoutException() noexcept = default; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_EXCEPTIONS__RPCTIMEOUTEXCEPTION_HPP diff --git a/include/fastdds/dds/rpc/interfaces.hpp b/include/fastdds/dds/rpc/interfaces.hpp new file mode 100644 index 00000000000..b6e0a69aa4a --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces.hpp @@ -0,0 +1,29 @@ +// Copyright 2025 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. + +/** + * @file interfaces.hpp + */ + +#ifndef FASTDDS_DDS_RPC__INTERFACES_HPP +#define FASTDDS_DDS_RPC__INTERFACES_HPP + +#include +#include +#include +#include +#include +#include + +#endif // FASTDDS_DDS_RPC__INTERFACES_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcClientReader.hpp b/include/fastdds/dds/rpc/interfaces/RpcClientReader.hpp new file mode 100644 index 00000000000..06b272080de --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcClientReader.hpp @@ -0,0 +1,93 @@ +// Copyright 2025 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. + +/** + * @file RpcClientReader.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTREADER_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTREADER_HPP + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * An interface for a client-side RPC reader. + * + * Would be used to read replies from a server on an operation with a `@feed` annotated return type. + */ +template +class RpcClientReader +{ +public: + + /** + * Destructor. + */ + virtual ~RpcClientReader() = default; + + /** + * Blocking read operation. + * + * Will block until a reply is available or the replies feed has finished. + * + * @param value The value to read the reply into. + * + * @return True if a reply was read, false if the feed has finished or has been cancelled. + * + * @throw RpcOperationError if the server communicates an error. + * @throw RpcBrokenPipeException if the communication with the server breaks. + */ + virtual bool read( + T& value) = 0; + + /** + * Blocking read operation with timeout. + * + * Will block until a reply is available, the replies feed has finished, or the timeout expires. + * + * @param value The value to read the reply into. + * @param timeout The maximum time to wait for a reply. + * + * @return True if a reply was read, false if the feed has finished or has been cancelled. + * + * @throw RpcOperationError if the server communicates an error. + * @throw RpcBrokenPipeException if the communication with the server breaks. + * @throw RpcTimeoutException if the timeout expires. + */ + virtual bool read( + T& value, + const eprosima::fastdds::dds::Duration_t& timeout) = 0; + + /** + * Cancel the replies feed. + * + * Will tell the server to stop sending replies, and block until the server acknowledges the cancellation. + * The replies feed would then be finished locally, so all pending read operations will return false. + * + * @throw RpcBrokenPipeException if the communication with the server breaks. + */ + virtual void cancel() = 0; +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTREADER_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcClientWriter.hpp b/include/fastdds/dds/rpc/interfaces/RpcClientWriter.hpp new file mode 100644 index 00000000000..111436c1dfa --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcClientWriter.hpp @@ -0,0 +1,98 @@ +// Copyright 2025 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. + +/** + * @file RpcClientWriter.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTWRITER_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTWRITER_HPP + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * An interface for a client-side RPC writer. + * + * Would be used to write inputs from a client on an operation with `@feed` annotated inputs. + */ +template +class RpcClientWriter +{ +public: + + /** + * Destructor. + */ + virtual ~RpcClientWriter() noexcept = default; + + /** + * Copy write operation. + * + * Will add a value to the input feed, that would be eventually sent to the server. + * May block depending on the configured queue sizes in both the client and the server. + * + * @param value The value to write to the input feed. + * + * @throw RpcBrokenPipeException if the communication with the server breaks. + * @throw RpcTimeoutException if the operation needs to block for a time longer than the configured timeout. + * @throw RpcOperationError if the server communicates an error. + */ + virtual void write( + const T& value) = 0; + + /** + * Move write operation. + * + * Will add a value to the input feed, that would be eventually sent to the server. + * May block depending on the configured queue sizes in both the client and the server. + * + * @param value The value to write to the input feed. + * + * @throw RpcBrokenPipeException if the communication with the server breaks. + * @throw RpcTimeoutException if the operation needs to block for a time longer than the configured timeout. + * @throw RpcOperationError if the server communicates an error. + */ + virtual void write( + T&& value) = 0; + + /** + * Marks the end of the input feed. + * + * Will indicate to the server that no more inputs will be sent. + * Specifying a reason different from `RPC_STATUS_CODE_OK` will indicate that the feed was finished due to an + * error, and that the client will not be expecting a reply. + * + * May block depending on the configured queue sizes in both the client and the server. + * + * @param reason The status code to indicate the reason for finishing the feed. + * + * @throw RpcBrokenPipeException if the communication with the server breaks. + * @throw RpcTimeoutException if the operation needs to block for a time longer than the configured timeout. + */ + virtual void finish( + RpcStatusCode reason = RPC_STATUS_CODE_OK) = 0; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCCLIENTWRITER_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcFuture.hpp b/include/fastdds/dds/rpc/interfaces/RpcFuture.hpp new file mode 100644 index 00000000000..f07982d9cad --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcFuture.hpp @@ -0,0 +1,37 @@ +// Copyright 2025 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. + +/** + * @file RpcFuture.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCFUTURE_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCFUTURE_HPP + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +template +using RpcFuture = std::future; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCFUTURE_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcServerReader.hpp b/include/fastdds/dds/rpc/interfaces/RpcServerReader.hpp new file mode 100644 index 00000000000..8683abca93a --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcServerReader.hpp @@ -0,0 +1,84 @@ +// Copyright 2025 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. + +/** + * @file RpcServerReader.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCSERVERREADER_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCSERVERREADER_HPP + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * An interface for a server-side RPC reader. + * + * Would be used to read inputs from a client on an operation with `@feed` annotated inputs. + */ +template +class RpcServerReader +{ +public: + + /** + * Destructor. + */ + virtual ~RpcServerReader() noexcept = default; + + /** + * Blocking read operation. + * + * Will block until an input is available or the input feed has finished. + * + * @param value The value to read the input into. + * + * @return True if a value was read, false if the feed has finished. + * + * @throw RpcBrokenPipeException if the communication with the client breaks. + * @throw RpcFeedCancelledException if the client cancels the input feed. + */ + virtual bool read( + T& value) = 0; + + /** + * Blocking read operation with timeout. + * + * Will block until an input is available, the input feed has finished, or the timeout expires. + * + * @param value The value to read the input into. + * @param timeout The maximum time to wait for an input. + * + * @return True if a value was read, false if the feed has finished. + * + * @throw RpcTimeoutException if the timeout expires. + * @throw RpcBrokenPipeException if the communication with the client breaks. + * @throw RpcFeedCancelledException if the client cancels the input feed. + */ + virtual bool read( + T& value, + const eprosima::fastdds::dds::Duration_t& timeout) = 0; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCSERVERREADER_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcServerWriter.hpp b/include/fastdds/dds/rpc/interfaces/RpcServerWriter.hpp new file mode 100644 index 00000000000..094fa3ba7c7 --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcServerWriter.hpp @@ -0,0 +1,79 @@ +// Copyright 2025 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. + +/** + * @file RpcServerWriter.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCSERVERWRITER_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCSERVERWRITER_HPP + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * An interface for a server-side RPC writer. + * + * Would be used to write replies from a server on an operation with a `@feed` annotated return type. + */ +template +class RpcServerWriter +{ +public: + + /** + * Destructor. + */ + virtual ~RpcServerWriter() noexcept = default; + + /** + * Copy write operation. + * + * Will add a value to the replies feed, that would be eventually sent to the client. + * May block depending on the configured queue sizes in both the client and the server. + * + * @param value The value to write to the replies feed. + * + * @throw RpcBrokenPipeException if the communication with the client breaks. + * @throw RpcTimeoutException if the operation needs to block for a time longer than the configured timeout. + * @throw RpcFeedCancelledException if the client cancels the output feed. + */ + virtual void write( + const T& value) = 0; + + /** + * Move write operation. + * + * Will add a value to the replies feed, that would be eventually sent to the client. + * May block depending on the configured queue sizes in both the client and the server. + * + * @param value The value to write to the replies feed. + * + * @throw RpcBrokenPipeException if the communication with the client breaks. + * @throw RpcTimeoutException if the operation needs to block for a time longer than the configured timeout. + * @throw RpcFeedCancelledException if the client cancels the output feed. + */ + virtual void write( + T&& value) = 0; + +}; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCSERVERWRITER_HPP diff --git a/include/fastdds/dds/rpc/interfaces/RpcStatusCode.hpp b/include/fastdds/dds/rpc/interfaces/RpcStatusCode.hpp new file mode 100644 index 00000000000..3fac3ea011d --- /dev/null +++ b/include/fastdds/dds/rpc/interfaces/RpcStatusCode.hpp @@ -0,0 +1,44 @@ +// Copyright 2025 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. + +/** + * @file RpcStatusCode.hpp + */ + +#ifndef FASTDDS_DDS_RPC_INTERFACES__RPCSTATUSCODE_HPP +#define FASTDDS_DDS_RPC_INTERFACES__RPCSTATUSCODE_HPP + +#include + +namespace eprosima { +namespace fastdds { +namespace dds { +namespace rpc { + +/** + * Status codes for RPC operations. + */ +using RpcStatusCode = uint32_t; + +/** + * Status code for successful operations. + */ +constexpr RpcStatusCode RPC_STATUS_OK = 0; + +} // namespace rpc +} // namespace dds +} // namespace fastdds +} // namespace eprosima + +#endif // FASTDDS_DDS_RPC_INTERFACES__RPCSTATUSCODE_HPP