Skip to content

Commit 6a0dfe4

Browse files
Refactor RPC utils types and structures
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
1 parent b294b58 commit 6a0dfe4

11 files changed

Lines changed: 394 additions & 413 deletions

File tree

ddsenabler/src/cpp/DDSEnabler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ bool DDSEnabler::send_action_goal(
389389
action_name,
390390
action_id,
391391
goal_request_id,
392-
RpcUtils::ActionType::GOAL,
392+
ACTION_TYPE::ACTION_GOAL,
393393
rpc_protocol))
394394
{
395395
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
@@ -424,7 +424,7 @@ bool DDSEnabler::send_action_get_result_request(
424424
action_name,
425425
action_id,
426426
get_result_request_id,
427-
RpcUtils::ActionType::RESULT))
427+
ACTION_TYPE::ACTION_RESULT))
428428
{
429429
EPROSIMA_LOG_ERROR(DDSENABLER_EXECUTION,
430430
"Failed to store action get result request to action " << action_name

ddsenabler_participants/include/ddsenabler_participants/EnablerParticipant.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,12 @@ class EnablerParticipant : public ddspipe::participants::SchemaParticipant
154154
const std::string& topic_name) const;
155155

156156
bool service_discovered_nts_(
157-
const std::string& service_name,
158-
const ddspipe::core::types::DdsTopic& topic,
159-
RpcUtils::RpcType rpc_type,
160-
RPC_PROTOCOL rpc_protocol);
157+
const RpcInfo& rpc_info,
158+
const ddspipe::core::types::DdsTopic& topic);
161159

162160
bool action_discovered_nts_(
163-
const std::string& action_name,
164-
const ddspipe::core::types::DdsTopic& topic,
165-
RpcUtils::RpcType rpc_type,
166-
RPC_PROTOCOL rpc_protocol);
161+
const RpcInfo& rpc_info,
162+
const ddspipe::core::types::DdsTopic& topic);
167163

168164
bool revoke_service_nts_(
169165
const std::string& service_name);

ddsenabler_participants/include/ddsenabler_participants/Handler.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
141141
*/
142142
DDSENABLER_PARTICIPANTS_DllAPI
143143
void add_action(
144-
const RpcUtils::RpcAction& action);
144+
const RpcAction& action);
145145

