rcl_lifecycle  master
C API providing common functionality for ROS lifecycle.
All Classes Namespaces Files Functions Variables Modules Pages
transition_map.h
1 // Copyright 2016 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef RCL_LIFECYCLE__TRANSITION_MAP_H_
17 #define RCL_LIFECYCLE__TRANSITION_MAP_H_
18 
19 #include "rcl/macros.h"
20 
21 #include "rcl_lifecycle/data_types.h"
22 
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27 
29 /*
30  * Should be called to get a null rcl_lifecycle_transition_map_t before passing to
31  * rcl_lifecycle_register_state() or rcl_lifecycle_register_transition().
32  *
33  * \return rcl_lifecycle_transition_map_t a initilized struct
34  */
35 RCL_LIFECYCLE_PUBLIC
36 RCL_WARN_UNUSED
38 rcl_lifecycle_get_zero_initialized_transition_map();
39 
41 /*
42  * The function checks if the transition map is initialized. It returns `RCL_RET_OK`
43  * if the transition map is initialized successfully or `RCL_RET_ERROR` if the transition
44  * map is not initialized.
45  *
46  * <hr>
47  * Attribute | Adherence
48  * ------------------ | -------------
49  * Allocates Memory | No
50  * Thread-Safe | No
51  * Uses Atomics | No
52  * Lock-Free | Yes
53  *
54  * \param[in] transition_map pointer to the transition map struct to check
55  * \return `RCL_RET_OK` if the transition map is initialized successfully, or
56  * \return `RCL_RET_ERROR` if the transition map is not initialized.
57  */
58 RCL_LIFECYCLE_PUBLIC
59 RCL_WARN_UNUSED
60 rcl_ret_t
61 rcl_lifecycle_transition_map_is_initialized(
62  const rcl_lifecycle_transition_map_t * transition_map);
63 
65 /*
66  * Calling this will set the rcl_lifecycle_transition_map_t struct into the an unitialized state that is
67  * functionally the same as before rcl_lifecycle_register_state or
68  * rcl_lifecycle_register_transition was called. This function make the rcl_lifecycle_transition_map_t invalid.
69  *
70  * <hr>
71  * Attribute | Adherence
72  * ------------------ | -------------
73  * Allocates Memory | Yes
74  * Thread-Safe | No
75  * Uses Atomics | No
76  * Lock-Free | Yes
77  *
78  * \param[inout] transition_map struct to be deinitialized
79  * \param[in] allocator a valid allocator used to deinitialized the state machine
80  * \return `RCL_RET_OK` if the state was deinitialized successfully, or
81  * \return `RCL_RET_ERROR` if an unspecified error occurs.
82  */
83 RCL_LIFECYCLE_PUBLIC
84 RCL_WARN_UNUSED
85 rcl_ret_t
86 rcl_lifecycle_transition_map_fini(
87  rcl_lifecycle_transition_map_t * transition_map,
88  const rcl_allocator_t * allocator);
89 
91 /*
92  * This function registers a new state in the transition map.
93  *
94  * <hr>
95  * Attribute | Adherence
96  * ------------------ | -------------
97  * Allocates Memory | Yes
98  * Thread-Safe | No
99  * Uses Atomics | No
100  * Lock-Free | Yes
101  *
102  * \param[in] map to be modified
103  * \param[in] state the state to register
104  * \param[in] allocator a valid allocator used to register the state machine
105  * \return `RCL_RET_OK` if the state was registered successfully, or
106  * \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or
107  * \return `RCL_RET_ERROR` if an unspecified error occurs.
108  */
109 RCL_LIFECYCLE_PUBLIC
110 RCL_WARN_UNUSED
111 rcl_ret_t
112 rcl_lifecycle_register_state(
114  rcl_lifecycle_state_t state,
115  const rcl_allocator_t * allocator);
116 
118 /*
119  * This function registers a new transition in the transition map.
120  *
121  * <hr>
122  * Attribute | Adherence
123  * ------------------ | -------------
124  * Allocates Memory | Yes
125  * Thread-Safe | No
126  * Uses Atomics | No
127  * Lock-Free | Yes
128  *
129  * \param[in] transition_map to be modified
130  * \param[in] transition the transition to register
131  * \param[in] allocator a valid allocator used to register the state machine
132  * \return `RCL_RET_OK` if the state was deinitialized successfully, or
133  * \return `RCL_RET_BAD_ALLOC` if allocating memory failed, or
134  * \return `RCL_RET_ERROR` if an unspecified error occurs.
135  */
136 RCL_LIFECYCLE_PUBLIC
137 RCL_WARN_UNUSED
138 rcl_ret_t
139 rcl_lifecycle_register_transition(
140  rcl_lifecycle_transition_map_t * transition_map,
141  rcl_lifecycle_transition_t transition,
142  const rcl_allocator_t * allocator);
143 
145 /*
146  * A pointer to the internally lifecycle state struct is returned based on the `id`.
147  *
148  * <hr>
149  * Attribute | Adherence
150  * ------------------ | -------------
151  * Allocates Memory | No
152  * Thread-Safe | No
153  * Uses Atomics | No
154  * Lock-Free | Yes
155  *
156  * \param[in] transition_map
157  * \param[in] state_id
158  * \return pointer to a rcl_lifecycle_state_t or NULL if the state id doesn't exist
159  */
160 RCL_LIFECYCLE_PUBLIC
161 RCL_WARN_UNUSED
163 rcl_lifecycle_get_state(
164  rcl_lifecycle_transition_map_t * transition_map,
165  unsigned int state_id);
166 
168 /*
169  * A pointer to the internally lifecycle transition struct is returned based on the `label`.
170  *
171  * <hr>
172  * Attribute | Adherence
173  * ------------------ | -------------
174  * Allocates Memory | No
175  * Thread-Safe | No
176  * Uses Atomics | No
177  * Lock-Free | Yes
178  *
179  * \param[in] transition_map to be modified
180  * \param[in] state_id used to get the label to search
181  * \return pointer to a rcl_lifecycle_state_t or NULL if the state id doesn't exist
182  */
183 RCL_LIFECYCLE_PUBLIC
184 RCL_WARN_UNUSED
186 rcl_lifecycle_get_transitions(
187  rcl_lifecycle_transition_map_t * transition_map,
188  unsigned int transition_id);
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif // RCL_LIFECYCLE__TRANSITION_MAP_H_
rcl_lifecycle_state_t
It contains the state of the lifecycle state machine.
Definition: data_types.h:30
rcl_lifecycle_transition_map_t
It contains the transition map states and transitions.
Definition: data_types.h:58
rcl_lifecycle_transition_t
It contains the transitions of the lifecycle state machine.
Definition: data_types.h:44