Skip to content

Commit 360a388

Browse files
CarlosespicurMiguelCompany
authored andcommitted
Add RPCDDS internal API (#5638)
* Refs #22682: Add public interfaces of RPC Entities Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add RequestInfo class Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add ServiceTypeSupport interface Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add Requester/Replier parameter classes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add private headers and implement RPC methods Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Expose Requester/Replier endpoint getters to public API Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add public methods for deleting requester/replier entities Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Allow calling get_statuscondition method on constant entities Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Refactor blackbox tests Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Avoid sample filtering on request topic Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix segFault error due to deleting endpoints manually Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix TCPRequester params Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Enable type() method for const DataReader objects Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add unit tests for Requester/Replier parameters validation Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add unit tests for DomainParticipant public API methods Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix test errors. Add service/participant checks and avoid inconsistent statuses when unregister types methods fail Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Update versions.md Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes. Remove RequesterParams/ReplierParams classes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes. Unify parameters in Requester/Replier take/send methods Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix RequesterImpl::send_request related_sample_identity assignment Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix typos Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Uncrustify Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Avoid creating unnecesary RequestReplyContentFilter instances Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Add suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes. Add return_load method to Requester/Replier public API Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes. Blackbox tests classes Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Apply suggested changes. Update send_reply signature. Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix blackbox tests Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix notation errors in Requester/Replier Signed-off-by: Carlosespicur <[email protected]> * Refs #22682: Fix memory leaks in RequestReplyContentFilterFactory Signed-off-by: Carlosespicur <[email protected]> --------- Signed-off-by: Carlosespicur <[email protected]>
1 parent a0ba4fc commit 360a388

File tree

61 files changed

+5642
-1125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5642
-1125
lines changed

include/fastdds/dds/core/Entity.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class Entity
132132
return status_condition_;
133133
}
134134

135+
/**
136+
* @brief Allows access to the StatusCondition associated with the Entity
137+
*
138+
* @return Const Reference to StatusCondition object
139+
*/
140+
FASTDDS_EXPORTED_API const StatusCondition& get_statuscondition() const
141+
{
142+
return status_condition_;
143+
}
144+
135145
protected:
136146

