libosmocore 0.9.6-23.20170220git32ee5af8.fc42
Osmocom core library
|
Files | |
file | fsm.h |
Finite State Machine. | |
file | fsm.c |
Finite State Machine abstraction. | |
Data Structures | |
struct | osmo_fsm_state |
description of a rule in the FSM More... | |
struct | osmo_fsm |
a description of an osmocom finite state machine More... | |
struct | osmo_fsm_inst |
a single instanceof an osmocom finite state machine More... | |
Macros | |
#define | LOGPFSML(fi, level, fmt, args...) |
#define | LOGPFSM(fi, fmt, args...) |
#define | LOGPFSMLSRC(fi, level, caller_file, caller_line, fmt, args...) |
#define | LOGPFSMSRC(fi, caller_file, caller_line, fmt, args...) |
#define | osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T) |
perform a state change of the given FSM instance | |
#define | osmo_fsm_inst_dispatch(fi, event, data) |
dispatch an event to an osmocom finite state machine instance | |
#define | osmo_fsm_inst_term(fi, cause, data) |
Terminate FSM instance with given cause. | |
#define | osmo_fsm_inst_term_children(fi, cause, data) |
Terminate all child FSM instances of an FSM instance. | |
Enumerations | |
enum | osmo_fsm_term_cause { OSMO_FSM_TERM_PARENT , OSMO_FSM_TERM_REQUEST , OSMO_FSM_TERM_REGULAR , OSMO_FSM_TERM_ERROR , OSMO_FSM_TERM_TIMEOUT } |
Functions | |
static const char * | osmo_fsm_term_cause_name (enum osmo_fsm_term_cause cause) |
void | osmo_fsm_log_addr (bool log_addr) |
specify if FSM instance addresses should be logged or not | |
int | osmo_fsm_register (struct osmo_fsm *fsm) |
register a FSM with the core | |
void | osmo_fsm_unregister (struct osmo_fsm *fsm) |
unregister a FSM from the core | |
struct osmo_fsm * | osmo_fsm_find_by_name (const char *name) |
struct osmo_fsm_inst * | osmo_fsm_inst_alloc (struct osmo_fsm *fsm, void *ctx, void *priv, int log_level, const char *id) |
allocate a new instance of a specified FSM | |
struct osmo_fsm_inst * | osmo_fsm_inst_alloc_child (struct osmo_fsm *fsm, struct osmo_fsm_inst *parent, uint32_t parent_term_event) |
allocate a new instance of a specified FSM as child of other FSM instance | |
void | osmo_fsm_inst_free (struct osmo_fsm_inst *fi) |
delete a given instance of a FSM | |
const char * | osmo_fsm_event_name (struct osmo_fsm *fsm, uint32_t event) |
get human-readable name of FSM event | |
const char * | osmo_fsm_inst_name (struct osmo_fsm_inst *fi) |
get human-readable name of FSM instance | |
const char * | osmo_fsm_state_name (struct osmo_fsm *fsm, uint32_t state) |
get human-readable name of FSM instance | |
int | _osmo_fsm_inst_state_chg (struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line) |
perform a state change of the given FSM instance | |
int | _osmo_fsm_inst_dispatch (struct osmo_fsm_inst *fi, uint32_t event, void *data, const char *file, int line) |
dispatch an event to an osmocom finite state machine instance | |
void | _osmo_fsm_inst_term (struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause, void *data, const char *file, int line) |
Terminate FSM instance with given cause. | |
void | _osmo_fsm_inst_term_children (struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause, void *data, const char *file, int line) |
Terminate all child FSM instances of an FSM instance. | |
LLIST_HEAD (osmo_g_fsms) | |
static void | fsm_tmr_cb (void *data) |
Variables | |
const struct value_string | osmo_fsm_term_cause_names [] |
static bool | fsm_log_addr = true |
const struct value_string | osmo_fsm_term_cause_names [] |
#define LOGPFSM | ( | fi, | |
fmt, | |||
args... ) |
#define LOGPFSML | ( | fi, | |
level, | |||
fmt, | |||
args... ) |
#define LOGPFSMLSRC | ( | fi, | |
level, | |||
caller_file, | |||
caller_line, | |||
fmt, | |||
args... ) |
#define LOGPFSMSRC | ( | fi, | |
caller_file, | |||
caller_line, | |||
fmt, | |||
args... ) |
#define osmo_fsm_inst_dispatch | ( | fi, | |
event, | |||
data ) |
dispatch an event to an osmocom finite state machine instance
This is a macro that calls _osmo_fsm_inst_dispatch() with the given parameters as well as the caller's source file and line number for logging purposes. See there for documentation.
Referenced by osmo_fsm_inst_alloc_child().
#define osmo_fsm_inst_state_chg | ( | fi, | |
new_state, | |||
timeout_secs, | |||
T ) |
perform a state change of the given FSM instance
This is a macro that calls _osmo_fsm_inst_state_chg() with the given parameters as well as the caller's source file and line number for logging purposes. See there for documentation.
#define osmo_fsm_inst_term | ( | fi, | |
cause, | |||
data ) |
Terminate FSM instance with given cause.
This is a macro that calls _osmo_fsm_inst_term() with the given parameters as well as the caller's source file and line number for logging purposes. See there for documentation.
#define osmo_fsm_inst_term_children | ( | fi, | |
cause, | |||
data ) |
Terminate all child FSM instances of an FSM instance.
This is a macro that calls _osmo_fsm_inst_term_children() with the given parameters as well as the caller's source file and line number for logging purposes. See there for documentation.
enum osmo_fsm_term_cause |
int _osmo_fsm_inst_dispatch | ( | struct osmo_fsm_inst * | fi, |
uint32_t | event, | ||
void * | data, | ||
const char * | file, | ||
int | line ) |
dispatch an event to an osmocom finite state machine instance
Best invoke via the osmo_fsm_inst_dispatch() macro which logs the source file where the event was effected. Alternatively, you may pass file as NULL to use the normal file/line indication instead.
Any incoming events to osmo_fsm instances must be dispatched to them via this function. It verifies, whether the event is permitted based on the current state of the FSM. If not, -1 is returned.
[in] | fi | FSM instance |
[in] | event | Event to send to FSM instance |
[in] | data | Data to pass along with the event |
[in] | file | Calling source file (from osmo_fsm_inst_dispatch macro) |
[in] | line | Calling source line (from osmo_fsm_inst_dispatch macro) |
References osmo_fsm_state::action, osmo_fsm::allstate_action, osmo_fsm::allstate_event_mask, DLGLOBAL, osmo_fsm_inst::fsm, osmo_fsm_state::in_event_mask, LOGL_ERROR, LOGPSRC, osmo_fsm::num_states, OSMO_ASSERT, osmo_fsm_event_name(), osmo_fsm_inst::state, and osmo_fsm::states.
Referenced by _osmo_fsm_inst_term().
int _osmo_fsm_inst_state_chg | ( | struct osmo_fsm_inst * | fi, |
uint32_t | new_state, | ||
unsigned long | timeout_secs, | ||
int | T, | ||
const char * | file, | ||
int | line ) |
perform a state change of the given FSM instance
Best invoke via the osmo_fsm_inst_state_chg() macro which logs the source file where the state change was effected. Alternatively, you may pass file as NULL to use the normal file/line indication instead.
All changes to the FSM instance state must be made via this function. It verifies that the existing state actually permits a transiiton to new_state.
timeout_secs and T are optional parameters, and only have any effect if timeout_secs is not 0. If the timeout function is used, then the new_state is entered, and the FSM instances timer is set to expire in timeout_secs functions. At that time, the FSM's timer_cb function will be called for handling of the timeout by the user.
[in] | fi | FSM instance whose state is to change |
[in] | new_state | The new state into which we should change |
[in] | timeout_secs | Timeout in seconds (if !=0) |
[in] | T | Timer number (if timeout_secs != 0) |
[in] | file | Calling source file (from osmo_fsm_inst_state_chg macro) |
[in] | line | Calling source line (from osmo_fsm_inst_state_chg macro) |
References osmo_fsm_inst::fsm, LOGL_ERROR, osmo_fsm_state::onenter, osmo_fsm_state::onleave, osmo_fsm_state_name(), osmo_timer_del(), osmo_timer_schedule(), osmo_fsm_state::out_state_mask, osmo_fsm_inst::state, osmo_fsm::states, osmo_fsm_inst::T, and osmo_fsm_inst::timer.
void _osmo_fsm_inst_term | ( | struct osmo_fsm_inst * | fi, |
enum osmo_fsm_term_cause | cause, | ||
void * | data, | ||
const char * | file, | ||
int | line ) |
Terminate FSM instance with given cause.
This safely terminates the given FSM instance by first iterating over all children and sending them a termination event. Next, it calls the FSM descriptors cleanup function (if any), followed by releasing any memory associated with the FSM instance.
Finally, the parent FSM instance (if any) is notified using the parent termination event configured at time of FSM instance start.
[in] | fi | FSM instance to be terminated |
[in] | cause | Cause / reason for termination |
[in] | data | Opaque event data to be passed with the parent term event |
[in] | file | Calling source file (from osmo_fsm_inst_term macro) |
[in] | line | Calling source line (from osmo_fsm_inst_term macro) |
References _osmo_fsm_inst_dispatch(), _osmo_fsm_inst_term_children(), osmo_fsm_inst::child, osmo_fsm::cleanup, osmo_fsm_inst::fsm, llist_del(), osmo_fsm_inst_free(), osmo_fsm_inst_name(), OSMO_FSM_TERM_PARENT, osmo_fsm_inst::parent, osmo_fsm_inst::parent_term_event, and osmo_fsm_inst::proc.
Referenced by _osmo_fsm_inst_term_children().
void _osmo_fsm_inst_term_children | ( | struct osmo_fsm_inst * | fi, |
enum osmo_fsm_term_cause | cause, | ||
void * | data, | ||
const char * | file, | ||
int | line ) |
Terminate all child FSM instances of an FSM instance.
Iterate over all children and send them a termination event, with the given cause. Pass OSMO_FSM_TERM_PARENT to avoid dispatching events from the terminated child FSMs.
[in] | fi | FSM instance that should be cleared of child FSMs |
[in] | cause | Cause / reason for termination (OSMO_FSM_TERM_PARENT) |
[in] | data | Opaque event data to be passed with the parent term events |
[in] | file | Calling source file (from osmo_fsm_inst_term_children macro) |
[in] | line | Calling source line (from osmo_fsm_inst_term_children macro) |
References _osmo_fsm_inst_term(), osmo_fsm_inst::children, llist_empty(), llist_entry, LOGL_ERROR, llist_head::next, and osmo_fsm_inst::proc.
Referenced by _osmo_fsm_inst_term().
const char * osmo_fsm_event_name | ( | struct osmo_fsm * | fsm, |
uint32_t | event ) |
get human-readable name of FSM event
[in] | fsm | FSM descriptor of event |
[in] | event | Event integer value |
References osmo_fsm::event_names, osmo_fsm_inst::fsm, and get_value_string().
Referenced by _osmo_fsm_inst_dispatch().
struct osmo_fsm_inst * osmo_fsm_inst_alloc | ( | struct osmo_fsm * | fsm, |
void * | ctx, | ||
void * | priv, | ||
int | log_level, | ||
const char * | id ) |
allocate a new instance of a specified FSM
[in] | fsm | Descriptor of the FSM |
[in] | ctx | talloc context from which to allocate memory |
[in] | priv | private data reference store in fsm instance |
[in] | log_level | The log level for events of this FSM |
References osmo_timer_list::cb, osmo_fsm_inst::child, osmo_fsm_inst::children, osmo_timer_list::data, osmo_fsm_inst::fsm, osmo_fsm_inst::id, INIT_LLIST_HEAD, osmo_fsm::instances, osmo_fsm_inst::list, llist_add(), osmo_fsm_inst::log_level, osmo_fsm::name, osmo_fsm_inst::name, osmo_fsm_inst::priv, osmo_fsm_inst::proc, and osmo_fsm_inst::timer.
Referenced by osmo_fsm_inst_alloc_child().
struct osmo_fsm_inst * osmo_fsm_inst_alloc_child | ( | struct osmo_fsm * | fsm, |
struct osmo_fsm_inst * | parent, | ||
uint32_t | parent_term_event ) |
allocate a new instance of a specified FSM as child of other FSM instance
This is like osmo_fsm_inst_alloc but using the parent FSM as talloc context, and inheriting the log level of the parent.
[in] | fsm | Descriptor of the to-be-allocated FSM |
[in] | parent | Parent FSM instance |
[in] | parent_term_event | Event to be sent to parent when terminating |
References osmo_fsm_inst::child, osmo_fsm_inst::children, osmo_fsm_inst::fsm, osmo_fsm_inst::id, llist_add(), osmo_fsm_inst::log_level, osmo_fsm_inst_alloc(), osmo_fsm_inst_dispatch, osmo_fsm_inst_name(), osmo_fsm_inst::parent, osmo_fsm_inst::parent_term_event, and osmo_fsm_inst::proc.
void osmo_fsm_inst_free | ( | struct osmo_fsm_inst * | fi | ) |
delete a given instance of a FSM
[in] | fsm | The FSM to be un-registered and deleted |
References osmo_fsm_inst::list, llist_del(), osmo_timer_del(), and osmo_fsm_inst::timer.
Referenced by _osmo_fsm_inst_term().
const char * osmo_fsm_inst_name | ( | struct osmo_fsm_inst * | fi | ) |
get human-readable name of FSM instance
[in] | fi | FSM instance |
References osmo_fsm_inst::fsm, osmo_fsm::name, and osmo_fsm_inst::name.
Referenced by _osmo_fsm_inst_term(), and osmo_fsm_inst_alloc_child().
void osmo_fsm_log_addr | ( | bool | log_addr | ) |
specify if FSM instance addresses should be logged or not
By default, the FSM name includes the pointer address of the osmo_fsm_inst. This behavior can be disabled (and re-enabled) using this function.
[in] | log_addr | Indicate if FSM instance address shall be logged |
int osmo_fsm_register | ( | struct osmo_fsm * | fsm | ) |
register a FSM with the core
A FSM descriptor needs to be registered with the core before any instances can be created for it.
[in] | fsm | Descriptor of Finite State Machine to be registered |
References INIT_LLIST_HEAD, osmo_fsm::instances, osmo_fsm::list, llist_add_tail(), and osmo_fsm::name.
const char * osmo_fsm_state_name | ( | struct osmo_fsm * | fsm, |
uint32_t | state ) |
get human-readable name of FSM instance
[in] | fsm | FSM descriptor |
[in] | state | FSM state number |
References osmo_fsm_inst::fsm, osmo_fsm_state::name, osmo_fsm::num_states, osmo_fsm_inst::state, and osmo_fsm::states.
Referenced by _osmo_fsm_inst_state_chg().
void osmo_fsm_unregister | ( | struct osmo_fsm * | fsm | ) |
unregister a FSM from the core
Once the FSM descriptor is unregistered, active instances can still use it, but no new instances may be created for it.
[in] | fsm | Descriptor of Finite State Machine to be removed |
References osmo_fsm::list, and llist_del().
const struct value_string osmo_fsm_term_cause_names[] |