use new error handling API from rcutils (#314)

* use new error handling API from rcutils

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

* use semicolons after macros

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

* use new error handling API from rcutils

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

* minimize vertical whitespace

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

* use semicolons after macros

Signed-off-by: William Woodall <william@osrfoundation.org>
This commit is contained in:
William Woodall 2018-11-01 21:08:31 -05:00 committed by GitHub
parent 765de78140
commit 4d8cb487f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 1131 additions and 1314 deletions

View file

@ -67,21 +67,16 @@ rcl_lifecycle_com_interface_init(
const rosidl_service_type_support_t * ts_srv_get_state,
const rosidl_service_type_support_t * ts_srv_get_available_states,
const rosidl_service_type_support_t * ts_srv_get_available_transitions,
const rosidl_service_type_support_t * ts_srv_get_transition_graph,
const rcl_allocator_t * allocator)
const rosidl_service_type_support_t * ts_srv_get_transition_graph)
{
RCL_CHECK_ARGUMENT_FOR_NULL(allocator, RCL_RET_INVALID_ARGUMENT, rcl_get_default_allocator())
RCL_CHECK_ARGUMENT_FOR_NULL(com_interface, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(node_handle, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(ts_pub_notify, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_change_state, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_get_state, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(
ts_srv_get_available_states, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(
ts_srv_get_available_transitions, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(
ts_srv_get_transition_graph, RCL_RET_INVALID_ARGUMENT, *allocator)
RCL_CHECK_ARGUMENT_FOR_NULL(com_interface, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(node_handle, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_pub_notify, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_change_state, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_get_state, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_get_available_states, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_get_available_transitions, RCL_RET_INVALID_ARGUMENT);
RCL_CHECK_ARGUMENT_FOR_NULL(ts_srv_get_transition_graph, RCL_RET_INVALID_ARGUMENT);
// initialize publisher
{

View file

@ -37,8 +37,7 @@ rcl_lifecycle_com_interface_init(
const rosidl_service_type_support_t * ts_srv_get_state,
const rosidl_service_type_support_t * ts_srv_get_available_states,
const rosidl_service_type_support_t * ts_srv_get_available_transitions,
const rosidl_service_type_support_t * ts_srv_get_transition_graph,
const rcl_allocator_t * allocator);
const rosidl_service_type_support_t * ts_srv_get_transition_graph);
rcl_ret_t
RCL_WARN_UNUSED

View file

@ -692,8 +692,7 @@ rcl_lifecycle_init_default_state_machine(
fail:
if (rcl_lifecycle_transition_map_fini(&state_machine->transition_map, allocator) != RCL_RET_OK) {
RCL_SET_ERROR_MSG("could not free lifecycle transition map. Leaking memory!\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("could not free lifecycle transition map. Leaking memory!\n");
}
return RCL_RET_ERROR;
}

View file

@ -51,19 +51,18 @@ rcl_lifecycle_state_init(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize state, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't initialize state, no allocator given\n");
return RCL_RET_ERROR;
}
if (!state) {
RCL_SET_ERROR_MSG("state pointer is null\n", *allocator);
RCL_SET_ERROR_MSG("state pointer is null\n");
return RCL_RET_ERROR;
}
state->id = id;
state->label = rcutils_strndup(label, strlen(label), *allocator);
if (!state->label) {
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_state_t\n", *allocator);
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_state_t\n");
return RCL_RET_ERROR;
}
@ -76,8 +75,7 @@ rcl_lifecycle_state_fini(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't free state, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't free state, no allocator given\n");
return RCL_RET_ERROR;
}
// it is already NULL
@ -114,13 +112,12 @@ rcl_lifecycle_transition_init(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n");
return RCL_RET_ERROR;
}
if (!transition) {
RCL_SET_ERROR_MSG("transition pointer is null\n", *allocator);
RCL_SET_ERROR_MSG("transition pointer is null\n");
return RCL_RET_OK;
}
@ -130,7 +127,7 @@ rcl_lifecycle_transition_init(
transition->id = id;
transition->label = rcutils_strndup(label, strlen(label), *allocator);
if (!transition->label) {
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_transition_t\n", *allocator);
RCL_SET_ERROR_MSG("failed to duplicate label for rcl_lifecycle_transition_t\n");
return RCL_RET_ERROR;
}
@ -143,8 +140,7 @@ rcl_lifecycle_transition_fini(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't initialize transition, no allocator given\n");
return RCL_RET_ERROR;
}
// it is already NULL
@ -197,8 +193,7 @@ rcl_lifecycle_state_machine_init(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't initialize state machine, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't initialize state machine, no allocator given\n");
return RCL_RET_ERROR;
}
@ -206,8 +201,7 @@ rcl_lifecycle_state_machine_init(
&state_machine->com_interface, node_handle,
ts_pub_notify,
ts_srv_change_state, ts_srv_get_state,
ts_srv_get_available_states, ts_srv_get_available_transitions, ts_srv_get_transition_graph,
allocator);
ts_srv_get_available_states, ts_srv_get_available_transitions, ts_srv_get_transition_graph);
if (ret != RCL_RET_OK) {
return RCL_RET_ERROR;
}
@ -235,24 +229,21 @@ rcl_lifecycle_state_machine_fini(
const rcl_allocator_t * allocator)
{
if (!allocator) {
RCL_SET_ERROR_MSG("can't free state machine, no allocator given\n",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("can't free state machine, no allocator given\n");
return RCL_RET_ERROR;
}
rcl_ret_t fcn_ret = RCL_RET_OK;
if (rcl_lifecycle_com_interface_fini(&state_machine->com_interface, node_handle) != RCL_RET_OK) {
RCL_SET_ERROR_MSG(
"could not free lifecycle com interface. Leaking memory!\n", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("could not free lifecycle com interface. Leaking memory!\n");
fcn_ret = RCL_RET_ERROR;
}
if (rcl_lifecycle_transition_map_fini(
&state_machine->transition_map, allocator) != RCL_RET_OK)
{
RCL_SET_ERROR_MSG(
"could not free lifecycle transition map. Leaking memory!\n", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("could not free lifecycle transition map. Leaking memory!\n");
fcn_ret = RCL_RET_ERROR;
}
@ -263,15 +254,15 @@ rcl_ret_t
rcl_lifecycle_state_machine_is_initialized(const rcl_lifecycle_state_machine_t * state_machine)
{
if (!state_machine->com_interface.srv_get_state.impl) {
RCL_SET_ERROR_MSG("get_state service is null", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("get_state service is null");
return RCL_RET_ERROR;
}
if (!state_machine->com_interface.srv_change_state.impl) {
RCL_SET_ERROR_MSG("change_state service is null", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("change_state service is null");
return RCL_RET_ERROR;
}
if (rcl_lifecycle_transition_map_is_initialized(&state_machine->transition_map) != RCL_RET_OK) {
RCL_SET_ERROR_MSG("transition map is null", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("transition map is null");
return RCL_RET_ERROR;
}
return RCL_RET_OK;
@ -282,8 +273,7 @@ rcl_lifecycle_get_transition_by_id(
const rcl_lifecycle_state_t * state,
uint8_t id)
{
RCL_CHECK_FOR_NULL_WITH_MSG(state,
"state pointer is null", return NULL, rcl_get_default_allocator());
RCL_CHECK_FOR_NULL_WITH_MSG(state, "state pointer is null", return NULL);
for (unsigned int i = 0; i < state->valid_transition_size; ++i) {
if (state->valid_transitions[i].id == id) {
@ -304,8 +294,7 @@ rcl_lifecycle_get_transition_by_label(
const rcl_lifecycle_state_t * state,
const char * label)
{
RCL_CHECK_FOR_NULL_WITH_MSG(state,
"state pointer is null", return NULL, rcl_get_default_allocator());
RCL_CHECK_FOR_NULL_WITH_MSG(state, "state pointer is null", return NULL);
for (unsigned int i = 0; i < state->valid_transition_size; ++i) {
if (strcmp(state->valid_transitions[i].label, label) == 0) {
@ -329,7 +318,7 @@ _trigger_transition(
{
// If we have a faulty transition pointer
if (!transition) {
RCL_SET_ERROR_MSG("Transition is not registered.", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("Transition is not registered.");
return RCL_RET_ERROR;
}
@ -344,7 +333,7 @@ _trigger_transition(
rcl_ret_t ret = rcl_lifecycle_com_interface_publish_notification(
&state_machine->com_interface, transition->start, state_machine->current_state);
if (ret != RCL_RET_OK) {
RCL_SET_ERROR_MSG("Could not publish transition", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("Could not publish transition");
return RCL_RET_ERROR;
}
}

View file

@ -72,8 +72,7 @@ rcl_lifecycle_register_state(
const rcutils_allocator_t * allocator)
{
if (rcl_lifecycle_get_state(transition_map, state.id) != NULL) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(rcutils_get_default_allocator(),
"state %u is already registered\n", state.id);
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("state %u is already registered\n", state.id);
return RCL_RET_ERROR;
}
@ -87,8 +86,7 @@ rcl_lifecycle_register_state(
transition_map->states_size * sizeof(rcl_lifecycle_state_t),
allocator->state);
if (!new_states) {
RCL_SET_ERROR_MSG(
"failed to reallocate memory for new states", rcl_get_default_allocator());
RCL_SET_ERROR_MSG("failed to reallocate memory for new states");
return RCL_RET_ERROR;
}
transition_map->states = new_states;
@ -108,8 +106,7 @@ rcl_lifecycle_register_transition(
rcl_lifecycle_state_t * state = rcl_lifecycle_get_state(transition_map, transition.start->id);
if (!state) {
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING(rcl_get_default_allocator(),
"state %u is not registered\n", transition.start->id);
RCL_SET_ERROR_MSG_WITH_FORMAT_STRING("state %u is not registered\n", transition.start->id);
return RCL_RET_ERROR;
}
@ -120,9 +117,7 @@ rcl_lifecycle_register_transition(
transition_map->transitions_size * sizeof(rcl_lifecycle_transition_t),
allocator->state);
if (!new_transitions) {
RCL_SET_ERROR_MSG(
"failed to reallocate memory for new transitions",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("failed to reallocate memory for new transitions");
return RCL_RET_BAD_ALLOC;
}
transition_map->transitions = new_transitions;
@ -138,9 +133,7 @@ rcl_lifecycle_register_transition(
state->valid_transition_size * sizeof(rcl_lifecycle_transition_t),
allocator->state);
if (!new_valid_transitions) {
RCL_SET_ERROR_MSG(
"failed to reallocate memory for new transitions on state",
rcl_get_default_allocator());
RCL_SET_ERROR_MSG("failed to reallocate memory for new transitions on state");
return RCL_RET_ERROR;
}
state->valid_transitions = new_valid_transitions;