diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 4714f46a..e26a7e97 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -32,6 +32,15 @@ $endif$ // If using windows in debug, it would try to use python_d, which would not be found. %begin %{ +$if(ctx.thereIsInterface)$ +/* + * From: https://github.com/swig/swig/issues/2638 + * When a module uses a type in a module that is defined in a different module, + * a false positive memory leak is detected. + * The following line silences this warning. + */ +#define SWIG_PYTHON_SILENT_MEMLEAK +$endif$ #ifdef _MSC_VER #define SWIG_PYTHON_INTERPRETER_NO_DEBUG #endif @@ -86,6 +95,7 @@ $endif$ $if(ctx.thereIsInterface)$ %import(module="fastdds") "fastdds/dds/rpc/exceptions/RpcException.hpp" %import(module="fastdds") "fastdds/dds/rpc/exceptions/RpcOperationError.hpp" +%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcServer.hpp" %exception { try @@ -386,17 +396,6 @@ $export_list$ %shared_ptr($interface.scopedname$); $if(!interface.annotatedAsNested)$ -%shared_ptr($interface.scopedname$Server); -%extend $interface.scopedname$Server -{ - void run() - { - Py_BEGIN_ALLOW_THREADS - self->run(); - Py_END_ALLOW_THREADS - } -} - %shared_ptr($interface.scopedname$Server_IServerImplementation); %shared_ptr($interface.scopedname$ServerImplementation); %feature("director") $interface.scopedname$ServerImplementation; diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/ServerHeader.stg b/src/main/java/com/eprosima/fastdds/idl/templates/ServerHeader.stg index 7020ed50..3b697920 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/ServerHeader.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/ServerHeader.stg @@ -51,28 +51,6 @@ $definition_list$ interface(ctx, parent, interface, export_list) ::= << $if(!interface.annotatedAsNested)$ -/** - * @brief Context for a client request. - */ -struct $interface.name$Server_ClientContext -{ - virtual ~$interface.name$Server_ClientContext() = default; - - /** - * @brief Get the GUID of the client that made the request. - * - * @return The GUID of the client that made the request. - */ - virtual const eprosima::fastdds::rtps::GUID_t& get_client_id() const = 0; - - /** - * @brief Get the locators of the client that made the request. - * - * @return The locators of the client that made the request. - */ - virtual const eprosima::fastdds::rtps::RemoteLocatorList& get_client_locators() const = 0; -}; - struct $interface.name$Server_IServerImplementation { virtual ~$interface.name$Server_IServerImplementation() = default; @@ -80,75 +58,8 @@ struct $interface.name$Server_IServerImplementation $interface.all_operations:{op | $operation_prototype(op)$}; separator="\n\n"$ }; -struct $interface.name$Server -{ - virtual ~$interface.name$Server() = default; - - /** - * @brief Run the server. - * - * This method starts the server and begins processing requests. - * The method will block until the server is stopped. - */ - virtual void run() = 0; - - /** - * @brief Stop the server. - * - * This method stops the server and releases all resources. - * It will cancel all pending requests, and then @c call server_stopped on the request scheduler to let - * it release any resources associated to this server. - * - * When the server has been created with the factory method that receives a @c thread_pool_size argument, - * it will wait for all threads in the pool to finish before returning. - */ - virtual void stop() = 0; - - /** - * @brief Perform execution of a client request. - * - * @param request The client request to execute. - */ - virtual void execute_request( - const std::shared_ptr<$interface.name$Server_ClientContext>& request) = 0; - -}; - -struct $interface.name$ServerSchedulingStrategy -{ - virtual ~$interface.name$ServerSchedulingStrategy() = default; - - /** - * @brief Schedule a request for processing. - * - * This method is called when a request is received and should be processed by the server. - * The implementation should decide how to handle the request, whether to process it immediately, - * or to queue it for later processing. - * - * A call to server->execute_request(request) should eventually be made to process the request. - * - * @note This method is called from the thread that takes requests and input feed values, so it - * should not directly execute the request for operations that have input feed parameters. - * - * @param request The request to schedule. - * @param server The server instance that should process the request. - */ - virtual void schedule_request( - const std::shared_ptr<$interface.name$Server_ClientContext>& request, - const std::shared_ptr<$interface.name$Server>& server) = 0; - - /** - * @brief Informs that a server has been stopped and all its requests have been cancelled. - * - * @param server The server instance that has been stopped. - */ - virtual void server_stopped( - const std::shared_ptr<$interface.name$Server>& server) = 0; - -}; - /** - * @brief Create a $interface.name$Server instance. + * @brief Create a $interface.name$ server instance. * * @param part The DomainParticipant to use for the server. * @param service_name The name of the service. @@ -157,7 +68,7 @@ struct $interface.name$ServerSchedulingStrategy * When set to 0, a pool with a single thread will be created. * @param implementation The implementation of the server interface. */ -extern eProsima_user_DllExport std::shared_ptr<$interface.name$Server> create_$interface.name$Server( +extern eProsima_user_DllExport std::shared_ptr create_$interface.name$Server( eprosima::fastdds::dds::DomainParticipant& part, const char* service_name, const eprosima::fastdds::dds::ReplierQos& qos, @@ -165,7 +76,7 @@ extern eProsima_user_DllExport std::shared_ptr<$interface.name$Server> create_$i std::shared_ptr<$interface.name$Server_IServerImplementation> implementation); /** - * @brief Create a $interface.name$Server instance. + * @brief Create a $interface.name$ server instance. * * @param part The DomainParticipant to use for the server. * @param service_name The name of the service. @@ -173,11 +84,11 @@ extern eProsima_user_DllExport std::shared_ptr<$interface.name$Server> create_$i * @param scheduler The request scheduling strategy to use for the server. * @param implementation The implementation of the server interface. */ -extern eProsima_user_DllExport std::shared_ptr<$interface.name$Server> create_$interface.name$Server( +extern eProsima_user_DllExport std::shared_ptr create_$interface.name$Server( eprosima::fastdds::dds::DomainParticipant& part, const char* service_name, const eprosima::fastdds::dds::ReplierQos& qos, - std::shared_ptr<$interface.name$ServerSchedulingStrategy> scheduler, + std::shared_ptr scheduler, std::shared_ptr<$interface.name$Server_IServerImplementation> implementation); $endif$ >> @@ -185,7 +96,7 @@ $endif$ operation_prototype(op) ::= << $if(op.annotationFeed)$ virtual void $op.name$( - const $interface.name$Server_ClientContext& info, + const eprosima::fastdds::dds::rpc::RpcRequest& info, $if(op.parameters)$ $operation_parameters(op.parameters)$, $endif$ @@ -194,18 +105,18 @@ $else$ $if(op.outputparam)$ virtual $paramRetType(op.outTypeCode)$ $op.name$( $if(op.inputparam)$ - const $interface.name$Server_ClientContext& info, + const eprosima::fastdds::dds::rpc::RpcRequest& info, $operation_parameters(op.inputparam)$) = 0; $else$ - const $interface.name$Server_ClientContext& info) = 0; + const eprosima::fastdds::dds::rpc::RpcRequest& info) = 0; $endif$ $elseif(op.inputparam)$ virtual $paramRetType(op.rettype)$ $op.name$( - const $interface.name$Server_ClientContext& info, + const eprosima::fastdds::dds::rpc::RpcRequest& info, $operation_parameters(op.inputparam)$) = 0; $else$ virtual $paramRetType(op.rettype)$ $op.name$( - const $interface.name$Server_ClientContext& info) = 0; + const eprosima::fastdds::dds::rpc::RpcRequest& info) = 0; $endif$ $endif$ >> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/ServerImplementation.stg b/src/main/java/com/eprosima/fastdds/idl/templates/ServerImplementation.stg index 906ad453..bb3ccac4 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/ServerImplementation.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/ServerImplementation.stg @@ -60,7 +60,7 @@ $endif$ operation_implementation(interface, op) ::= << $if(op.annotationFeed)$ void $op.name$( - const $interface.name$Server_ClientContext& info, + const eprosima::fastdds::dds::rpc::RpcRequest& info, $if(op.parameters)$ $operation_parameters(op.parameters)$, $endif$ @@ -72,10 +72,10 @@ $else$ $paramRetType(op.rettype)$ $op.name$( $endif$ $if(op.inputparam)$ - const $interface.name$Server_ClientContext& info, + const eprosima::fastdds::dds::rpc::RpcRequest& info, $operation_parameters(op.inputparam)$) override $else$ - const $interface.name$Server_ClientContext& info) override + const eprosima::fastdds::dds::rpc::RpcRequest& info) override $endif$ $endif$ { diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg b/src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg index 4696d1ce..ca83f00b 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg @@ -77,7 +77,7 @@ namespace frpc = eprosima::fastdds::dds::rpc; namespace frtps = eprosima::fastdds::rtps; class $interface.name$ServerLogic - : public $interface.name$Server + : public frpc::RpcServer , public std::enable_shared_from_this<$interface.name$ServerLogic> { using RequestType = $interface.name$_Request; @@ -104,9 +104,9 @@ public: fdds::DomainParticipant& part, const char* service_name, const fdds::ReplierQos& qos, - std::shared_ptr<$interface.name$ServerSchedulingStrategy> scheduler, + std::shared_ptr scheduler, std::shared_ptr<$interface.name$Server_IServerImplementation> implementation) - : $interface.name$Server() + : frpc::RpcServer() , participant_(part) , request_scheduler_(scheduler) , implementation_(std::move(implementation)) @@ -206,7 +206,7 @@ public: } void execute_request( - const std::shared_ptr<$interface.name$Server_ClientContext>& request) override + const std::shared_ptr& request) override { auto ctx = std::dynamic_pointer_cast(request); if (ctx) @@ -245,7 +245,7 @@ private: $interface.all_operations:{op | $operation_declarations(op)$}; separator="\n\n"$ - struct RequestContext : $interface.name$Server_ClientContext + struct RequestContext : frpc::RpcRequest { RequestType request; frpc::RequestInfo info; @@ -374,7 +374,7 @@ $endif$ }; struct ThreadPool - : public $interface.name$ServerSchedulingStrategy + : public frpc::RpcServerSchedulingStrategy { ThreadPool( $interface.name$ServerLogic& server, @@ -391,7 +391,7 @@ $endif$ { while (!finished_) { - std::shared_ptr<$interface.name$Server_ClientContext> req; + std::shared_ptr req; { std::unique_lock lock(mtx_); cv_.wait(lock, [this]() @@ -418,8 +418,8 @@ $endif$ } void schedule_request( - const std::shared_ptr<$interface.name$Server_ClientContext>& req, - const std::shared_ptr<$interface.name$Server>& server) override + const std::shared_ptr& req, + const std::shared_ptr& server) override { static_cast(server); @@ -432,7 +432,7 @@ $endif$ } void server_stopped( - const std::shared_ptr<$interface.name$Server>& server) override + const std::shared_ptr& server) override { static_cast(server); @@ -457,7 +457,7 @@ $endif$ $interface.name$ServerLogic& server_; std::mutex mtx_; std::condition_variable cv_; - std::queue> requests_; + std::queue> requests_; bool finished_{ false }; std::vector threads_; }; @@ -526,16 +526,16 @@ $endif$ fdds::GuardCondition finish_condition_; std::mutex mtx_; std::map> processing_requests_; - std::shared_ptr<$interface.name$ServerSchedulingStrategy> request_scheduler_; + std::shared_ptr request_scheduler_; std::shared_ptr<$interface.name$Server_IServerImplementation> implementation_; }; struct $interface.name$ServerProxy - : public $interface.name$Server + : public frpc::RpcServer { $interface.name$ServerProxy( - std::shared_ptr<$interface.name$Server> impl) + std::shared_ptr impl) : impl_(std::move(impl)) { } @@ -559,19 +559,19 @@ struct $interface.name$ServerProxy } void execute_request( - const std::shared_ptr<$interface.name$Server_ClientContext>& request) override + const std::shared_ptr& request) override { impl_->execute_request(request); } private: - std::shared_ptr<$interface.name$Server> impl_; + std::shared_ptr impl_; }; } // namespace detail -std::shared_ptr<$interface.name$Server> create_$interface.name$Server( +std::shared_ptr create_$interface.name$Server( eprosima::fastdds::dds::DomainParticipant& part, const char* service_name, const eprosima::fastdds::dds::ReplierQos& qos, @@ -583,11 +583,11 @@ std::shared_ptr<$interface.name$Server> create_$interface.name$Server( return std::make_shared(ptr); } -std::shared_ptr<$interface.name$Server> create_$interface.name$Server( +std::shared_ptr create_$interface.name$Server( eprosima::fastdds::dds::DomainParticipant& part, const char* service_name, const eprosima::fastdds::dds::ReplierQos& qos, - std::shared_ptr<$interface.name$ServerSchedulingStrategy> scheduler, + std::shared_ptr scheduler, std::shared_ptr<$interface.name$Server_IServerImplementation> implementation) { auto ptr = std::make_shared(