libosmocore 1.9.0.196-9975
Osmocom core library

Finite State Machine. More...

#include <stdint.h>
#include <stdbool.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>

Go to the source code of this file.

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 LOGPFSMSL(fi, subsys, level, fmt, args...)    LOGPFSMSLSRC(fi, subsys, level, __FILE__, __LINE__, fmt, ## args)
 Log using FSM instance's context, on explicit logging subsystem and level. More...
 
#define LOGPFSMSLSRC(fi, subsys, level, caller_file, caller_line, fmt, args...)
 Log using FSM instance's context, on explicit logging subsystem and level, and passing explicit source file and line information. More...
 
#define LOGPFSML(fi, level, fmt, args...)    LOGPFSMLSRC(fi, level, __FILE__, __LINE__, fmt, ## args)
 Log using FSM instance's context, on explicit logging level. More...
 
#define LOGPFSMLSRC(fi, level, caller_file, caller_line, fmt, args...)
 Log using FSM instance's context, on explicit logging level, and with explicit source file and line info. More...
 
#define LOGPFSM(fi, fmt, args...)    LOGPFSML(fi, (fi) ? (fi)->log_level : LOGL_ERROR, fmt, ## args)
 Log using FSM instance's context. More...
 
#define LOGPFSMSRC(fi, caller_file, caller_line, fmt, args...)
 Log using FSM instance's context, with explicit source file and line info. More...
 
#define OSMO_T_FMT   "%c%u"
 
#define OSMO_T_FMT_ARGS(T)   ((T) >= 0 ? 'T' : 'X'), ((T) >= 0 ? (T) : -(T))
 
#define osmo_fsm_inst_state_chg(fi, new_state, timeout_secs, T)
 perform a state change of the given FSM instance More...
 
#define osmo_fsm_inst_state_chg_ms(fi, new_state, timeout_ms, T)
 
#define osmo_fsm_inst_state_chg_keep_timer(fi, new_state)
 perform a state change while keeping the current timer running. More...
 
#define osmo_fsm_inst_state_chg_keep_or_start_timer(fi, new_state, timeout_secs, T)
 perform a state change while keeping the current timer if running, or starting a timer otherwise. More...
 
#define osmo_fsm_inst_state_chg_keep_or_start_timer_ms(fi, new_state, timeout_ms, T)
 
#define osmo_fsm_inst_dispatch(fi, event, data)    _osmo_fsm_inst_dispatch(fi, event, data, __FILE__, __LINE__)
 dispatch an event to an osmocom finite state machine instance More...
 
#define osmo_fsm_inst_term(fi, cause, data)    _osmo_fsm_inst_term(fi, cause, data, __FILE__, __LINE__)
 Terminate FSM instance with given cause. More...
 
#define osmo_fsm_inst_term_children(fi, cause, data)    _osmo_fsm_inst_term_children(fi, cause, data, __FILE__, __LINE__)
 Terminate all child FSM instances of an FSM instance. More...
 
#define osmo_fsm_inst_broadcast_children(fi, cause, data)    _osmo_fsm_inst_broadcast_children(fi, cause, data, __FILE__, __LINE__)
 dispatch an event to all children of an osmocom finite state machine instance More...
 

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 More...
 
void osmo_fsm_log_timeouts (bool log_timeouts)
 Enable or disable logging of timeout values for FSM instance state changes. More...
 
void osmo_fsm_term_safely (bool term_safely)
 Enable safer way to deallocate cascades of terminating FSM instances. More...
 
void osmo_fsm_set_dealloc_ctx (void *ctx)
 Instead of deallocating FSM instances, move them to the given talloc context. More...
 
int osmo_fsm_register (struct osmo_fsm *fsm)
 register a FSM with the core More...
 
void osmo_fsm_unregister (struct osmo_fsm *fsm)
 unregister a FSM from the core More...
 
struct osmo_fsmosmo_fsm_find_by_name (const char *name)
 
struct osmo_fsm_instosmo_fsm_inst_find_by_name (const struct osmo_fsm *fsm, const char *name)
 
struct osmo_fsm_instosmo_fsm_inst_find_by_id (const struct osmo_fsm *fsm, const char *id)
 
struct osmo_fsm_instosmo_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 More...
 
struct osmo_fsm_instosmo_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 More...
 
void osmo_fsm_inst_unlink_parent (struct osmo_fsm_inst *fi, void *ctx)
 unlink child FSM from its parent FSM. More...
 
void osmo_fsm_inst_change_parent (struct osmo_fsm_inst *fi, struct osmo_fsm_inst *new_parent, uint32_t new_parent_term_event)
 change parent instance of an FSM. More...
 
void osmo_fsm_inst_free (struct osmo_fsm_inst *fi)
 delete a given instance of a FSM More...
 
int osmo_fsm_inst_update_id (struct osmo_fsm_inst *fi, const char *id)
 Change id of the FSM instance. More...
 
int osmo_fsm_inst_update_id_f (struct osmo_fsm_inst *fi, const char *fmt,...)
 Change id of the FSM instance using a string format. More...
 
int osmo_fsm_inst_update_id_f_sanitize (struct osmo_fsm_inst *fi, char replace_with, const char *fmt,...)
 Change id of the FSM instance using a string format, and ensuring a valid id. More...
 
const char * osmo_fsm_event_name (const struct osmo_fsm *fsm, uint32_t event)
 get human-readable name of FSM event More...
 
const char * osmo_fsm_inst_name (const struct osmo_fsm_inst *fi)
 get human-readable name of FSM instance More...
 
const char * osmo_fsm_state_name (const struct osmo_fsm *fsm, uint32_t state)
 get human-readable name of FSM state More...
 
static const char * osmo_fsm_inst_state_name (struct osmo_fsm_inst *fi)
 return the name of the state the FSM instance is currently in. More...
 
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 More...
 
int _osmo_fsm_inst_state_chg_ms (struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_ms, int T, const char *file, int line)
 
int _osmo_fsm_inst_state_chg_keep_timer (struct osmo_fsm_inst *fi, uint32_t new_state, const char *file, int line)
 perform a state change while keeping the current timer running. More...
 
int _osmo_fsm_inst_state_chg_keep_or_start_timer (struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_secs, int T, const char *file, int line)
 perform a state change while keeping the current timer if running, or starting a timer otherwise. More...
 
int _osmo_fsm_inst_state_chg_keep_or_start_timer_ms (struct osmo_fsm_inst *fi, uint32_t new_state, unsigned long timeout_ms, int T, const char *file, int line)
 
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 More...
 
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. More...
 
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. More...
 
void _osmo_fsm_inst_broadcast_children (struct osmo_fsm_inst *fi, uint32_t event, void *data, const char *file, int line)
 Broadcast an event to all the FSMs children. More...
 

Variables

const struct value_string osmo_fsm_term_cause_names []
 

Detailed Description

Finite State Machine.