137147
/**

include/fastdds/dds/domain/DomainParticipant.hpp

+113
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
3434
#include <fastdds/dds/domain/qos/ReplierQos.hpp>
3535
#include <fastdds/dds/domain/qos/RequesterQos.hpp>
36+
#include <fastdds/dds/rpc/ServiceTypeSupport.hpp>
3637
#include <fastdds/dds/topic/ContentFilteredTopic.hpp>
3738
#include <fastdds/dds/topic/IContentFilterFactory.hpp>
3839
#include <fastdds/dds/topic/Topic.hpp>
@@ -55,12 +56,19 @@ class ResourceEvent;
5556
} // namespace rtps
5657

5758
namespace dds {
59+
namespace rpc {
60+
class Replier;
61+
class Requester;
62+
class Service;
63+
} // namespace rpc
5864

5965
class DomainParticipantImpl;
6066
class DomainParticipantListener;
6167
class Publisher;
6268
class PublisherQos;
6369
class PublisherListener;
70+
class ReplierQos;
71+
class RequesterQos;
6472
class Subscriber;
6573
class SubscriberQos;
6674
class SubscriberListener;
@@ -388,6 +396,82 @@ class DomainParticipant : public Entity
388396
const std::string& topic_name,
389397
const fastdds::dds::Duration_t& timeout);
390398

399+
/**
400+
* Create a RPC service.
401+
*
402+
* @param service_name Name of the service.
403+
* @param service_type_name Type name of the service (Request & reply types)
404+
*
405+
* @return Pointer to the created service. nullptr in error case.
406+
*/
407+
FASTDDS_EXPORTED_API rpc::Service* create_service(
408+
const std::string& service_name,
409+
const std::string& service_type_name);
410+
411+
/**
412+
* Find a RPC service by name
413+
*
414+
* @param service_name Name of the service to search for.
415+
* @return Pointer to the service object if found, nullptr if not found.
416+
*/
417+
FASTDDS_EXPORTED_API rpc::Service* find_service(
418+
const std::string& service_name) const;
419+
420+
/**
421+
* Delete a registered RPC service
422+
*
423+
* @param service Pointer to the service to be deleted.
424+
* @return RETCODE_OK if the service was deleted, or an specific error code otherwise.
425+
*/
426+
FASTDDS_EXPORTED_API ReturnCode_t delete_service(
427+
const rpc::Service* service);
428+
429+
/**
430+
* Create a RPC Requester in a given Service.
431+
*
432+
* @param service Pointer to a service object where the requester will be created.
433+
* @param requester_qos QoS of the requester.
434+
*
435+
* @return Pointer to the created requester. nullptr in error case.
436+
*/
437+
FASTDDS_EXPORTED_API rpc::Requester* create_service_requester(
438+
rpc::Service* service,
439+
const RequesterQos& requester_qos);
440+
441+
/**
442+
* Deletes an existing RPC Requester
443+
*
444+
* @param service_name Name of the service where the requester is created.
445+
* @param requester Pointer to the requester to be deleted.
446+
* @return RETCODE_OK if the requester was deleted, or an specific error code otherwise.
447+
*/
448+
FASTDDS_EXPORTED_API ReturnCode_t delete_service_requester(
449+
const std::string& service_name,
450+
rpc::Requester* requester);
451+
452+
/**
453+
* Create a RPC Replier in a given Service. It will override the current service's replier
454+
*
455+
* @param service Pointer to a service object where the Replier will be created.
456+
* @param replier_qos QoS of the replier.
457+
*
458+
* @return Pointer to the created replier. nullptr in error case.
459+
*/
460+
FASTDDS_EXPORTED_API rpc::Replier* create_service_replier(
461+
rpc::Service* service,
462+
const ReplierQos& replier_qos);
463+
464+
/**
465+
* Deletes an existing RPC Replier
466+
*
467+
* @param service_name Name of the service where the replier is created.
468+
* @param replier Pointer to the replier to be deleted.
469+
* @return RETCODE_OK if the replier was deleted, or an specific error code otherwise.
470+
*/
471+
FASTDDS_EXPORTED_API ReturnCode_t delete_service_replier(
472+
const std::string& service_name,
473+
rpc::Replier* replier);
474+
391475
/**
392476
* Looks up an existing, locally created @ref TopicDescription, based on its name.
393477
* May be called on a disabled participant.
@@ -1041,6 +1125,35 @@ class DomainParticipant : public Entity
10411125
FASTDDS_EXPORTED_API TypeSupport find_type(
10421126
const std::string& type_name) const;
10431127

1128+
/**
1129+
* Register a service type in this participant.
1130+
*
1131+
* @param service_type ServiceTypeSupport.
1132+
* @param service_type_name The name that will be used to identify the service type.
1133+
* @return RETCODE_OK if it is correctly registered. Error code otherwise.
1134+
*/
1135+
FASTDDS_EXPORTED_API ReturnCode_t register_service_type(
1136+
rpc::ServiceTypeSupport service_type,
1137+
const std::string& service_type_name);
1138+
1139+
/**
1140+
* Unregister a service type in this participant.
1141+
*
1142+
* @param service_type_name Name of the type
1143+
* @return RETCODE_OK if it is correctly unregistered. Error code otherwise.
1144+
*/
1145+
FASTDDS_EXPORTED_API ReturnCode_t unregister_service_type(
1146+
const std::string& service_type_name);
1147+
1148+
/**
1149+
* This method gives access to a registered service type based on its name.
1150+
*
1151+
* @param service_type_name Name of the type
1152+
* @return ServiceTypeSupport corresponding to the service_type_name
1153+
*/
1154+
FASTDDS_EXPORTED_API rpc::ServiceTypeSupport find_service_type(
1155+
const std::string& service_type_name) const;
1156+
10441157
/**
10451158
* Returns the DomainParticipant's handle.
10461159
*

include/fastdds/dds/rpc/RPCEntity.hpp

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FASTDDS_DDS_RPC__RPCENTITY_HPP
16+
#define FASTDDS_DDS_RPC__RPCENTITY_HPP
17+
18+
#include <fastdds/dds/core/detail/DDSReturnCode.hpp>
19+
#include <fastdds/fastdds_dll.hpp>
20+
21+
namespace eprosima {
22+
namespace fastdds {
23+
namespace dds {
24+
namespace rpc {
25+
26+
/**
27+
* @brief Abstract base class for all RPC Objects
28+
*/
29+
class RPCEntity
30+
{
31+
32+
public:
33+
34+
/**
35+
* @brief Enables the entity
36+
*/
37+
virtual ReturnCode_t enable() = 0;
38+
39+
/**
40+
* @brief Disables the entity
41+
*/
42+
virtual ReturnCode_t close() = 0;
43+
44+
/**
45+
* @brief Check if the entity is enabled
46+
*/
47+
virtual bool is_enabled() const = 0;
48+
49+
protected:
50+
51+
/**
52+
* @brief Destructor
53+
*/
54+
~RPCEntity() = default;
55+
56+
};
57+
58+
} // namespace rpc
59+
} // namespace dds
60+
} // namespace fastdds
61+
} // namespace eprosima
62+
63+
#endif // FASTDDS_DDS_RPC__RPCENTITY_HPP

