Skip to content

Commit 276ae8e

Browse files
Separate creation & destroy entities streams (backport #185) (#188)
* Separate creation & destroy entities streams (#185) * Separate creation & destroy entities streams * Fix * Fix * Update session destruction * Update rmw_microxrcedds_c/src/config.h.in Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> * Update rmw_microxrcedds_c/CMakeLists.txt Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> * Update rmw_microxrcedds_c/src/config.h.in Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> (cherry picked from commit 0575d52) # Conflicts: # README.md # rmw_microxrcedds_c/CMakeLists.txt * Fix conflicts Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
1 parent 0aa2e12 commit 276ae8e

13 files changed

Lines changed: 98 additions & 65 deletions

File tree

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,32 @@ set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maxim
5757
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
5858
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
5959
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
60-
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING
61-
"This value sets the maximum time to wait for an XRCE entity creation and destroy in milliseconds.
62-
If set to 0 best effort is used.")
6360
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
6461
"This value sets the default time to wait for a publication in a reliable mode in milliseconds.")
6562

66-
set(RMW_UXRCE_STREAM_HISTORY "4" CACHE STRING "This value sets the number of MTUs to buffer, both input and output. Micro XRCE-DDS client configuration provides their size")
67-
set(RMW_UXRCE_STREAM_HISTORY_INPUT "" CACHE STRING "This value sets the number of MTUs to input buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_OUTPUT is blank. Micro XRCE-DDS client configuration provides their size")
68-
set(RMW_UXRCE_STREAM_HISTORY_OUTPUT "" CACHE STRING "This value sets the number of MTUs to output buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_INPUT is blank. Micro XRCE-DDS client configuration provides their size")
63+
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING
64+
"This value sets the default maximum time to wait for an XRCE entity creation and destroy in milliseconds.
65+
If set to 0 best effort is used.")
66+
set(RMW_UXRCE_ENTITY_CREATION_TIMEOUT "" CACHE STRING
67+
"This value sets the maximum time to wait for an XRCE entity creation in milliseconds.
68+
If set to 0 best effort is used.")
69+
set(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT "" CACHE STRING
70+
"This value sets the maximum time to wait for an XRCE entity destroy in milliseconds.
71+
If set to 0 best effort is used.")
72+
73+
if(RMW_UXRCE_ENTITY_CREATION_TIMEOUT STREQUAL "")
74+
set(RMW_UXRCE_ENTITY_CREATION_TIMEOUT ${RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT})
75+
endif()
76+
77+
if(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT STREQUAL "")
78+
set(RMW_UXRCE_ENTITY_DESTROY_TIMEOUT ${RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT})
79+
endif()
80+
81+
set(RMW_UXRCE_STREAM_HISTORY "4" CACHE STRING "This value sets the number of MTUs to buffer, both input and output.")
82+
set(RMW_UXRCE_STREAM_HISTORY_INPUT "" CACHE STRING
83+
"This value sets the number of MTUs to input buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_OUTPUT is blank.")
84+
set(RMW_UXRCE_STREAM_HISTORY_OUTPUT "" CACHE STRING
85+
"This value sets the number of MTUs to output buffer. It will be ignored if RMW_UXRCE_STREAM_HISTORY_INPUT is blank.")
6986

7087
if(RMW_UXRCE_STREAM_HISTORY_INPUT STREQUAL "" OR RMW_UXRCE_STREAM_HISTORY_OUTPUT STREQUAL "")
7188
unset(RMW_UXRCE_STREAM_HISTORY_INPUT)

rmw_microxrcedds_c/src/config.h.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define RMW_UXRCE_MAX_TRANSPORT_MTU UXR_CONFIG_CUSTOM_TRANSPORT_MTU
2929
#endif
3030

31+
#define RMW_UXRCE_ENTITY_CREATION_TIMEOUT @RMW_UXRCE_ENTITY_CREATION_TIMEOUT@
32+
#define RMW_UXRCE_ENTITY_DESTROY_TIMEOUT @RMW_UXRCE_ENTITY_DESTROY_TIMEOUT@
33+
3134
#cmakedefine RMW_UXRCE_STREAM_HISTORY_INPUT
3235
#cmakedefine RMW_UXRCE_STREAM_HISTORY_OUTPUT
3336
#if defined(RMW_UXRCE_STREAM_HISTORY_INPUT) && defined(RMW_UXRCE_STREAM_HISTORY_OUTPUT)
@@ -40,7 +43,6 @@
4043
#define RMW_UXRCE_STREAM_HISTORY_OUTPUT @RMW_UXRCE_STREAM_HISTORY@
4144
#endif
4245

43-
#define RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT @RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT@
4446
#define RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT @RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT@
4547

4648
#define RMW_UXRCE_MAX_HISTORY @RMW_UXRCE_MAX_HISTORY@

rmw_microxrcedds_c/src/rmw_client.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ rmw_create_client(
104104
#ifdef RMW_UXRCE_USE_REFS
105105
// TODO(pablogs9): Use here true references
106106
// client_req = uxr_buffer_create_replier_ref(&custom_node->context->session,
107-
// *custom_node->context->creation_destroy_stream, custom_service->subscriber_id,
107+
// *custom_node->context->creation_stream, custom_service->subscriber_id,
108108
// custom_node->participant_id, "", UXR_REPLACE | UXR_REUSE);
109109
char service_name_id[20];
110110
generate_name(&custom_client->client_id, service_name_id, sizeof(service_name_id));
@@ -118,7 +118,7 @@ rmw_create_client(
118118
}
119119
client_req = uxr_buffer_create_requester_xml(
120120
&custom_node->context->session,
121-
*custom_node->context->creation_destroy_stream,
121+
*custom_node->context->creation_stream,
122122
custom_client->client_id,
123123
custom_node->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
124124
#else
@@ -136,7 +136,7 @@ rmw_create_client(
136136

137137
client_req = uxr_buffer_create_requester_bin(
138138
&custom_node->context->session,
139-
*custom_node->context->creation_destroy_stream,
139+
*custom_node->context->creation_stream,
140140
custom_client->client_id,
141141
custom_node->participant_id,
142142
(char *) service_name,
@@ -150,7 +150,7 @@ rmw_create_client(
150150
rmw_client->data = custom_client;
151151

152152
if (!run_xrce_session(
153-
custom_node->context, client_req,
153+
custom_node->context, custom_node->context->creation_stream, client_req,
154154
custom_node->context->creation_timeout))
155155
{
156156
put_memory(&client_memory, &custom_client->mem);
@@ -175,7 +175,7 @@ rmw_create_client(
175175

176176
custom_client->client_data_request = uxr_buffer_request_data(
177177
&custom_node->context->session,
178-
*custom_node->context->creation_destroy_stream, custom_client->client_id,
178+
*custom_node->context->creation_stream, custom_client->client_id,
179179
data_request_stream_id, &delivery_control);
180180
}
181181
return rmw_client;
@@ -216,11 +216,11 @@ rmw_destroy_client(
216216
uint16_t delete_client =
217217
uxr_buffer_delete_entity(
218218
&custom_node->context->session,
219-
*custom_node->context->creation_destroy_stream,
219+
*custom_node->context->destroy_stream,
220220
custom_client->client_id);
221221

222222
if (!run_xrce_session(
223-
custom_node->context, delete_client,
223+
custom_node->context, custom_node->context->destroy_stream, delete_client,
224224
custom_node->context->destroy_timeout))
225225
{
226226
result_ret = RMW_RET_TIMEOUT;

rmw_microxrcedds_c/src/rmw_graph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ rmw_ret_t rmw_graph_init(
4444

4545
uint16_t participant_req = uxr_buffer_create_participant_bin(
4646
&context->session,
47-
*context->creation_destroy_stream,
47+
*context->creation_stream,
4848
graph_info->participant_id,
4949
(int16_t)microros_domain_id,
5050
graph_participant_name,
@@ -79,7 +79,7 @@ rmw_ret_t rmw_graph_init(
7979
}
8080

8181
uint16_t subscriber_req = uxr_buffer_create_subscriber_xml(
82-
&context->session, *context->creation_destroy_stream, graph_info->subscriber_id,
82+
&context->session, *context->creation_stream, graph_info->subscriber_id,
8383
graph_info->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
8484

8585
graph_info->datareader_id = uxr_object_id(context->id_datareader++, UXR_DATAREADER_ID);
@@ -101,7 +101,7 @@ rmw_ret_t rmw_graph_init(
101101
}
102102

103103
uint16_t topic_req = uxr_buffer_create_topic_xml(
104-
&context->session, *context->creation_destroy_stream, graph_info->topic_id,
104+
&context->session, *context->creation_stream, graph_info->topic_id,
105105
graph_info->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
106106

107107
// Create graph datareader request
@@ -117,7 +117,7 @@ rmw_ret_t rmw_graph_init(
117117
}
118118

119119
uint16_t datareader_req = uxr_buffer_create_datareader_xml(
120-
&context->session, *context->creation_destroy_stream, graph_info->datareader_id,
120+
&context->session, *context->creation_stream, graph_info->datareader_id,
121121
graph_info->subscriber_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
122122

123123
// Run session

rmw_microxrcedds_c/src/rmw_init.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,16 @@ rmw_init(
189189
options->impl->transport_params.read_cb);
190190
#endif // RMW_UXRCE_TRANSPORT_CUSTOM
191191

192-
context_impl->creation_timeout = RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT;
193-
context_impl->destroy_timeout = RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT;
192+
context_impl->creation_timeout = RMW_UXRCE_ENTITY_CREATION_TIMEOUT;
193+
context_impl->destroy_timeout = RMW_UXRCE_ENTITY_DESTROY_TIMEOUT;
194+
195+
context_impl->creation_stream = (RMW_UXRCE_ENTITY_CREATION_TIMEOUT > 0) ?
196+
&context_impl->reliable_output :
197+
&context_impl->best_effort_output;
198+
199+
context_impl->destroy_stream = (RMW_UXRCE_ENTITY_DESTROY_TIMEOUT > 0) ?
200+
&context_impl->reliable_output :
201+
&context_impl->best_effort_output;
194202

195203
context_impl->id_participant = 0;
196204
context_impl->id_topic = 0;
@@ -246,10 +254,6 @@ rmw_init(
246254
&context_impl->session,
247255
context_impl->output_best_effort_stream_buffer, context_impl->transport.comm.mtu);
248256

249-
context_impl->creation_destroy_stream = (RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT > 0) ?
250-
&context_impl->reliable_output :
251-
&context_impl->best_effort_output;
252-
253257
if (!uxr_create_session(&context_impl->session)) {
254258
CLOSE_TRANSPORT(&context_impl->transport);
255259
RMW_SET_ERROR_MSG("failed to create node session on Micro ROS Agent.");
@@ -313,7 +317,14 @@ rmw_context_fini(
313317
}
314318

315319
if (NULL != context->impl) {
316-
uxr_delete_session(&context->impl->session);
320+
size_t retries = UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS;
321+
322+
rmw_context_impl_t * context_impl = context->impl;
323+
if (context_impl->destroy_stream->type == UXR_BEST_EFFORT_STREAM) {
324+
retries = 0;
325+
}
326+
327+
uxr_delete_session_retries(&context->impl->session, retries);
317328
rmw_uxrce_fini_session_memory(context->impl);
318329
CLOSE_TRANSPORT(&context->impl->transport);
319330
}

rmw_microxrcedds_c/src/rmw_microros_internal/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ typedef struct rmw_context_impl_t
8181
uxrStreamId best_effort_output;
8282
uxrStreamId best_effort_input;
8383

84-
uxrStreamId * creation_destroy_stream;
84+
uxrStreamId * creation_stream;
85+
uxrStreamId * destroy_stream;
8586
int creation_timeout;
8687
int destroy_timeout;
8788

rmw_microxrcedds_c/src/rmw_microros_internal/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
bool run_xrce_session(
2323
rmw_context_impl_t * context,
24+
uxrStreamId * target_stream,
2425
uint16_t requests,
2526
int timeout);
2627

rmw_microxrcedds_c/src/rmw_microxrcedds_topic.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ create_topic(
6666

6767
topic_req = uxr_buffer_create_topic_ref(
6868
&custom_node->context->session,
69-
*custom_node->context->creation_destroy_stream, custom_topic->topic_id,
69+
*custom_node->context->creation_stream, custom_topic->topic_id,
7070
custom_node->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
7171
#else
7272
static char full_topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
@@ -77,7 +77,7 @@ create_topic(
7777

7878
topic_req = uxr_buffer_create_topic_bin(
7979
&custom_node->context->session,
80-
*custom_node->context->creation_destroy_stream,
80+
*custom_node->context->creation_stream,
8181
custom_topic->topic_id,
8282
custom_node->participant_id,
8383
full_topic_name,
@@ -86,7 +86,7 @@ create_topic(
8686
#endif /* ifdef RMW_UXRCE_USE_XML */
8787

8888
if (!run_xrce_session(
89-
custom_node->context, topic_req,
89+
custom_node->context, custom_node->context->creation_stream, topic_req,
9090
custom_node->context->creation_timeout))
9191
{
9292
rmw_uxrce_fini_topic_memory(custom_topic);
@@ -107,11 +107,11 @@ rmw_ret_t destroy_topic(
107107

108108
uint16_t delete_topic = uxr_buffer_delete_entity(
109109
&custom_node->context->session,
110-
*custom_node->context->creation_destroy_stream,
110+
*custom_node->context->destroy_stream,
111111
topic->topic_id);
112112

113113
if (!run_xrce_session(
114-
custom_node->context, delete_topic,
114+
custom_node->context, custom_node->context->destroy_stream, delete_topic,
115115
custom_node->context->destroy_timeout))
116116
{
117117
result_ret = RMW_RET_TIMEOUT;

rmw_microxrcedds_c/src/rmw_node.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ rmw_node_t * create_node(
8686
}
8787
participant_req = uxr_buffer_create_participant_ref(
8888
&custom_node->context->session,
89-
*custom_node->context->creation_destroy_stream,
89+
*custom_node->context->creation_stream,
9090
custom_node->participant_id,
9191
(uint16_t)domain_id,
9292
rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
@@ -101,15 +101,15 @@ rmw_node_t * create_node(
101101

102102
participant_req = uxr_buffer_create_participant_bin(
103103
&custom_node->context->session,
104-
*custom_node->context->creation_destroy_stream,
104+
*custom_node->context->creation_stream,
105105
custom_node->participant_id,
106106
domain_id,
107107
xrce_node_name,
108108
UXR_REPLACE | UXR_REUSE);
109109
#endif /* ifdef RMW_UXRCE_USE_REFS */
110110

111111
if (!run_xrce_session(
112-
custom_node->context, participant_req,
112+
custom_node->context, custom_node->context->creation_stream, participant_req,
113113
custom_node->context->creation_timeout))
114114
{
115115
rmw_uxrce_fini_node_memory(node_handle);
@@ -211,11 +211,11 @@ rmw_ret_t rmw_destroy_node(
211211

212212
uint16_t delete_participant = uxr_buffer_delete_entity(
213213
&custom_node->context->session,
214-
*custom_node->context->creation_destroy_stream,
214+
*custom_node->context->destroy_stream,
215215
custom_node->participant_id);
216216

217217
if (!run_xrce_session(
218-
custom_node->context, delete_participant,
218+
custom_node->context, custom_node->context->destroy_stream, delete_participant,
219219
custom_node->context->destroy_timeout))
220220
{
221221
ret = RMW_RET_TIMEOUT;

rmw_microxrcedds_c/src/rmw_publisher.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,20 @@ rmw_create_publisher(
155155
#ifdef RMW_UXRCE_USE_REFS
156156
publisher_req = uxr_buffer_create_publisher_xml(
157157
&custom_publisher->owner_node->context->session,
158-
*custom_node->context->creation_destroy_stream,
158+
*custom_node->context->creation_stream,
159159
custom_publisher->publisher_id,
160160
custom_node->participant_id, "", UXR_REPLACE | UXR_REUSE);
161161
#else
162162
publisher_req = uxr_buffer_create_publisher_bin(
163163
&custom_publisher->owner_node->context->session,
164-
*custom_node->context->creation_destroy_stream,
164+
*custom_node->context->creation_stream,
165165
custom_publisher->publisher_id,
166166
custom_node->participant_id,
167167
UXR_REPLACE | UXR_REUSE);
168168
#endif /* ifdef RMW_UXRCE_USE_REFS */
169169

170170
if (!run_xrce_session(
171-
custom_node->context, publisher_req,
171+
custom_node->context, custom_node->context->creation_stream, publisher_req,
172172
custom_node->context->creation_timeout))
173173
{
174174
put_memory(&publisher_memory, &custom_publisher->mem);
@@ -194,7 +194,7 @@ rmw_create_publisher(
194194

195195
datawriter_req = uxr_buffer_create_datawriter_ref(
196196
&custom_publisher->owner_node->context->session,
197-
*custom_node->context->creation_destroy_stream,
197+
*custom_node->context->creation_stream,
198198
custom_publisher->datawriter_id,
199199
custom_publisher->publisher_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE | UXR_REUSE);
200200
#else
@@ -217,7 +217,7 @@ rmw_create_publisher(
217217

218218
datawriter_req = uxr_buffer_create_datawriter_bin(
219219
&custom_publisher->owner_node->context->session,
220-
*custom_node->context->creation_destroy_stream,
220+
*custom_node->context->creation_stream,
221221
custom_publisher->datawriter_id,
222222
custom_publisher->publisher_id,
223223
custom_publisher->topic->topic_id,
@@ -229,7 +229,7 @@ rmw_create_publisher(
229229
#endif /* ifdef RMW_UXRCE_USE_REFS */
230230

231231
if (!run_xrce_session(
232-
custom_node->context, datawriter_req,
232+
custom_node->context, custom_node->context->creation_stream, datawriter_req,
233233
custom_node->context->creation_timeout))
234234
{
235235
put_memory(&publisher_memory, &custom_publisher->mem);
@@ -367,18 +367,18 @@ rmw_destroy_publisher(
367367

368368
uint16_t delete_writer = uxr_buffer_delete_entity(
369369
&custom_publisher->owner_node->context->session,
370-
*custom_publisher->owner_node->context->creation_destroy_stream,
370+
*custom_publisher->owner_node->context->destroy_stream,
371371
custom_publisher->datawriter_id);
372372
uint16_t delete_publisher = uxr_buffer_delete_entity(
373373
&custom_publisher->owner_node->context->session,
374-
*custom_publisher->owner_node->context->creation_destroy_stream,
374+
*custom_publisher->owner_node->context->destroy_stream,
375375
custom_publisher->publisher_id);
376376

377377
bool ret = run_xrce_session(
378-
custom_node->context, delete_writer,
378+
custom_node->context, custom_node->context->destroy_stream, delete_writer,
379379
custom_node->context->destroy_timeout);
380380
ret &= run_xrce_session(
381-
custom_node->context, delete_publisher,
381+
custom_node->context, custom_node->context->destroy_stream, delete_publisher,
382382
custom_node->context->destroy_timeout);
383383
if (!ret) {
384384
result_ret = RMW_RET_TIMEOUT;

0 commit comments

Comments
 (0)