Skip to content

Commit d878e93

Browse files
pablogs9Your Name
authored andcommitted
Refactor entities creation XML and REF
1 parent 9e27b72 commit d878e93

5 files changed

Lines changed: 72 additions & 23 deletions

File tree

rmw_microxrcedds_c/src/rmw_client.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,24 @@ rmw_create_client(
127127
}
128128
client_req = uxr_buffer_create_requester_xml(
129129
&custom_node->context->session,
130-
custom_node->context->reliable_output, custom_client->client_id,
131-
custom_node->participant_id, rmw_uxrce_xml_buffer, UXR_REPLACE);
130+
custom_node->context->reliable_output,
131+
custom_client->client_id,
132+
custom_node->participant_id,
133+
rmw_uxrce_xml_buffer,
134+
UXR_REPLACE);
132135
#elif defined(MICRO_XRCEDDS_USE_REFS)
133-
// TODO(pablogs9): Is possible to instantiate a replier by ref?
134-
// client_req = uxr_buffer_create_replier_ref(&custom_node->context->session,
135-
// custom_node->context->reliable_output, custom_service->subscriber_id,
136-
// custom_node->participant_id, "", UXR_REPLACE);
136+
if (!build_requester_profile(service_name, rmw_uxrce_profile_name, sizeof(rmw_uxrce_profile_name))) {
137+
RMW_SET_ERROR_MSG("failed to generate ref request for client creation");
138+
goto fail;
139+
}
140+
141+
client_req = uxr_buffer_create_requester_ref(
142+
&custom_node->context->session,
143+
custom_node->context->reliable_output,
144+
custom_client->client_id,
145+
custom_node->participant_id,
146+
rmw_uxrce_profile_name,
147+
UXR_REPLACE);
137148
#endif
138149

139150
rmw_client->data = custom_client;

rmw_microxrcedds_c/src/rmw_publisher.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,22 @@ rmw_create_publisher(
185185
&custom_publisher->owner_node->context->session,
186186
custom_node->context->reliable_output,
187187
custom_publisher->datawriter_id,
188-
custom_publisher->publisher_id, rmw_uxrce_xml_buffer, UXR_REPLACE);
188+
custom_publisher->publisher_id,
189+
rmw_uxrce_xml_buffer,
190+
UXR_REPLACE);
189191
#elif defined(MICRO_XRCEDDS_USE_REFS)
190192
if (!build_datawriter_profile(topic_name, rmw_uxrce_profile_name, sizeof(rmw_uxrce_profile_name))) {
191-
RMW_SET_ERROR_MSG("failed to generate xml request for node creation");
193+
RMW_SET_ERROR_MSG("failed to generate ref request datawriter creation");
192194
goto fail;
193195
}
194196

195197
datawriter_req = uxr_buffer_create_datawriter_ref(
196198
&custom_publisher->owner_node->context->session,
197199
custom_node->context->reliable_output,
198200
custom_publisher->datawriter_id,
199-
custom_publisher->publisher_id, rmw_uxrce_profile_name, UXR_REPLACE);
201+
custom_publisher->publisher_id,
202+
rmw_uxrce_profile_name,
203+
UXR_REPLACE);
200204
#endif
201205

202206
rmw_publisher->data = custom_publisher;

rmw_microxrcedds_c/src/rmw_service.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,18 @@ rmw_create_service(
127127
custom_node->context->reliable_output, custom_service->service_id,
128128
custom_node->participant_id, rmw_uxrce_xml_buffer, UXR_REPLACE);
129129
#elif defined(MICRO_XRCEDDS_USE_REFS)
130-
// CHECK IF THIS IS NECESSARY
131-
// service_req = uxr_buffer_create_replier_ref(&custom_node->context->session,
132-
// custom_node->context->reliable_output, custom_service->subscriber_id,
133-
// custom_node->participant_id, "", UXR_REPLACE);
130+
if (!build_replier_profile(service_name, rmw_uxrce_profile_name, sizeof(rmw_uxrce_profile_name))) {
131+
RMW_SET_ERROR_MSG("failed to generate ref request for service creation");
132+
goto fail;
133+
}
134+
135+
service_req = uxr_buffer_create_replier_ref(
136+
&custom_node->context->session,
137+
custom_node->context->reliable_output,
138+
custom_client->client_id,
139+
custom_node->participant_id,
140+
rmw_uxrce_profile_name,
141+
UXR_REPLACE);
134142
#endif
135143

