comply with rcl allocator (#336)

* comply with rcl allocator

* do not throw exception in destructor
This commit is contained in:
Karsten Knese 2017-06-16 23:44:25 +02:00 committed by Dirk Thomas
parent 756ef6886d
commit 99441d8494

View file

@ -35,6 +35,7 @@
#include "rcl/error_handling.h" #include "rcl/error_handling.h"
#include "rcl_lifecycle/rcl_lifecycle.h" #include "rcl_lifecycle/rcl_lifecycle.h"
#include "rcl_lifecycle/transition_map.h"
#include "rclcpp/node_interfaces/node_base_interface.hpp" #include "rclcpp/node_interfaces/node_base_interface.hpp"
#include "rclcpp/node_interfaces/node_services_interface.hpp" #include "rclcpp/node_interfaces/node_services_interface.hpp"
@ -60,24 +61,21 @@ public:
~LifecycleNodeInterfaceImpl() ~LifecycleNodeInterfaceImpl()
{ {
if (rcl_lifecycle_state_machine_is_initialized(&state_machine_) != RCL_RET_OK) { rcl_node_t * node_handle = node_base_interface_->get_rcl_node_handle();
fprintf(stderr, "%s:%u, FATAL: rcl_state_machine got destroyed externally.\n", const rcl_node_options_t * node_options = rcl_node_get_options(node_handle);
__FILE__, __LINE__); auto ret = rcl_lifecycle_state_machine_fini(
// TODO(karsten1987): Remove else. It should always be possible to call &state_machine_, node_handle, &node_options->allocator);
// fini on state machine, also when not initialized if (ret != RCL_RET_OK) {
} else { fprintf(stderr, "FATAL: failed to destroy rcl_state_machine\n");
if (rcl_lifecycle_state_machine_fini(&state_machine_,
node_base_interface_->get_rcl_node_handle()) != RCL_RET_OK)
{
fprintf(stderr, "%s:%u, FATAL: failed to destroy rcl_state_machine.\n",
__FILE__, __LINE__);
}
} }
} }
void void
init() init()
{ {
rcl_node_t * node_handle = node_base_interface_->get_rcl_node_handle();
const rcl_node_options_t * node_options =
rcl_node_get_options(node_base_interface_->get_rcl_node_handle());
state_machine_ = rcl_lifecycle_get_zero_initialized_state_machine(); state_machine_ = rcl_lifecycle_get_zero_initialized_state_machine();
// The call to initialize the state machine takes // The call to initialize the state machine takes
// currently five different typesupports for all publishers/services // currently five different typesupports for all publishers/services
@ -86,17 +84,19 @@ public:
// the message) is done fully in RCL. // the message) is done fully in RCL.
// Services are handled in C++, so that it needs a C++ typesupport structure. // Services are handled in C++, so that it needs a C++ typesupport structure.
rcl_ret_t ret = rcl_lifecycle_state_machine_init( rcl_ret_t ret = rcl_lifecycle_state_machine_init(
&state_machine_, node_base_interface_->get_rcl_node_handle(), &state_machine_,
node_handle,
ROSIDL_GET_MSG_TYPE_SUPPORT(lifecycle_msgs, msg, TransitionEvent), ROSIDL_GET_MSG_TYPE_SUPPORT(lifecycle_msgs, msg, TransitionEvent),
rosidl_typesupport_cpp::get_service_type_support_handle<ChangeStateSrv>(), rosidl_typesupport_cpp::get_service_type_support_handle<ChangeStateSrv>(),
rosidl_typesupport_cpp::get_service_type_support_handle<GetStateSrv>(), rosidl_typesupport_cpp::get_service_type_support_handle<GetStateSrv>(),
rosidl_typesupport_cpp::get_service_type_support_handle<GetAvailableStatesSrv>(), rosidl_typesupport_cpp::get_service_type_support_handle<GetAvailableStatesSrv>(),
rosidl_typesupport_cpp::get_service_type_support_handle<GetAvailableTransitionsSrv>(), rosidl_typesupport_cpp::get_service_type_support_handle<GetAvailableTransitionsSrv>(),
true); true,
&node_options->allocator);
if (ret != RCL_RET_OK) { if (ret != RCL_RET_OK) {
throw std::runtime_error( throw std::runtime_error(
std::string( std::string("Couldn't initialize state machine for node ") +
"Couldn't initialize state machine for node ") + node_base_interface_->get_name()); node_base_interface_->get_name());
} }
{ // change_state { // change_state