146146
/**
147147
* @brief Add a data sample, associated to the given \c topic.
@@ -199,7 +199,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
199199
const std::string& action_name,
200200
const UUID& action_id,
201201
const uint64_t request_id,
202-
const RpcUtils::ActionType action_type,
202+
const ACTION_TYPE action_type,
203203
const RPC_PROTOCOL rpc_protocol = RPC_PROTOCOL::ROS2);
204204

205205
/**
@@ -253,7 +253,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
253253
*
254254
* @param [in] action_name Name of the action.
255255
* @param [in] action_id UUID of the action to be checked.
256-
* @return The RPC protocol of the action, or RPC_PROTOCOL::UNKNOWN if the action is not found.
256+
* @return The RPC protocol of the action, or RPC_PROTOCOL::PROTOCOL_UNKNOWN if the action is not found.
257257
*/
258258
DDSENABLER_PARTICIPANTS_DllAPI
259259
RPC_PROTOCOL get_action_rpc_protocol(
@@ -422,7 +422,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
422422
*/
423423
bool get_action_request_UUID(
424424
const uint64_t request_id,
425-
const RpcUtils::ActionType action_type,
425+
const ACTION_TYPE action_type,
426426
UUID& action_id);
427427

428428
/**
@@ -493,7 +493,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
493493
* @param [in] action RPC action associated to this action.
494494
*/
495495
void write_action_nts_(
496-
const RpcUtils::RpcAction& action);
496+
const RpcAction& action);
497497
/**
498498
* @brief Write to user's app.
499499
*
@@ -603,7 +603,7 @@ class Handler : public ddspipe::participants::ISchemaHandler
603603
const fastdds::dds::DynamicType::_ref_type& dyn_type,
604604
const uint64_t request_id,
605605
const std::string& action_name,
606-
const RpcUtils::RpcType& rpc_type);
606+
const ACTION_TYPE action_type);
607607

608608
/**
609609
* @brief Register a type using the given serialized type data.

ddsenabler_participants/include/ddsenabler_participants/RpcStructs.hpp

Lines changed: 75 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <optional>
2222

2323
#include <ddspipe_core/types/dds/Endpoint.hpp>
24-
#include <ddsenabler_participants/RpcUtils.hpp>
24+
#include <ddsenabler_participants/RpcTypes.hpp>
2525

2626
namespace eprosima {
2727
namespace ddsenabler {
@@ -34,13 +34,60 @@ enum class ActionEraseReason
3434
FORCED // Force erase regardless of status/result
3535
};
3636

37+
struct RpcAction
38+
{
39+
RpcAction() = default;
40+
RpcAction(
41+
const std::string& action_name,
42+
const ddspipe::core::types::RpcTopic& goal,
43+
const ddspipe::core::types::RpcTopic& result,
44+
const ddspipe::core::types::RpcTopic& cancel,
45+
const ddspipe::core::types::DdsTopic& feedback,
46+
const ddspipe::core::types::DdsTopic& status)
47+
: action_name(action_name)
48+
, goal(goal)
49+
, result(result)
50+
, cancel(cancel)
51+
, feedback(feedback)
52+
, status(status)
53+
{
54+
}
55+
56+
std::string action_name;
57+
ddspipe::core::types::RpcTopic goal;
58+
ddspipe::core::types::RpcTopic result;
59+
ddspipe::core::types::RpcTopic cancel;
60+
ddspipe::core::types::DdsTopic feedback;
61+
ddspipe::core::types::DdsTopic status;
62+
};
63+
64+
struct RpcInfo
65+
{
66+
RpcInfo(const std::string& dds_topic_name)
67+
: topic_name(dds_topic_name)
68+
, rpc_protocol(RPC_PROTOCOL::PROTOCOL_UNKNOWN)
69+
, rpc_type(RPC_TYPE::RPC_NONE)
70+
, service_type(SERVICE_TYPE::SERVICE_NONE)
71+
, action_type(ACTION_TYPE::ACTION_NONE)
72+
{
73+
}
74+
75+
std::string topic_name;
76+
std::string service_name;
77+
std::string action_name;
78+
RPC_PROTOCOL rpc_protocol;
79+
RPC_TYPE rpc_type;
80+
SERVICE_TYPE service_type;
81+
ACTION_TYPE action_type;
82+
};
83+
3784
struct ActionRequestInfo
3885
{
3986
ActionRequestInfo() = default;
4087

4188
ActionRequestInfo(
4289
const std::string& _action_name,
43-
RpcUtils::ActionType action_type,
90+
ACTION_TYPE action_type,
4491
uint64_t request_id,
4592
RPC_PROTOCOL rpc_protocol)
4693
: action_name(_action_name)
@@ -52,14 +99,14 @@ struct ActionRequestInfo
5299

53100
void set_request(
54101
uint64_t request_id,
55-
RpcUtils::ActionType action_type)
102+
ACTION_TYPE action_type)
56103
{
57104
switch (action_type)
58105
{
59-
case RpcUtils::ActionType::GOAL:
106+
case ACTION_TYPE::ACTION_GOAL:
60107
goal_request_id = request_id;
61108
break;
62-
case RpcUtils::ActionType::RESULT:
109+
case ACTION_TYPE::ACTION_RESULT:
63110
result_request_id = request_id;
64111
break;
65112
default:
@@ -69,13 +116,13 @@ struct ActionRequestInfo
69116
}
70117

71118
uint64_t get_request(
72-
RpcUtils::ActionType action_type) const
119+
ACTION_TYPE action_type) const
73120
{
74121
switch (action_type)
75122
{
76-
case RpcUtils::ActionType::GOAL:
123+
case ACTION_TYPE::ACTION_GOAL:
77124
return goal_request_id;
78-
case RpcUtils::ActionType::RESULT:
125+
case ACTION_TYPE::ACTION_RESULT:
79126
return result_request_id;
80127
default:
81128
return 0;
@@ -137,7 +184,7 @@ struct ServiceDiscovered
137184
}
138185

139186
std::string service_name;
140-
RPC_PROTOCOL rpc_protocol{RPC_PROTOCOL::UNKNOWN};
187+
RPC_PROTOCOL rpc_protocol{RPC_PROTOCOL::PROTOCOL_UNKNOWN};
141188

142189
ddspipe::core::types::DdsTopic topic_request;
143190
bool request_discovered{false};
@@ -153,9 +200,9 @@ struct ServiceDiscovered
153200

154201
bool add_topic(
155202
const ddspipe::core::types::DdsTopic& topic,
156-
RpcUtils::RpcType rpc_type)
203+
SERVICE_TYPE service_type)
157204
{
158-
if(rpc_type == RpcUtils::RpcType::RPC_REQUEST)
205+
if(service_type == SERVICE_TYPE::SERVICE_REQUEST)
159206
{
160207
if(request_discovered)
161208
return false;
@@ -187,9 +234,9 @@ struct ServiceDiscovered
187234
return false;
188235
}
189236

190-
bool remove_topic(RpcUtils::RpcType rpc_type)
237+
bool remove_topic(SERVICE_TYPE service_type)
191238
{
192-
if(rpc_type == RpcUtils::RpcType::RPC_REQUEST)
239+
if(service_type == SERVICE_TYPE::SERVICE_REQUEST)
193240
{
194241
request_discovered = false;
195242
topic_request = ddspipe::core::types::DdsTopic();
@@ -214,17 +261,17 @@ struct ServiceDiscovered
214261
}
215262

216263
bool get_topic(
217-
const RpcUtils::RpcType& rpc_type,
264+
SERVICE_TYPE service_type,
218265
ddspipe::core::types::DdsTopic& topic)
219266
{
220-
if(rpc_type == RpcUtils::RpcType::RPC_REQUEST)
267+
if(service_type == SERVICE_TYPE::SERVICE_REQUEST)
221268
{
222269
if(!request_discovered)
223270
return false;
224271
topic = topic_request;
225272
return true;
226273
}
227-
if (rpc_type == RpcUtils::RpcType::RPC_REPLY)
274+
if (service_type == SERVICE_TYPE::SERVICE_REPLY)
228275
{
229276
if(!reply_discovered)
230277
return false;
@@ -251,7 +298,7 @@ struct ActionDiscovered
251298
}
252299

253300
std::string action_name;
254-
RPC_PROTOCOL rpc_protocol{RPC_PROTOCOL::UNKNOWN};
301+
RPC_PROTOCOL rpc_protocol{RPC_PROTOCOL::PROTOCOL_UNKNOWN};
255302
std::weak_ptr<ServiceDiscovered> goal;
256303
std::weak_ptr<ServiceDiscovered> result;
257304
std::weak_ptr<ServiceDiscovered> cancel;
@@ -281,20 +328,17 @@ struct ActionDiscovered
281328

282329
bool add_service(
283330
std::shared_ptr<ServiceDiscovered> service,
284-
RpcUtils::RpcType rpc_type)
331+
ACTION_TYPE action_type)
285332
{
286-
switch (rpc_type)
333+
switch (action_type)
287334
{
288-
case RpcUtils::RpcType::ACTION_GOAL_REQUEST:
289-
case RpcUtils::RpcType::ACTION_GOAL_REPLY:
335+
case ACTION_TYPE::ACTION_GOAL:
290336
goal = service;
291337
break;
292-
case RpcUtils::RpcType::ACTION_RESULT_REQUEST:
293-
case RpcUtils::RpcType::ACTION_RESULT_REPLY:
338+
case ACTION_TYPE::ACTION_RESULT:
294339
result = service;
295340
break;
296-
case RpcUtils::RpcType::ACTION_CANCEL_REQUEST:
297-
case RpcUtils::RpcType::ACTION_CANCEL_REPLY:
341+
case ACTION_TYPE::ACTION_CANCEL:
298342
cancel = service;
299343
break;
300344
default:
@@ -306,15 +350,15 @@ struct ActionDiscovered
306350

307351
bool add_topic(
308352
const ddspipe::core::types::DdsTopic& topic,
309-
RpcUtils::RpcType rpc_type)
353+
ACTION_TYPE action_type)
310354
{
311-
switch (rpc_type)
355+
switch (action_type)
312356
{
313-
case RpcUtils::RpcType::ACTION_FEEDBACK:
357+
case ACTION_TYPE::ACTION_FEEDBACK:
314358
feedback = topic;
315359
feedback_discovered = true;
316360
break;
317-
case RpcUtils::RpcType::ACTION_STATUS:
361+
case ACTION_TYPE::ACTION_STATUS:
318362
status = topic;
319363
status_discovered = true;
320364
break;
@@ -325,7 +369,7 @@ struct ActionDiscovered
325369
return true;
326370
}
327371

328-
RpcUtils::RpcAction get_action(const std::string& action_name)
372+
RpcAction get_action()
329373
{
330374
auto g = goal.lock();
331375
auto r = result.lock();
@@ -334,7 +378,7 @@ struct ActionDiscovered
334378
if (!fully_discovered || !g || !r || !c)
335379
throw std::runtime_error("Action not fully discovered or ServiceDiscovered expired");
336380

337-
return RpcUtils::RpcAction(
381+
return RpcAction(
338382
action_name,
339383
g->get_service(),
340384
r->get_service(),

ddsenabler_participants/include/ddsenabler_participants/RpcTypes.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <cstdint>
2121
#include <string>
2222

23+
#include <ddspipe_core/types/topic/dds/DdsTopic.hpp>
24+
#include <ddspipe_core/types/topic/rpc/RpcTopic.hpp>
25+
2326
#pragma once
2427

2528
namespace eprosima {
@@ -31,7 +34,31 @@ using UUID = std::array<uint8_t, 16>;
3134
enum RPC_PROTOCOL {
3235
ROS2 = 0,
3336
FASTDDS,
34-
UNKNOWN
37+
PROTOCOL_UNKNOWN
38+
};
39+
40+
enum RPC_TYPE
41+
{
42+
RPC_NONE = 0,
43+
RPC_SERVICE,
44+
RPC_ACTION
45+
};
46+
47+
enum SERVICE_TYPE
48+
{
49+
SERVICE_NONE = 0,
50+
SERVICE_REQUEST,
51+
SERVICE_REPLY
52+
};
53+
54+
enum ACTION_TYPE
55+
{
56+
ACTION_NONE = 0,
57+
ACTION_GOAL,
58+
ACTION_RESULT,
59+
ACTION_CANCEL,
60+
ACTION_FEEDBACK,
61+
ACTION_STATUS
3562
};
3663

3764
enum STATUS_CODE {
@@ -46,7 +73,7 @@ enum STATUS_CODE {
4673
STATUS_TIMEOUT,
4774
STATUS_FAILED,
4875
STATUS_CANCEL_REQUEST_FAILED
49-
};
76+
};
5077

5178
enum CANCEL_CODE {
5279
ERROR_NONE = 0,

0 commit comments

Comments
 (0)