include/fastdds/dds/rpc/Replier.hpp

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FASTDDS_DDS_RPC__REPLIER_HPP
16+
#define FASTDDS_DDS_RPC__REPLIER_HPP
17+
18+
#include <fastdds/dds/core/LoanableSequence.hpp>
19+
#include <fastdds/dds/rpc/RequestInfo.hpp>
20+
#include <fastdds/dds/rpc/RPCEntity.hpp>
21+
22+
namespace eprosima {
23+
namespace fastdds {
24+
namespace dds {
25+
26+
class LoanableCollection;
27+
class DataWriter;
28+
class DataReader;
29+
30+
} // namespace dds
31+
32+
namespace dds {
33+
namespace rpc {
34+
35+
/**
36+
* @brief Base class for a Replier in the RPC communication
37+
*/
38+
class Replier : public RPCEntity
39+
{
40+
41+
public:
42+
43+
/**
44+
* @brief Returns the name of the service to which the replier belongs
45+
*/
46+
virtual const std::string& get_service_name() const = 0;
47+
48+
/**
49+
* @brief Send a reply message
50+
*
51+
* @param data Data to send
52+
* @param info Information about the reply sample. This information is used to match the reply with the request through the SampleIdentity
53+
* @return RETCODE_OK if the reply was sent successfully or a ReturnCode related to the specific error otherwise
54+
*/
55+
virtual ReturnCode_t send_reply(
56+
void* data,
57+
const RequestInfo& info) = 0;
58+
59+
/**
60+
* @brief Take a request message from the Replier DataReader's history.
61+
*
62+
* @param data Data to receive the request
63+
* @param info Information about the request sample
64+
* @return RETCODE_OK if the request was taken successfully or a ReturnCode related to the specific error otherwise
65+
*/
66+
virtual ReturnCode_t take_request(
67+
void* data,
68+
RequestInfo& info) = 0;
69+
70+
/**
71+
* @brief Take all request messages stored in the Replier DataReader's history.
72+
* @note This method does not allow to take only the samples associated to a given request. User must implement a zero-copy solution to link request and reply samples.
73+
*
74+
* @param data Data to receive the request
75+
* @param info Information about the request sample
76+
* @return RETCODE_OK if the request was taken successfully or a ReturnCode related to the specific error otherwise
77+
*/
78+
virtual ReturnCode_t take_request(
79+
LoanableCollection& data,
80+
LoanableSequence<RequestInfo>& info) = 0;
81+
82+
/**
83+
* @brief This operation indicates to the Replier's DataReader that
84+
* the application is done accessing the collection of Request @c datas and @c infos obtained by
85+
* some earlier invocation of @ref take_request.
86+
*
87+
* @param [in,out] data A LoanableCollection object where the received data samples were obtained from
88+
* an earlier invocation of take_request on this Replier.
89+
* @param [in,out] info A LoanableSequence where the received request infos were obtained from
90+
* an earlier invocation of take_request on this Replier.
91+
*/
92+
virtual ReturnCode_t return_loan(
93+
LoanableCollection& data,
94+
LoanableSequence<RequestInfo>& info) = 0;
95+
96+
/**
97+
* @brief Getter for the Replier's DataWriter
98+
*/
99+
virtual const DataWriter* get_replier_writer() const = 0;
100+
101+
/**
102+
* @brief Getter for the Replier's DataReader
103+
*/
104+
virtual const DataReader* get_replier_reader() const = 0;
105+
106+
protected:
107+
108+
/**
109+
* @brief Destructor
110+
*/
111+
~Replier() = default;
112+
113+
};
114+
115+
} // namespace rpc
116+
} // namespace dds
117+
} // namesapce fastdds
118+
} // namespace eprosima
119+
120+
121+
#endif // FASTDDS_DDS_RPC__REPLIER_HPP
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FASTDDS_DDS_RPC__REQUESTINFO_HPP
16+
#define FASTDDS_DDS_RPC__REQUESTINFO_HPP
17+
18+
#include <fastdds/dds/subscriber/SampleInfo.hpp>
19+
20+
namespace eprosima {
21+
namespace fastdds {
22+
namespace dds {
23+
namespace rpc {
24+
25+
using RequestInfo = SampleInfo;
26+
27+
} // namespace rpc
28+
} // namespace dds
29+
} // namespace fastdds
30+
} // namespace eprosima
31+
32+
#endif // FASTDDS_DDS_RPC__REQUESTINFO_HPP

0 commit comments

Comments
 (0)