136144
rmw_service->data = custom_service;

rmw_microxrcedds_c/src/rmw_subscription.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ rmw_create_subscription(
158158
custom_node->context->reliable_output, custom_subscription->subscriber_id,
159159
custom_node->participant_id, rmw_uxrce_xml_buffer, UXR_REPLACE);
160160
#elif defined(MICRO_XRCEDDS_USE_REFS)
161-
// TODO(BORJA) Publisher by reference does not make sense in
162-
// current micro XRCE-DDS implementation.
163161
subscriber_req = uxr_buffer_create_subscriber_xml(
164162
&custom_node->context->session,
165-
custom_node->context->reliable_output, custom_subscription->subscriber_id,
166-
custom_node->participant_id, "", UXR_REPLACE);
163+
custom_node->context->reliable_output,
164+
custom_subscription->subscriber_id,
165+
custom_node->participant_id,
166+
"",
167+
UXR_REPLACE);
167168
#endif
168169

169170

@@ -184,18 +185,24 @@ rmw_create_subscription(
184185

185186
datareader_req = uxr_buffer_create_datareader_xml(
186187
&custom_node->context->session,
187-
custom_node->context->reliable_output, custom_subscription->datareader_id,
188-
custom_subscription->subscriber_id, rmw_uxrce_xml_buffer, UXR_REPLACE);
188+
custom_node->context->reliable_output,
189+
custom_subscription->datareader_id,
190+
custom_subscription->subscriber_id,
191+
rmw_uxrce_xml_buffer,
192+
UXR_REPLACE);
189193
#elif defined(MICRO_XRCEDDS_USE_REFS)
190194
if (!build_datareader_profile(topic_name, rmw_uxrce_profile_name, sizeof(rmw_uxrce_profile_name))) {
191-
RMW_SET_ERROR_MSG("failed to generate xml request for node creation");
195+
RMW_SET_ERROR_MSG("failed to generate ref request for datareader creation");
192196
goto fail;
193197
}
194198

195199
datareader_req = uxr_buffer_create_datareader_ref(
196200
&custom_node->context->session,
197-
custom_node->context->reliable_output, custom_subscription->datareader_id,
198-
custom_subscription->subscriber_id, rmw_uxrce_profile_name, UXR_REPLACE);
201+
custom_node->context->reliable_output,
202+
custom_subscription->datareader_id,
203+
custom_subscription->subscriber_id,
204+
rmw_uxrce_profile_name,
205+
UXR_REPLACE);
199206
#endif
200207

201208
rmw_subscription->data = custom_subscription;

rmw_microxrcedds_c/src/utils.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,23 @@ bool is_uxrce_rmw_identifier_valid(const char * id)
374374
{
375375
return id != NULL &&
376376
strcmp(id, rmw_get_implementation_identifier()) == 0;
377-
}
377+
}
378+
bool build_requester_profile(const char * service_name, char profile_name[], size_t buffer_size)
379+
{
380+
const char * const format = "%s___requester";
381+
topic_name++;
382+
bool ret = false;
383+
int written = snprintf(profile_name, buffer_size, format, service_name);
384+
ret = (written > 0) && (written < (int)buffer_size);
385+
return ret;
386+
}
387+
388+
bool build_replier_profile(const char * service_name, char profile_name[], size_t buffer_size)
389+
{
390+
const char * const format = "%s___replier";
391+
topic_name++;
392+
bool ret = false;
393+
int written = snprintf(profile_name, buffer_size, format, service_name);
394+
ret = (written > 0) && (written < (int)buffer_size);
395+
return ret;
396+
}

0 commit comments

Comments
 (0)