Skip to content

Commit 1b5a2bc

Browse files
authored
Add Binary entity creation mode (#123)
* Initial Init Update Update * Update branch * Update API * Update * Update * Uncrustified * Apply suggestions from code review * Update Co-authored-by: GitHub Actions Bot <>
1 parent 43371c9 commit 1b5a2bc

13 files changed

Lines changed: 248 additions & 197 deletions

rmw_microxrcedds_c/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ option(RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS "Enables increasing static pools with
5454
set(RMW_UXRCE_NODE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a node name.")
5555
set(RMW_UXRCE_TOPIC_NAME_MAX_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a topic name.")
5656
set(RMW_UXRCE_TYPE_NAME_MAX_LENGTH "128" CACHE STRING "This value sets the maximum number of characters for a type name.")
57-
set(RMW_UXRCE_XML_BUFFER_LENGTH "600" CACHE STRING "This value sets the maximum number of characters for a XML buffer.")
5857
set(RMW_UXRCE_REF_BUFFER_LENGTH "100" CACHE STRING "This value sets the maximum number of characters for a reference buffer.")
5958
set(RMW_UXRCE_ENTITY_CREATION_DESTROY_TIMEOUT "1000" CACHE STRING "This value sets the maximum time to wait for an XRCE entity creation and destroy in milliseconds. If set to 0 best effort is used.")
6059
set(RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT "1000" CACHE STRING "This value sets the maximum time to wait for a publication in a reliable mode in milliseconds.")
@@ -97,13 +96,8 @@ endif()
9796

9897
# Create entities type define macros.
9998
set(RMW_UXRCE_USE_REFS OFF)
100-
set(RMW_UXRCE_USE_XML OFF)
10199
if(${RMW_UXRCE_CREATION_MODE} STREQUAL "refs")
102100
set(RMW_UXRCE_USE_REFS ON)
103-
elseif(${RMW_UXRCE_CREATION_MODE} STREQUAL "xml")
104-
set(RMW_UXRCE_USE_XML ON)
105-
else()
106-
message(FATAL_ERROR "Creation mode not supported. Use \"refs\" or \"xml\"")
107101
endif()
108102

109103
# Create source files with the define

rmw_microxrcedds_c/src/config.h.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#cmakedefine RMW_UXRCE_TRANSPORT_IPV4
1010
#cmakedefine RMW_UXRCE_TRANSPORT_IPV6
1111
#cmakedefine RMW_UXRCE_USE_REFS
12-
#cmakedefine RMW_UXRCE_USE_XML
1312
#cmakedefine RMW_UXRCE_ALLOW_DYNAMIC_ALLOCATIONS
1413
#cmakedefine RMW_UXRCE_GRAPH
1514

@@ -61,10 +60,6 @@
6160
#define RMW_UXRCE_TOPIC_NAME_MAX_LENGTH @RMW_UXRCE_TOPIC_NAME_MAX_LENGTH@
6261
#define RMW_UXRCE_TYPE_NAME_MAX_LENGTH @RMW_UXRCE_TYPE_NAME_MAX_LENGTH@
6362

64-
#if defined(RMW_UXRCE_USE_XML)
65-
#define RMW_UXRCE_ENTITY_NAMING_BUFFER_LENGTH @RMW_UXRCE_XML_BUFFER_LENGTH@
66-
#elif defined(RMW_UXRCE_USE_REFS)
6763
#define RMW_UXRCE_ENTITY_NAMING_BUFFER_LENGTH @RMW_UXRCE_REF_BUFFER_LENGTH@
68-
#endif
6964

7065
#endif // RMW_MICROXRCEDDS_CONFIG_H

rmw_microxrcedds_c/src/rmw_client.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ rmw_create_client(
8383

8484
rmw_uxrce_client_t* custom_client = (rmw_uxrce_client_t*)memory_node->data;
8585
custom_client->rmw_handle = rmw_client;
86-
8786
custom_client->owner_node = custom_node;
88-
custom_client->client_gid.implementation_identifier =
89-
rmw_get_implementation_identifier();
9087

9188
const rosidl_service_type_support_t* type_support_xrce = NULL;
9289
#ifdef ROSIDL_TYPESUPPORT_MICROXRCEDDS_C__IDENTIFIER_VALUE
@@ -114,24 +111,17 @@ rmw_create_client(
114111
RMW_SET_ERROR_MSG("type support data is NULL");
115112
goto fail;
116113
}
117-
else if (sizeof(uxrObjectId) > RMW_GID_STORAGE_SIZE)
118-
{
119-
RMW_SET_ERROR_MSG("Not enough memory for impl ids");
120-
goto fail;
121-
}
122-
123114

124115
custom_client->client_id =
125116
uxr_object_id(custom_node->context->id_requester++, UXR_REQUESTER_ID);
126117

127-
memset(custom_client->client_gid.data, 0, RMW_GID_STORAGE_SIZE);
128-
memcpy(
129-
custom_client->client_gid.data, &custom_client->client_id,
130-
sizeof(uxrObjectId));
131-
132118
uint16_t client_req = UXR_INVALID_REQUEST_ID;
133119

134-
#ifdef RMW_UXRCE_USE_XML
120+
#ifdef RMW_UXRCE_USE_REFS
121+
// TODO(pablogs9): Use here true references
122+
// client_req = uxr_buffer_create_replier_ref(&custom_node->context->session,
123+
// *custom_node->context->creation_destroy_stream, custom_service->subscriber_id,
124+
// custom_node->participant_id, "", UXR_REPLACE);
135125
char service_name_id[20];
136126
generate_name(&custom_client->client_id, service_name_id, sizeof(service_name_id));
137127
if (!build_service_xml(
@@ -147,11 +137,27 @@ rmw_create_client(
147137
*custom_node->context->creation_destroy_stream,
148138
custom_client->client_id,
149139
custom_node->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
150-
#elif defined(RMW_UXRCE_USE_REFS)
151-
// TODO(pablogs9): Is possible to instantiate a replier by ref?
152-
// client_req = uxr_buffer_create_replier_ref(&custom_node->context->session,
153-
// *custom_node->context->creation_destroy_stream, custom_service->subscriber_id,
154-
// custom_node->participant_id, "", UXR_REPLACE);
140+
#else
141+
char req_type_name[RMW_UXRCE_TYPE_NAME_MAX_LENGTH];
142+
char res_type_name[RMW_UXRCE_TYPE_NAME_MAX_LENGTH];
143+
generate_service_types(custom_client->type_support_callbacks, req_type_name, res_type_name,
144+
RMW_UXRCE_TYPE_NAME_MAX_LENGTH);
145+
146+
char req_topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
147+
char res_topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
148+
generate_service_topics(service_name, req_topic_name, res_topic_name, RMW_UXRCE_TOPIC_NAME_MAX_LENGTH);
149+
150+
client_req = uxr_buffer_create_requester_bin(
151+
&custom_node->context->session,
152+
*custom_node->context->creation_destroy_stream,
153+
custom_client->client_id,
154+
custom_node->participant_id,
155+
(char*) service_name,
156+
req_type_name,
157+
res_type_name,
158+
req_topic_name,
159+
res_topic_name,
160+
UXR_REPLACE);
155161
#endif /* ifdef RMW_UXRCE_USE_XML */
156162

157163
rmw_client->data = custom_client;

rmw_microxrcedds_c/src/rmw_get_gid_for_publisher.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,19 @@ rmw_get_gid_for_publisher(
3333

3434
// Do
3535
rmw_uxrce_publisher_t* custom_publisher = (rmw_uxrce_publisher_t*)publisher->data;
36-
memcpy(gid, &custom_publisher->publisher_gid, sizeof(rmw_gid_t));
36+
37+
if (sizeof(uxrObjectId) > RMW_GID_STORAGE_SIZE)
38+
{
39+
RMW_SET_ERROR_MSG("Not enough memory for impl ids");
40+
return RMW_RET_ERROR;
41+
}
42+
43+
memset(gid->data, 0, RMW_GID_STORAGE_SIZE);
44+
memcpy(
45+
gid->data,
46+
&custom_publisher->publisher_id,
47+
sizeof(uxrObjectId));
48+
3749

3850
return RMW_RET_OK;
3951
}

rmw_microxrcedds_c/src/rmw_graph.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ rmw_ret_t rmw_graph_init(
5151
return RMW_RET_ERROR;
5252
}
5353

54-
uint16_t participant_req = uxr_buffer_create_participant_xml(
54+
uint16_t participant_req = uxr_buffer_create_participant_bin(
5555
&context->session,
5656
*context->creation_destroy_stream,
57-
graph_info->participant_id, (int16_t)microros_domain_id,
58-
rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
57+
graph_info->participant_id,
58+
(int16_t)microros_domain_id,
59+
UXR_REPLACE);
5960

6061
// Set graph subscription QoS policies
6162
// TODO (jamoralp): most of these QoS are not even being used.

rmw_microxrcedds_c/src/rmw_microxrcedds_topic.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ create_topic(
2929
const message_type_support_callbacks_t* message_type_support_callbacks,
3030
const rmw_qos_profile_t* qos_policies)
3131
{
32+
(void) qos_policies;
33+
3234
rmw_uxrce_topic_t* custom_topic = NULL;
3335
rmw_uxrce_mempool_item_t* memory_node = get_memory(&topics_memory);
3436

@@ -41,7 +43,6 @@ create_topic(
4143
custom_topic = (rmw_uxrce_topic_t*)memory_node->data;
4244

4345
// Init
44-
custom_topic->sync_with_agent = false;
4546
custom_topic->owner_node = custom_node;
4647

4748
// Asociate to typesupport
@@ -52,22 +53,7 @@ create_topic(
5253

5354
// Generate request
5455
uint16_t topic_req = 0;
55-
#ifdef RMW_UXRCE_USE_XML
56-
if (!build_topic_xml(
57-
topic_name, message_type_support_callbacks,
58-
qos_policies, rmw_uxrce_entity_naming_buffer, sizeof(rmw_uxrce_entity_naming_buffer)))
59-
{
60-
RMW_SET_ERROR_MSG("failed to generate xml request for subscriber creation");
61-
rmw_uxrce_fini_topic_memory(custom_topic);
62-
custom_topic = NULL;
63-
goto fail;
64-
}
65-
66-
topic_req = uxr_buffer_create_topic_xml(
67-
&custom_node->context->session,
68-
*custom_node->context->creation_destroy_stream, custom_topic->topic_id,
69-
custom_node->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
70-
#elif defined(RMW_UXRCE_USE_REFS)
56+
#ifdef RMW_UXRCE_USE_REFS
7157
(void)qos_policies;
7258
if (!build_topic_profile(topic_name, rmw_uxrce_entity_naming_buffer, sizeof(rmw_uxrce_entity_naming_buffer)))
7359
{
@@ -81,12 +67,24 @@ create_topic(
8167
&custom_node->context->session,
8268
*custom_node->context->creation_destroy_stream, custom_topic->topic_id,
8369
custom_node->participant_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
84-
#endif /* ifdef RMW_UXRCE_USE_XML */
70+
#else
71+
char full_topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
72+
char type_name[RMW_UXRCE_TYPE_NAME_MAX_LENGTH];
73+
74+
generate_topic_name(topic_name, full_topic_name, sizeof(full_topic_name));
75+
generate_type_name(message_type_support_callbacks, type_name, sizeof(type_name));
8576

86-
// Send the request and wait for response
87-
custom_topic->sync_with_agent = run_xrce_session(custom_node->context, topic_req);
77+
topic_req = uxr_buffer_create_topic_bin(
78+
&custom_node->context->session,
79+
*custom_node->context->creation_destroy_stream,
80+
custom_topic->topic_id,
81+
custom_node->participant_id,
82+
full_topic_name,
83+
type_name,
84+
UXR_REPLACE);
85+
#endif /* ifdef RMW_UXRCE_USE_XML */
8886

89-
if (!custom_topic->sync_with_agent)
87+
if (!run_xrce_session(custom_node->context, topic_req))
9088
{
9189
rmw_uxrce_fini_topic_memory(custom_topic);
9290
custom_topic = NULL;

rmw_microxrcedds_c/src/rmw_node.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,26 @@ rmw_node_t* create_node(
8484
uxr_object_id(node_info->context->id_participant++, UXR_PARTICIPANT_ID);
8585
uint16_t participant_req = UXR_INVALID_REQUEST_ID;
8686

87-
#ifdef RMW_UXRCE_USE_XML
88-
if (!build_participant_xml(domain_id, name, rmw_uxrce_entity_naming_buffer, sizeof(rmw_uxrce_entity_naming_buffer)))
87+
#ifdef RMW_UXRCE_USE_REFS
88+
if (!build_participant_profile(rmw_uxrce_entity_naming_buffer, sizeof(rmw_uxrce_entity_naming_buffer)))
8989
{
9090
RMW_SET_ERROR_MSG("failed to generate xml request for node creation");
9191
return NULL;
9292
}
93-
participant_req =
94-
uxr_buffer_create_participant_xml(
93+
participant_req = uxr_buffer_create_participant_ref(
9594
&node_info->context->session,
9695
*node_info->context->creation_destroy_stream,
97-
node_info->participant_id, (uint16_t)domain_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
98-
#elif defined(RMW_UXRCE_USE_REFS)
99-
if (!build_participant_profile(rmw_uxrce_entity_naming_buffer, sizeof(rmw_uxrce_entity_naming_buffer)))
100-
{
101-
RMW_SET_ERROR_MSG("failed to generate xml request for node creation");
102-
return NULL;
103-
}
104-
participant_req =
105-
uxr_buffer_create_participant_ref(
96+
node_info->participant_id,
97+
(uint16_t)domain_id,
98+
rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
99+
#else
100+
participant_req = uxr_buffer_create_participant_bin(
106101
&node_info->context->session,
107102
*node_info->context->creation_destroy_stream,
108-
node_info->participant_id, (uint16_t)domain_id, rmw_uxrce_entity_naming_buffer, UXR_REPLACE);
109-
#endif /* ifdef RMW_UXRCE_USE_XML */
103+
node_info->participant_id,
104+
domain_id,
105+
UXR_REPLACE);
106+
#endif /* ifdef RMW_UXRCE_USE_REFS */
110107

111108
if (!run_xrce_session(node_info->context, participant_req))
112109
{

0 commit comments

Comments
 (0)