Lifecycle refactor (#298)
* no static initialization of states anymore * make transition labels more descriptive * introduce labeled keys * define default transition keys * fix memory management * introduce service for transition graph * export transition keys * remove keys, transition id unique, label ambiguous * semicolon for macro call
This commit is contained in:
parent
9d4b1c9912
commit
5e3d4be720
13 changed files with 933 additions and 659 deletions
|
@ -24,8 +24,6 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
typedef uint8_t rcl_lifecycle_transition_key_t;
|
||||
|
||||
typedef struct rcl_lifecycle_transition_t rcl_lifecycle_transition_t;
|
||||
|
||||
typedef struct rcl_lifecycle_state_t
|
||||
|
@ -33,16 +31,6 @@ typedef struct rcl_lifecycle_state_t
|
|||
const char * label;
|
||||
unsigned int id;
|
||||
|
||||
// a valid key is a generic identifier for deciding
|
||||
// which transitions to trigger.
|
||||
// This serves the purpose of hiding a unique ID from
|
||||
// users prospective.
|
||||
// e.g. shutdown
|
||||
// the concrete transition for the state "unconfigured"
|
||||
// is "unconfigured_shutdown". However, the user only specifies
|
||||
// "shutdown". So we register the "unconfigured_shutdown"
|
||||
// transition with the impuls "shutdown".
|
||||
rcl_lifecycle_transition_key_t * valid_transition_keys;
|
||||
rcl_lifecycle_transition_t * valid_transitions;
|
||||
unsigned int valid_transition_size;
|
||||
} rcl_lifecycle_state_t;
|
||||
|
@ -71,6 +59,7 @@ typedef struct rcl_lifecycle_com_interface_t
|
|||
rcl_service_t srv_get_state;
|
||||
rcl_service_t srv_get_available_states;
|
||||
rcl_service_t srv_get_available_transitions;
|
||||
rcl_service_t srv_get_transition_graph;
|
||||
} rcl_lifecycle_com_interface_t;
|
||||
|
||||
typedef struct rcl_lifecycle_state_machine_t
|
||||
|
|
49
rcl_lifecycle/include/rcl_lifecycle/default_state_machine.h
Normal file
49
rcl_lifecycle/include/rcl_lifecycle/default_state_machine.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2016 Open Source Robotics Foundation, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef RCL_LIFECYCLE__DEFAULT_STATE_MACHINE_H_
|
||||
#define RCL_LIFECYCLE__DEFAULT_STATE_MACHINE_H_
|
||||
|
||||
#include "rcl/macros.h"
|
||||
#include "rcl/types.h"
|
||||
|
||||
#include "rcl_lifecycle/data_types.h"
|
||||
#include "rcl_lifecycle/visibility_control.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_configure_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_cleanup_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_activate_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_deactivate_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_shutdown_label;
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_transition_success_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_transition_failure_label;
|
||||
RCL_LIFECYCLE_PUBLIC extern const char * rcl_lifecycle_transition_error_label;
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
rcl_ret_t
|
||||
rcl_lifecycle_init_default_state_machine(
|
||||
rcl_lifecycle_state_machine_t * state_machine, const rcl_allocator_t * allocator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // RCL_LIFECYCLE__DEFAULT_STATE_MACHINE_H_
|
|
@ -23,6 +23,7 @@ extern "C"
|
|||
#include <stdbool.h>
|
||||
|
||||
#include "rcl_lifecycle/data_types.h"
|
||||
#include "rcl_lifecycle/default_state_machine.h"
|
||||
#include "rcl_lifecycle/visibility_control.h"
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
|
@ -89,6 +90,7 @@ rcl_lifecycle_state_machine_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,
|
||||
bool default_states,
|
||||
const rcl_allocator_t * allocator);
|
||||
|
||||
|
@ -109,27 +111,32 @@ rcl_lifecycle_state_machine_is_initialized(
|
|||
RCL_LIFECYCLE_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
const rcl_lifecycle_transition_t *
|
||||
rcl_lifecycle_is_valid_callback_transition(
|
||||
rcl_lifecycle_state_machine_t * state_machine,
|
||||
rcl_lifecycle_transition_key_t key);
|
||||
rcl_lifecycle_get_transition_by_id(
|
||||
const rcl_lifecycle_state_t * state,
|
||||
uint8_t id);
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
const rcl_lifecycle_transition_t *
|
||||
rcl_lifecycle_get_transition_by_label(
|
||||
const rcl_lifecycle_state_t * state,
|
||||
const char * label);
|
||||
|
||||
/// Execute a transition
|
||||
/*
|
||||
* Important note for \param key here:
|
||||
* This is meant as feedback from the high level
|
||||
* callback associated with this transition.
|
||||
* The key is the index for the valid transitions
|
||||
* associated with the current state.
|
||||
* This key may either be a valid external stimuli
|
||||
* such as "configure" or direct return codes from
|
||||
* callbacks such as RCL_LIFECYCLE_RET_OK et. al.
|
||||
*/
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
rcl_ret_t
|
||||
rcl_lifecycle_trigger_transition(
|
||||
rcl_lifecycle_trigger_transition_by_id(
|
||||
rcl_lifecycle_state_machine_t * state_machine,
|
||||
rcl_lifecycle_transition_key_t key, bool publish_notification);
|
||||
uint8_t id,
|
||||
bool publish_notification);
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
RCL_WARN_UNUSED
|
||||
rcl_ret_t
|
||||
rcl_lifecycle_trigger_transition_by_label(
|
||||
rcl_lifecycle_state_machine_t * state_machine,
|
||||
const char * label,
|
||||
bool publish_notification);
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
void
|
||||
|
|
|
@ -57,7 +57,6 @@ rcl_ret_t
|
|||
rcl_lifecycle_register_transition(
|
||||
rcl_lifecycle_transition_map_t * transition_map,
|
||||
rcl_lifecycle_transition_t transition,
|
||||
rcl_lifecycle_transition_key_t key,
|
||||
const rcl_allocator_t * allocator);
|
||||
|
||||
RCL_LIFECYCLE_PUBLIC
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue