Skip to content

Commit 233e683

Browse files
Static operation (backport #184) (#190)
* Static operation (#184) * Static RMW operation * Uncrustify * Remove rmw_handle * Update tests * Update size calculator * Update * Add guard_condition init * Add define for rmw_options size * Update custom_guard_condition init * Fix func name Co-authored-by: Antonio Cuadros <acuadros1995@gmail.com> Co-authored-by: Antonio Cuadros <49162117+Acuadros95@users.noreply.github.com> (cherry picked from commit cb4f522) # Conflicts: # README.md # rmw_microxrcedds_c/CMakeLists.txt * Fix conflicts Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
1 parent 276ae8e commit 233e683

21 files changed

Lines changed: 276 additions & 160 deletions

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ set(RMW_UXRCE_MAX_PUBLISHERS "4" CACHE STRING "This value sets the maximum numbe
5151
set(RMW_UXRCE_MAX_SUBSCRIPTIONS "4" CACHE STRING "This value sets the maximum number of subscriptions for an application.")
5252
set(RMW_UXRCE_MAX_SERVICES "4" CACHE STRING "This value sets the maximum number of services for an application.")
5353
set(RMW_UXRCE_MAX_CLIENTS "4" CACHE STRING "This value sets the maximum number of clients for an application.")
54-
set(RMW_UXRCE_MAX_TOPICS "-1" CACHE STRING "This value sets the maximum number of topics for an application. If set to -1 RMW_UXRCE_MAX_TOPICS = RMW_UXRCE_MAX_PUBLISHERS + RMW_UXRCE_MAX_SUBSCRIPTIONS + RMW_UXRCE_MAX_NODES.")
54+
set(RMW_UXRCE_MAX_WAIT_SETS "4" CACHE STRING "This value sets the maximum number of wait sets for an application.")
55+
set(RMW_UXRCE_MAX_GUARD_CONDITION "4" CACHE STRING "This value sets the maximum number of guard conditions for an application.")
56+
set(RMW_UXRCE_MAX_TOPICS "-1" CACHE STRING
57+
"This value sets the maximum number of topics for an application.
58+
If set to -1 RMW_UXRCE_MAX_TOPICS = RMW_UXRCE_MAX_PUBLISHERS + RMW_UXRCE_MAX_SUBSCRIPTIONS + RMW_UXRCE_MAX_NODES.")
5559
option(RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS "Enables increasing static pools with dynamic allocation when needed." OFF)
56-
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a node name.")
57-
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
58-
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
60+
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a node name.")
61+
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a topic name.")
62+
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a type name.")
5963
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
6064
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
6165
"This value sets the default time to wait for a publication in a reliable mode in milliseconds.")

rmw_microxrcedds_c/src/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@
5050
#define RMW_UXRCE_MAX_OUTPUT_BUFFER_SIZE (RMW_UXRCE_MAX_TRANSPORT_MTU * RMW_UXRCE_STREAM_HISTORY_OUTPUT)
5151

5252
#define RMW_UXRCE_MAX_SESSIONS @RMW_UXRCE_MAX_SESSIONS@
53+
#define RMW_UXRCE_MAX_OPTIONS RMW_UXRCE_MAX_SESSIONS + 1
5354
#define RMW_UXRCE_MAX_NODES @RMW_UXRCE_MAX_NODES@
5455
#define RMW_UXRCE_MAX_PUBLISHERS @RMW_UXRCE_MAX_PUBLISHERS@
5556
#define RMW_UXRCE_MAX_SUBSCRIPTIONS @RMW_UXRCE_MAX_SUBSCRIPTIONS@
5657
#define RMW_UXRCE_MAX_SERVICES @RMW_UXRCE_MAX_SERVICES@
5758
#define RMW_UXRCE_MAX_CLIENTS @RMW_UXRCE_MAX_CLIENTS@
5859
#define RMW_UXRCE_MAX_TOPICS @RMW_UXRCE_MAX_TOPICS@
60+
#define RMW_UXRCE_MAX_WAIT_SETS @RMW_UXRCE_MAX_WAIT_SETS@
61+
#define RMW_UXRCE_MAX_GUARD_CONDITION @RMW_UXRCE_MAX_GUARD_CONDITION@
5962

6063
#if RMW_UXRCE_MAX_TOPICS == -1
6164
#define RMW_UXRCE_MAX_TOPICS_INTERNAL RMW_UXRCE_MAX_PUBLISHERS + RMW_UXRCE_MAX_SUBSCRIPTIONS

rmw_microxrcedds_c/src/rmw_client.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,25 @@ rmw_create_client(
4545
} else if (!qos_policies) {
4646
RMW_SET_ERROR_MSG("qos_profile is null");
4747
} else {
48-
rmw_client = (rmw_client_t *)rmw_allocate(
49-
sizeof(rmw_client_t));
50-
rmw_client->data = NULL;
51-
rmw_client->implementation_identifier = rmw_get_implementation_identifier();
52-
53-
rmw_client->service_name = (const char *)(rmw_allocate(
54-
sizeof(char) * (strlen(
55-
service_name) + 1)));
56-
if (!rmw_client->service_name) {
57-
RMW_SET_ERROR_MSG("failed to allocate memory");
58-
goto fail;
59-
}
60-
memcpy((void *)rmw_client->service_name, service_name, strlen(service_name) + 1);
61-
6248
rmw_uxrce_node_t * custom_node = (rmw_uxrce_node_t *)node->data;
6349
rmw_uxrce_mempool_item_t * memory_node = get_memory(&client_memory);
6450
if (!memory_node) {
6551
RMW_SET_ERROR_MSG("Not available memory node");
52+
return NULL;
53+
}
54+
rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t *)memory_node->data;
55+
56+
rmw_client = &custom_client->rmw_client;
57+
rmw_client->data = NULL;
58+
rmw_client->implementation_identifier = rmw_get_implementation_identifier();
59+
rmw_client->service_name = custom_client->service_name;
60+
if ((strlen(service_name) + 1 ) > sizeof(custom_client->service_name)) {
61+
RMW_SET_ERROR_MSG("failed to allocate string");
6662
goto fail;
6763
}
6864

69-
rmw_uxrce_client_t * custom_client = (rmw_uxrce_client_t *)memory_node->data;
70-
custom_client->rmw_handle = rmw_client;
65+
memcpy((void *)rmw_client->service_name, service_name, strlen(service_name) + 1);
66+
7167
custom_client->owner_node = custom_node;
7268
custom_client->session_timeout = RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT;
7369
custom_client->qos = *qos_policies;

rmw_microxrcedds_c/src/rmw_guard_condition.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,36 @@ rmw_create_guard_condition(
2323
{
2424
(void)context;
2525

26-
rmw_guard_condition_t * rmw_guard_condition = (rmw_guard_condition_t *)rmw_allocate(
27-
sizeof(rmw_guard_condition_t));
28-
29-
rmw_guard_condition->context = context;
30-
rmw_guard_condition->implementation_identifier = rmw_get_implementation_identifier();
31-
rmw_guard_condition->data = (bool *)rmw_allocate(sizeof(bool));
32-
33-
bool * hasTriggered = (bool *)rmw_guard_condition->data;
34-
*hasTriggered = false;
35-
36-
return rmw_guard_condition;
26+
rmw_uxrce_mempool_item_t * memory_node = get_memory(&guard_condition_memory);
27+
if (!memory_node) {
28+
RMW_SET_ERROR_MSG("Not available memory node");
29+
return NULL;
30+
}
31+
rmw_uxrce_guard_condition_t * custom_guard_condition =
32+
(rmw_uxrce_guard_condition_t *)memory_node->data;
33+
custom_guard_condition->hasTriggered = false;
34+
custom_guard_condition->rmw_guard_condition.context = context;
35+
custom_guard_condition->rmw_guard_condition.implementation_identifier =
36+
rmw_get_implementation_identifier();
37+
38+
return &custom_guard_condition->rmw_guard_condition;
3739
}
3840

3941
rmw_ret_t
4042
rmw_destroy_guard_condition(
4143
rmw_guard_condition_t * guard_condition)
4244
{
43-
rmw_free(guard_condition);
44-
45-
return RMW_RET_OK;
45+
rmw_uxrce_mempool_item_t * item = guard_condition_memory.allocateditems;
46+
47+
while (NULL != item) {
48+
rmw_uxrce_guard_condition_t * custom_guard_condition =
49+
(rmw_uxrce_guard_condition_t *)item->data;
50+
if (&custom_guard_condition->rmw_guard_condition == guard_condition) {
51+
put_memory(&guard_condition_memory, item);
52+
return RMW_RET_OK;
53+
}
54+
item = item->next;
55+
}
56+
57+
return RMW_RET_ERROR;
4658
}

rmw_microxrcedds_c/src/rmw_init.c

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ rmw_init_options_init(
5555
init_options->allocator = allocator;
5656
init_options->enclave = "/";
5757

58-
init_options->impl = allocator.allocate(sizeof(rmw_init_options_impl_t), allocator.state);
58+
// This can be call before rmw_init()
59+
rmw_uxrce_init_init_options_impl_memory(
60+
&init_options_memory, custom_init_options,
61+
RMW_UXRCE_MAX_OPTIONS);
62+
63+
rmw_uxrce_mempool_item_t * memory_node = get_memory(&init_options_memory);
64+
if (!memory_node) {
65+
RMW_SET_ERROR_MSG("Not available memory node");
66+
return RMW_RET_ERROR;
67+
}
68+
init_options->impl = memory_node->data;
5969

6070
#if defined(RMW_UXRCE_TRANSPORT_SERIAL)
6171
if (strlen(RMW_UXRCE_DEFAULT_SERIAL_DEVICE) <= MAX_SERIAL_DEVICE) {
@@ -124,8 +134,18 @@ rmw_init_options_copy(
124134
return RMW_RET_INVALID_ARGUMENT;
125135
}
126136
memcpy(dst, src, sizeof(rmw_init_options_t));
127-
dst->impl = rmw_allocate(sizeof(rmw_init_options_impl_t));
128-
memcpy(dst->impl, src->impl, sizeof(rmw_init_options_impl_t));
137+
138+
rmw_uxrce_mempool_item_t * memory_node = get_memory(&init_options_memory);
139+
if (!memory_node) {
140+
RMW_SET_ERROR_MSG("Not available memory node");
141+
return RMW_RET_ERROR;
142+
}
143+
dst->impl = memory_node->data;
144+
145+
rmw_uxrce_init_options_impl_t * dst_impl = dst->impl;
146+
rmw_uxrce_init_options_impl_t * src_impl = src->impl;
147+
148+
dst_impl->transport_params = src_impl->transport_params;
129149

130150
return RMW_RET_OK;
131151
}
@@ -142,9 +162,25 @@ rmw_init_options_fini(
142162
eprosima_microxrcedds_identifier,
143163
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
144164

145-
rmw_free(init_options->impl);
165+
rmw_uxrce_mempool_item_t * item = init_options_memory.allocateditems;
166+
167+
while (NULL != item) {
168+
rmw_uxrce_init_options_impl_t * custom_init_options =
169+
(rmw_uxrce_init_options_impl_t *)item->data;
170+
if (custom_init_options == init_options->impl) {
171+
put_memory(&init_options_memory, item);
172+
break;
173+
}
174+
item = item->next;
175+
}
176+
177+
if (NULL == item) {
178+
return RMW_RET_ERROR;
179+
}
180+
146181

147182
*init_options = rmw_get_zero_initialized_init_options();
183+
148184
return RMW_RET_OK;
149185
}
150186

@@ -222,6 +258,13 @@ rmw_init(
222258
rmw_uxrce_init_service_memory(&service_memory, custom_services, RMW_UXRCE_MAX_SERVICES);
223259
rmw_uxrce_init_client_memory(&client_memory, custom_clients, RMW_UXRCE_MAX_CLIENTS);
224260
rmw_uxrce_init_topic_memory(&topics_memory, custom_topics, RMW_UXRCE_MAX_TOPICS_INTERNAL);
261+
rmw_uxrce_init_init_options_impl_memory(
262+
&init_options_memory, custom_init_options,
263+
RMW_UXRCE_MAX_OPTIONS);
264+
rmw_uxrce_init_wait_set_memory(&wait_set_memory, custom_wait_set, RMW_UXRCE_MAX_WAIT_SETS);
265+
rmw_uxrce_init_guard_condition_memory(
266+
&guard_condition_memory, custom_guard_condition,
267+
RMW_UXRCE_MAX_GUARD_CONDITION);
225268

226269
// Micro-XRCE-DDS Client transport initialization
227270
rmw_ret_t transport_init_ret = rmw_uxrce_transport_init(
@@ -256,6 +299,8 @@ rmw_init(
256299

257300
if (!uxr_create_session(&context_impl->session)) {
258301
CLOSE_TRANSPORT(&context_impl->transport);
302+
put_memory(&session_memory, &context_impl->mem);
303+
context->impl = NULL;
259304
RMW_SET_ERROR_MSG("failed to create node session on Micro ROS Agent.");
260305
return RMW_RET_ERROR;
261306
}
@@ -303,7 +348,6 @@ rmw_ret_t
303348
rmw_context_fini(
304349
rmw_context_t * context)
305350
{
306-
// TODO(pablogs9): Should we manage not closed XRCE sessions?
307351
rmw_ret_t ret = RMW_RET_OK;
308352

309353
rmw_uxrce_mempool_item_t * item = node_memory.allocateditems;
@@ -312,7 +356,7 @@ rmw_context_fini(
312356
rmw_uxrce_node_t * custom_node = (rmw_uxrce_node_t *)item->data;
313357
item = item->next;
314358
if (custom_node->context == context->impl) {
315-
ret = rmw_destroy_node(custom_node->rmw_handle);
359+
ret = rmw_destroy_node(&custom_node->rmw_node);
316360
}
317361
}
318362

rmw_microxrcedds_c/src/rmw_microros/init_options.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ rmw_ret_t rmw_uros_init_options(
3030
return RMW_RET_INVALID_ARGUMENT;
3131
}
3232
rmw_ret_t ret = RMW_RET_OK;
33-
// TODO(pablogs9): Is the impl allocated at this point?
34-
// rmw_options->impl = rmw_options->allocator.allocate(
35-
// sizeof(rmw_init_options_impl_t),
36-
// rmw_options->allocator.state);
3733
#if defined(RMW_UXRCE_TRANSPORT_SERIAL)
3834
if (argc >= 2) {
3935
snprintf(rmw_options->impl->transport_params.serial_device, MAX_SERIAL_DEVICE, "%s", argv[1]);

rmw_microxrcedds_c/src/rmw_microros_internal/rmw_uxrce_transports.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*/
4848
rmw_ret_t rmw_uxrce_transport_init(
4949
rmw_context_impl_t * context,
50-
rmw_init_options_impl_t * init_options,
50+
rmw_uxrce_init_options_impl_t * init_options,
5151
void * override_transport);
5252

5353
/**

0 commit comments

Comments
 (0)