Skip to content

Commit 125ed1c

Browse files
Separate creation & destroy entities streams (#185) (#187)
* 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) Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
1 parent a02f895 commit 125ed1c

14 files changed

Lines changed: 96 additions & 63 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ All the configurable parameters are:
4545
| RMW_UXRCE_TOPIC_NAME_MAX_LENGTH | This value sets the maximum number of characters for a topic name. | 100 |
4646
| RMW_UXRCE_TYPE_NAME_MAX_LENGTH | This value sets the maximum number of characters for a type name. | 128 |
4747
| RMW_UXRCE_REF_BUFFER_LENGTH | This value sets the maximum number of characters for a reference buffer. | 100 |
48-
| RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT | This value sets the maximum time to wait for an XRCE entity creation </br> and destroy in milliseconds. If set to 0 best effort is used. | 1000 |
48+
| RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT | This value sets the default maximum time to wait for an XRCE entity creation </br> and destroy in milliseconds. If set to 0 best effort is used. | 1000 |
49+
| RMW_UXRCE_ENTITY_CREATION_TIMEOUT | This value sets the maximum time to wait for an XRCE entity creation </br> in milliseconds. If set to 0 best effort is used. | 1000 |
50+
| RMW_UXRCE_ENTITY_DESTROY_TIMEOUT | This value sets the maximum time to wait for an XRCE entity destroy </br> in milliseconds. If set to 0 best effort is used. | 1000 |
4951
| RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT | This value sets the default time to wait for a publication in a </br> reliable mode in milliseconds. | 1000 |
5052
| RMW_UXRCE_STREAM_HISTORY | This value sets the number of MTUs to buffer, both input and output. | 4 |
5153
| RMW_UXRCE_STREAM_HISTORY_INPUT | This value sets the number of MTUs to input buffer. </br> It will be ignored if RMW_UXRCE_STREAM_HISTORY_OUTPUT is blank. | - |

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,27 @@ set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maxim
6060
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
6161
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
6262
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
63-
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING
64-
"This value sets the maximum time to wait for an XRCE entity creation and destroy in milliseconds.
65-
If set to 0 best effort is used.")
6663
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
6764
"This value sets the default time to wait for a publication in a reliable mode in milliseconds.")
6865

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

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
@@ -193,8 +193,16 @@ rmw_init(
193193
options->impl->transport_params.read_cb);
194194
#endif // RMW_UXRCE_TRANSPORT_CUSTOM
195195

196-
context_impl->creation_timeout = RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT;
197-
context_impl->destroy_timeout = RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT;
196+
context_impl->creation_timeout = RMW_UXRCE_ENTITY_CREATION_TIMEOUT;
197+
context_impl->destroy_timeout = RMW_UXRCE_ENTITY_DESTROY_TIMEOUT;
198+
199+
context_impl->creation_stream = (RMW_UXRCE_ENTITY_CREATION_TIMEOUT > 0) ?
200+
&context_impl->reliable_output :
201+
&context_impl->best_effort_output;
202+
203+
context_impl->destroy_stream = (RMW_UXRCE_ENTITY_DESTROY_TIMEOUT > 0) ?
204+
&context_impl->reliable_output :
205+
&context_impl->best_effort_output;
198206

199207
context_impl->id_participant = 0;
200208
context_impl->id_topic = 0;
@@ -250,10 +258,6 @@ rmw_init(
250258
&context_impl->session,
251259
context_impl->output_best_effort_stream_buffer, context_impl->transport.comm.mtu);
252260

253-
context_impl->creation_destroy_stream = (RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT > 0) ?
254-
&context_impl->reliable_output :
255-
&context_impl->best_effort_output;
256-
257261
if (!uxr_create_session(&context_impl->session)) {
258262
CLOSE_TRANSPORT(&context_impl->transport);
259263
RMW_SET_ERROR_MSG("failed to create node session on Micro ROS Agent.");
@@ -317,7 +321,14 @@ rmw_context_fini(
317321
}
318322

319323
if (NULL != context->impl) {
320-
uxr_delete_session(&context->impl->session);
324+
size_t retries = UXR_CONFIG_MAX_SESSION_CONNECTION_ATTEMPTS;
325+
326+
rmw_context_impl_t * context_impl = context->impl;
327+
if (context_impl->destroy_stream->type == UXR_BEST_EFFORT_STREAM) {
328+
retries = 0;
329+
}
330+
331+
uxr_delete_session_retries(&context->impl->session, retries);
321332
rmw_uxrce_fini_session_memory(context->impl);
322333
CLOSE_TRANSPORT(&context->impl->transport);
323334
}

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 @@ struct rmw_context_impl_s
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);
@@ -207,11 +207,11 @@ rmw_ret_t rmw_destroy_node(
207207

208208
uint16_t delete_participant = uxr_buffer_delete_entity(
209209
&custom_node->context->session,
210-
*custom_node->context->creation_destroy_stream,
210+
*custom_node->context->destroy_stream,
211211
custom_node->participant_id);
212212

213213
if (!run_xrce_session(
214-
custom_node->context, delete_participant,
214+
custom_node->context, custom_node->context->destroy_stream, delete_participant,
215215
custom_node->context->destroy_timeout))
216216
{
217217
ret = RMW_RET_TIMEOUT;

0 commit comments

Comments
 (0)