Skip to content

Commit

Permalink
[rcl_lifecycle] Do not share transition event message between nodes (r…
Browse files Browse the repository at this point in the history
…os2#956)

Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored and Mauro Passerino committed Aug 2, 2022
1 parent edfd0ac commit 86ee7e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rcl_lifecycle/include/rcl_lifecycle/data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "rcl_lifecycle/visibility_control.h"

#include "lifecycle_msgs/msg/transition_event.h"

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -84,6 +86,8 @@ typedef struct rcl_lifecycle_com_interface_t
rcl_service_t srv_get_available_transitions;
/// Service that allows to get transitions from the graph
rcl_service_t srv_get_transition_graph;
/// Cached transition event message.
lifecycle_msgs__msg__TransitionEvent msg;
} rcl_lifecycle_com_interface_t;

/// It contains various options to configure the rcl_lifecycle_state_machine_t instance
Expand Down
18 changes: 10 additions & 8 deletions rcl_lifecycle/src/com_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C"

#include <stdio.h>
#include <string.h>
#include <stddef.h>

#include "lifecycle_msgs/msg/transition_event.h"

Expand All @@ -36,7 +37,6 @@ extern "C"

#include "rcl_lifecycle/data_types.h"

static lifecycle_msgs__msg__TransitionEvent msg;
static const char * pub_transition_event_topic = "~/transition_event";
static const char * srv_change_state_service = "~/change_state";
static const char * srv_get_state_service = "~/get_state";
Expand All @@ -55,6 +55,8 @@ rcl_lifecycle_get_zero_initialized_com_interface()
com_interface.srv_get_available_states = rcl_get_zero_initialized_service();
com_interface.srv_get_available_transitions = rcl_get_zero_initialized_service();
com_interface.srv_get_transition_graph = rcl_get_zero_initialized_service();
lifecycle_msgs__msg__TransitionEvent msg = {0};
com_interface.msg = msg;
return com_interface;
}

Expand Down Expand Up @@ -115,7 +117,7 @@ rcl_lifecycle_com_interface_publisher_init(
}

// initialize static message for notification
lifecycle_msgs__msg__TransitionEvent__init(&msg);
lifecycle_msgs__msg__TransitionEvent__init(&com_interface->msg);

return RCL_RET_OK;

Expand All @@ -131,7 +133,7 @@ rcl_lifecycle_com_interface_publisher_fini(
rcl_lifecycle_com_interface_t * com_interface,
rcl_node_t * node_handle)
{
lifecycle_msgs__msg__TransitionEvent__fini(&msg);
lifecycle_msgs__msg__TransitionEvent__fini(&com_interface->msg);

rcl_ret_t ret = rcl_publisher_fini(
&com_interface->pub_transition_event, node_handle);
Expand Down Expand Up @@ -325,12 +327,12 @@ rcl_lifecycle_com_interface_publish_notification(
rcl_lifecycle_com_interface_t * com_interface,
const rcl_lifecycle_state_t * start, const rcl_lifecycle_state_t * goal)
{
msg.start_state.id = start->id;
rosidl_runtime_c__String__assign(&msg.start_state.label, start->label);
msg.goal_state.id = goal->id;
rosidl_runtime_c__String__assign(&msg.goal_state.label, goal->label);
com_interface->msg.start_state.id = start->id;
rosidl_runtime_c__String__assign(&com_interface->msg.start_state.label, start->label);
com_interface->msg.goal_state.id = goal->id;
rosidl_runtime_c__String__assign(&com_interface->msg.goal_state.label, goal->label);

return rcl_publish(&com_interface->pub_transition_event, &msg, NULL);
return rcl_publish(&com_interface->pub_transition_event, &com_interface->msg, NULL);
}

#ifdef __cplusplus
Expand Down

0 comments on commit 86ee7e4

Please sign in to comment.