Skip to content

Commit 49ab4f6

Browse files
committed
Move topic name to topic object
Signed-off-by: Pablo Garrido <pablogs9@gmail.com>
1 parent 10c440d commit 49ab4f6

4 files changed

Lines changed: 15 additions & 20 deletions

File tree

rmw_microxrcedds_c/src/rmw_microros_internal/types.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ typedef struct rmw_uxrce_topic_t
121121

122122
uxrObjectId topic_id;
123123
const message_type_support_callbacks_t * message_type_support_callbacks;
124+
char topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
124125

125126
struct rmw_uxrce_node_t * owner_node;
126127
} rmw_uxrce_topic_t;
@@ -173,7 +174,6 @@ typedef struct rmw_uxrce_subscription_t
173174
uxrStreamId stream_id;
174175

175176
rmw_subscription_t rmw_subscription;
176-
char topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
177177
} rmw_uxrce_subscription_t;
178178

179179
typedef struct rmw_uxrce_publisher_t
@@ -196,7 +196,6 @@ typedef struct rmw_uxrce_publisher_t
196196
struct rmw_uxrce_node_t * owner_node;
197197

198198
rmw_publisher_t rmw_publisher;
199-
char topic_name[RMW_UXRCE_TOPIC_NAME_MAX_LENGTH];
200199
} rmw_uxrce_publisher_t;
201200

202201
typedef struct rmw_uxrce_node_t

rmw_microxrcedds_c/src/rmw_microxrcedds_topic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ create_topic(
4949
// Generate topic id
5050
custom_topic->topic_id = uxr_object_id(custom_node->context->id_topic++, UXR_TOPIC_ID);
5151

52+
if ((strlen(topic_name) + 1 ) > sizeof(custom_topic->topic_name)) {
53+
RMW_UROS_TRACE_MESSAGE("failed to allocate string")
54+
rmw_uxrce_fini_topic_memory(custom_topic);
55+
custom_topic = NULL;
56+
goto fail;
57+
}
58+
snprintf(
59+
(char *)custom_topic->topic_name, sizeof(custom_topic->topic_name), "%s",
60+
topic_name);
61+
5262
// Generate request
5363
uint16_t topic_req = 0;
5464
#ifdef RMW_UXRCE_USE_REFS

rmw_microxrcedds_c/src/rmw_publisher.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ rmw_create_publisher(
9090
rmw_publisher = &custom_publisher->rmw_publisher;
9191
rmw_publisher->data = NULL;
9292
rmw_publisher->implementation_identifier = rmw_get_implementation_identifier();
93-
rmw_publisher->topic_name = custom_publisher->topic_name;
94-
95-
if ((strlen(topic_name) + 1 ) > sizeof(custom_publisher->topic_name)) {
96-
RMW_UROS_TRACE_MESSAGE("failed to allocate string")
97-
goto fail;
98-
}
99-
snprintf(
100-
(char *)rmw_publisher->topic_name, sizeof(custom_publisher->topic_name), "%s",
101-
topic_name);
10293

10394
custom_publisher->owner_node = custom_node;
10495
custom_publisher->session_timeout = RMW_UXRCE_PUBLISH_RELIABLE_TIMEOUT;
@@ -146,6 +137,8 @@ rmw_create_publisher(
146137
goto fail;
147138
}
148139

140+
rmw_publisher->topic_name = custom_publisher->topic->topic_name;
141+
149142
// Create publisher
150143
custom_publisher->publisher_id = uxr_object_id(
151144
custom_node->context->id_publisher++,

rmw_microxrcedds_c/src/rmw_subscription.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ rmw_create_subscription(
9090
rmw_subscription = &custom_subscription->rmw_subscription;
9191
rmw_subscription->data = NULL;
9292
rmw_subscription->implementation_identifier = rmw_get_implementation_identifier();
93-
rmw_subscription->topic_name = custom_subscription->topic_name;
94-
if ((strlen(topic_name) + 1 ) > sizeof(custom_subscription->topic_name)) {
95-
RMW_UROS_TRACE_MESSAGE("failed to allocate string")
96-
goto fail;
97-
}
98-
99-
snprintf(
100-
(char *)rmw_subscription->topic_name, sizeof(custom_subscription->topic_name), "%s",
101-
topic_name);
10293

10394
custom_subscription->owner_node = custom_node;
10495
custom_subscription->qos = *qos_policies;
@@ -135,6 +126,8 @@ rmw_create_subscription(
135126
goto fail;
136127
}
137128

129+
rmw_subscription->topic_name = custom_subscription->topic->topic_name;
130+
138131
// Create subscriber
139132
custom_subscription->subscriber_id = uxr_object_id(
140133
custom_node->context->id_subscriber++,

0 commit comments

Comments
 (0)