Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
109 changes: 10 additions & 99 deletions src/main/java/com/eprosima/fastdds/idl/templates/ServerHeader.stg
Original file line number Diff line number Diff line change
Expand Up @@ -51,104 +51,15 @@ $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;

$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.
Expand All @@ -157,35 +68,35 @@ 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<eprosima::fastdds::dds::rpc::RpcServer> create_$interface.name$Server(
eprosima::fastdds::dds::DomainParticipant& part,
const char* service_name,
const eprosima::fastdds::dds::ReplierQos& qos,
size_t thread_pool_size,
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.
* @param qos The QoS settings for the server.
* @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<eprosima::fastdds::dds::rpc::RpcServer> 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<eprosima::fastdds::dds::rpc::RpcServerSchedulingStrategy> scheduler,
std::shared_ptr<$interface.name$Server_IServerImplementation> implementation);
$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$
Expand All @@ -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$
>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand All @@ -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$
{
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/com/eprosima/fastdds/idl/templates/ServerSource.stg
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<frpc::RpcServerSchedulingStrategy> scheduler,
std::shared_ptr<$interface.name$Server_IServerImplementation> implementation)
: $interface.name$Server()
: frpc::RpcServer()
, participant_(part)
, request_scheduler_(scheduler)
, implementation_(std::move(implementation))
Expand Down Expand Up @@ -206,7 +206,7 @@ public:
}

void execute_request(
const std::shared_ptr<$interface.name$Server_ClientContext>& request) override
const std::shared_ptr<frpc::RpcRequest>& request) override
{
auto ctx = std::dynamic_pointer_cast<RequestContext>(request);
if (ctx)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -374,7 +374,7 @@ $endif$
};

struct ThreadPool
: public $interface.name$ServerSchedulingStrategy
: public frpc::RpcServerSchedulingStrategy
{
ThreadPool(
$interface.name$ServerLogic& server,
Expand All @@ -391,7 +391,7 @@ $endif$
{
while (!finished_)
{
std::shared_ptr<$interface.name$Server_ClientContext> req;
std::shared_ptr<frpc::RpcRequest> req;
{
std::unique_lock<std::mutex> lock(mtx_);
cv_.wait(lock, [this]()
Expand All @@ -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<frpc::RpcRequest>& req,
const std::shared_ptr<frpc::RpcServer>& server) override
{
static_cast<void>(server);

Expand All @@ -432,7 +432,7 @@ $endif$
}

void server_stopped(
const std::shared_ptr<$interface.name$Server>& server) override
const std::shared_ptr<frpc::RpcServer>& server) override
{
static_cast<void>(server);

Expand All @@ -457,7 +457,7 @@ $endif$
$interface.name$ServerLogic& server_;
std::mutex mtx_;
std::condition_variable cv_;
std::queue<std::shared_ptr<$interface.name$Server_ClientContext\>> requests_;
std::queue<std::shared_ptr<frpc::RpcRequest\>> requests_;
bool finished_{ false };
std::vector<std::thread> threads_;
};
Expand Down Expand Up @@ -526,16 +526,16 @@ $endif$
fdds::GuardCondition finish_condition_;
std::mutex mtx_;
std::map<frtps::SampleIdentity, std::shared_ptr<RequestContext\>> processing_requests_;
std::shared_ptr<$interface.name$ServerSchedulingStrategy> request_scheduler_;
std::shared_ptr<frpc::RpcServerSchedulingStrategy> 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<frpc::RpcServer> impl)
: impl_(std::move(impl))
{
}
Expand All @@ -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<frpc::RpcRequest>& request) override
{
impl_->execute_request(request);
}

private:

std::shared_ptr<$interface.name$Server> impl_;
std::shared_ptr<frpc::RpcServer> impl_;
};

} // namespace detail

std::shared_ptr<$interface.name$Server> create_$interface.name$Server(
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcServer> create_$interface.name$Server(
eprosima::fastdds::dds::DomainParticipant& part,
const char* service_name,
const eprosima::fastdds::dds::ReplierQos& qos,
Expand All @@ -583,11 +583,11 @@ std::shared_ptr<$interface.name$Server> create_$interface.name$Server(
return std::make_shared<detail::$interface.name$ServerProxy>(ptr);
}

std::shared_ptr<$interface.name$Server> create_$interface.name$Server(
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcServer> 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<eprosima::fastdds::dds::rpc::RpcServerSchedulingStrategy> scheduler,
std::shared_ptr<$interface.name$Server_IServerImplementation> implementation)
{
auto ptr = std::make_shared<detail::$interface.name$ServerLogic>(
Expand Down