Skip to content

Commit

Permalink
add mechanism to pass rmw impl specific payloads during pub/sub creat…
Browse files Browse the repository at this point in the history
…ion (#513)

* add optional rmw payload to rcl options for pub and sub

Signed-off-by: William Woodall <william@osrfoundation.org>

* move ignore_local_publications into rmw options structure for subs

Signed-off-by: William Woodall <william@osrfoundation.org>
  • Loading branch information
wjwwood authored Oct 8, 2019
1 parent 0198ffe commit e673988
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions rcl/include/rcl/publisher.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct rcl_publisher_options_t
/// Custom allocator for the publisher, used for incidental allocations.
/** For default behavior (malloc/free), use: rcl_get_default_allocator() */
rcl_allocator_t allocator;
/// rmw specific publisher options, e.g. the rmw implementation specific payload.
rmw_publisher_options_t rmw_publisher_options;
} rcl_publisher_options_t;

/// Return a rcl_publisher_t struct with members set to `NULL`.
Expand Down
4 changes: 2 additions & 2 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ typedef struct rcl_subscription_options_t
{
/// Middleware quality of service settings for the subscription.
rmw_qos_profile_t qos;
/// If true, messages published from within the same node are ignored.
bool ignore_local_publications;
/// Custom allocator for the subscription, used for incidental allocations.
/** For default behavior (malloc/free), see: rcl_get_default_allocator() */
rcl_allocator_t allocator;
/// rmw specific subscription options, e.g. the rmw implementation specific payload.
rmw_subscription_options_t rmw_subscription_options;
} rcl_subscription_options_t;

/// Return a rcl_subscription_t struct with members set to `NULL`.
Expand Down
4 changes: 3 additions & 1 deletion rcl/src/rcl/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ rcl_publisher_init(
rcl_node_get_rmw_handle(node),
type_support,
remapped_topic_name,
&(options->qos));
&(options->qos),
&(options->rmw_publisher_options));
RCL_CHECK_FOR_NULL_WITH_MSG(publisher->impl->rmw_handle,
rmw_get_error_string().str, goto fail);
// get actual qos, and store it
Expand Down Expand Up @@ -240,6 +241,7 @@ rcl_publisher_get_default_options()
// Must set the allocator and qos after because they are not a compile time constant.
default_options.qos = rmw_qos_profile_default;
default_options.allocator = rcl_get_default_allocator();
default_options.rmw_publisher_options = rmw_get_default_publisher_options();
return default_options;
}

Expand Down
9 changes: 4 additions & 5 deletions rcl/src/rcl/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ rcl_subscription_init(
type_support,
remapped_topic_name,
&(options->qos),
options->ignore_local_publications);
&(options->rmw_subscription_options));
if (!subscription->impl->rmw_handle) {
RCL_SET_ERROR_MSG(rmw_get_error_string().str);
goto fail;
Expand Down Expand Up @@ -230,12 +230,11 @@ rcl_subscription_options_t
rcl_subscription_get_default_options()
{
// !!! MAKE SURE THAT CHANGES TO THESE DEFAULTS ARE REFLECTED IN THE HEADER DOC STRING
static rcl_subscription_options_t default_options = {
.ignore_local_publications = false,
};
// Must set the allocator and qos after because they are not a compile time constant.
static rcl_subscription_options_t default_options;
// Must set these after declaration because they are not a compile time constants.
default_options.qos = rmw_qos_profile_default;
default_options.allocator = rcl_get_default_allocator();
default_options.rmw_subscription_options = rmw_get_default_subscription_options();
return default_options;
}

Expand Down
9 changes: 4 additions & 5 deletions rcl_action/src/rcl_action/action_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ rcl_action_get_zero_initialized_client(void)
} \
goto fail; \
} \
rcl_subscription_options_t Type ## _topic_subscription_options = { \
.qos = options->Type ## _topic_qos, \
.ignore_local_publications = false, \
.allocator = allocator \
}; \
rcl_subscription_options_t Type ## _topic_subscription_options = \
rcl_subscription_get_default_options(); \
Type ## _topic_subscription_options.qos = options->Type ## _topic_qos; \
Type ## _topic_subscription_options.allocator = allocator; \
action_client->impl->Type ## _subscription = rcl_get_zero_initialized_subscription(); \
ret = rcl_subscription_init( \
&action_client->impl->Type ## _subscription, \
Expand Down

0 comments on commit e673988

Please sign in to comment.