Skip to content

Commit fb6a063

Browse files
Static operation (backport #184) (#189)
* 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: # rmw_microxrcedds_c/src/rmw_microros_internal/types.h * Solve conflicts Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
1 parent 125ed1c commit fb6a063

22 files changed

Lines changed: 278 additions & 162 deletions

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ All the configurable parameters are:
4141
| RMW_UXRCE_MAX_SERVICES | This value sets the maximum number of services for an application. | 4 |
4242
| RMW_UXRCE_MAX_CLIENTS | This value sets the maximum number of clients for an application. | 4 |
4343
| RMW_UXRCE_MAX_TOPICS | This value sets the maximum number of topics for an application. </br> If set to -1 RMW_UXRCE_MAX_TOPICS = RMW_UXRCE_MAX_PUBLISHERS + </br> RMW_UXRCE_MAX_SUBSCRIPTIONS + RMW_UXRCE_MAX_NODES. | -1 |
44-
| RMW_UXRCE_NODE_NAME_MAX_LENGTH | This value sets the maximum number of characters for a node name. | 128 |
45-
| RMW_UXRCE_TOPIC_NAME_MAX_LENGTH | This value sets the maximum number of characters for a topic name. | 100 |
46-
| RMW_UXRCE_TYPE_NAME_MAX_LENGTH | This value sets the maximum number of characters for a type name. | 128 |
44+
| RMW_UXRCE_MAX_WAIT_SETS | This value sets the maximum number of wait sets for an application. | 4 |
45+
| RMW_UXRCE_MAX_GUARD_CONDITION | This value sets the maximum number of guard conditions for an application. | 4 |
46+
| RMW_UXRCE_NODE_NAME_MAX_LENGTH | This value sets the maximum number of characters for a node name. | 60 |
47+
| RMW_UXRCE_TOPIC_NAME_MAX_LENGTH | This value sets the maximum number of characters for a topic name. | 60 |
48+
| RMW_UXRCE_TYPE_NAME_MAX_LENGTH | This value sets the maximum number of characters for a type name. | 100 |
4749
| RMW_UXRCE_REF_BUFFER_LENGTH | This value sets the maximum number of characters for a reference buffer. | 100 |
4850
| 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 |
4951
| 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 |

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ set(RMW_UXRCE_MAX_PUBLISHERS "4" CACHE STRING "This value sets the maximum numbe
5252
set(RMW_UXRCE_MAX_SUBSCRIPTIONS "4" CACHE STRING "This value sets the maximum number of subscriptions for an application.")
5353
set(RMW_UXRCE_MAX_SERVICES "4" CACHE STRING "This value sets the maximum number of services for an application.")
5454
set(RMW_UXRCE_MAX_CLIENTS "4" CACHE STRING "This value sets the maximum number of clients for an application.")
55+
set(RMW_UXRCE_MAX_WAIT_SETS "4" CACHE STRING "This value sets the maximum number of wait sets for an application.")
56+
set(RMW_UXRCE_MAX_GUARD_CONDITION "4" CACHE STRING "This value sets the maximum number of guard conditions for an application.")
5557
set(RMW_UXRCE_MAX_TOPICS "-1" CACHE STRING
5658
"This value sets the maximum number of topics for an application.
5759
If set to -1 RMW_UXRCE_MAX_TOPICS = RMW_UXRCE_MAX_PUBLISHERS + RMW_UXRCE_MAX_SUBSCRIPTIONS + RMW_UXRCE_MAX_NODES.")
5860
option(RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS "Enables increasing static pools with dynamic allocation when needed." OFF)
59-
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a node name.")
60-
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
61-
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
61+
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a node name.")
62+
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "60" CACHE STRING "This value sets the maximum number of characters for a topic name.")
63+
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a type name.")
6264
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
6365
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING
6466
"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
@@ -58,7 +58,17 @@ rmw_init_options_init(
5858
init_options->security_options = rmw_get_default_security_options();
5959
init_options->localhost_only = RMW_LOCALHOST_ONLY_DEFAULT;
6060

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

6373
#if defined(RMW_UXRCE_TRANSPORT_SERIAL)
6474
if (strlen(RMW_UXRCE_DEFAULT_SERIAL_DEVICE) <= MAX_SERIAL_DEVICE) {
@@ -127,8 +137,18 @@ rmw_init_options_copy(
127137
return RMW_RET_INVALID_ARGUMENT;
128138
}
129139
memcpy(dst, src, sizeof(rmw_init_options_t));
130-
dst->impl = rmw_allocate(sizeof(rmw_init_options_impl_t));
131-
memcpy(dst->impl, src->impl, sizeof(rmw_init_options_impl_t));
140+
141+
rmw_uxrce_mempool_item_t * memory_node = get_memory(&init_options_memory);
142+
if (!memory_node) {
143+
RMW_SET_ERROR_MSG("Not available memory node");
144+
return RMW_RET_ERROR;
145+
}
146+
dst->impl = memory_node->data;
147+
148+
rmw_uxrce_init_options_impl_t * dst_impl = dst->impl;
149+
rmw_uxrce_init_options_impl_t * src_impl = src->impl;
150+
151+
dst_impl->transport_params = src_impl->transport_params;
132152

133153
return RMW_RET_OK;
134154
}
@@ -145,9 +165,25 @@ rmw_init_options_fini(
145165
eprosima_microxrcedds_identifier,
146166
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
147167

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

150185
*init_options = rmw_get_zero_initialized_init_options();
186+
151187
return RMW_RET_OK;
152188
}
153189

@@ -226,6 +262,13 @@ rmw_init(
226262
rmw_uxrce_init_service_memory(&service_memory, custom_services, RMW_UXRCE_MAX_SERVICES);
227263
rmw_uxrce_init_client_memory(&client_memory, custom_clients, RMW_UXRCE_MAX_CLIENTS);
228264
rmw_uxrce_init_topic_memory(&topics_memory, custom_topics, RMW_UXRCE_MAX_TOPICS_INTERNAL);
265+
rmw_uxrce_init_init_options_impl_memory(
266+
&init_options_memory, custom_init_options,
267+
RMW_UXRCE_MAX_OPTIONS);
268+
rmw_uxrce_init_wait_set_memory(&wait_set_memory, custom_wait_set, RMW_UXRCE_MAX_WAIT_SETS);
269+
rmw_uxrce_init_guard_condition_memory(
270+
&guard_condition_memory, custom_guard_condition,
271+
RMW_UXRCE_MAX_GUARD_CONDITION);
229272

230273
// Micro-XRCE-DDS Client transport initialization
231274
rmw_ret_t transport_init_ret = rmw_uxrce_transport_init(
@@ -260,6 +303,8 @@ rmw_init(
260303

261304
if (!uxr_create_session(&context_impl->session)) {
262305
CLOSE_TRANSPORT(&context_impl->transport);
306+
put_memory(&session_memory, &context_impl->mem);
307+
context->impl = NULL;
263308
RMW_SET_ERROR_MSG("failed to create node session on Micro ROS Agent.");
264309
return RMW_RET_ERROR;
265310
}
@@ -307,7 +352,6 @@ rmw_ret_t
307352
rmw_context_fini(
308353
rmw_context_t * context)
309354
{
310-
// TODO(pablogs9): Should we manage not closed XRCE sessions?
311355
rmw_ret_t ret = RMW_RET_OK;
312356

313357
rmw_uxrce_mempool_item_t * item = node_memory.allocateditems;
@@ -316,7 +360,7 @@ rmw_context_fini(
316360
rmw_uxrce_node_t * custom_node = (rmw_uxrce_node_t *)item->data;
317361
item = item->next;
318362
if (custom_node->context == context->impl) {
319-
ret = rmw_destroy_node(custom_node->rmw_handle);
363+
ret = rmw_destroy_node(&custom_node->rmw_node);
320364
}
321365
}
322366

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)