The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions
machine.h File Reference

State machine functions. More...

#include <freeradius-devel/util/dcursor.h>
+ Include dependency graph for machine.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  fr_machine_def_t
 
struct  fr_machine_state_s
 

Macros

#define ALLOW(_x)   .allowed[_x] = true
 
#define ENTER(_x)   static int MACHINE ## _enter ## _x(fr_machine_t *m, void *uctx)
 
#define EXIT(_x)   static int MACHINE ## _exit ## _x(fr_machine_t *m, void *uctx)
 
#define MACHINE   radius
 
#define PROCESS(_x)   static int MACHINE ## _process ## _x(fr_machine_t *m, void *uctx)
 

Typedefs

typedef void(* fr_machine_func_t) (fr_machine_t *m, void *uctx)
 
typedef void(* fr_machine_hook_func_t) (fr_machine_t *m, int, int, void *uctx)
 
typedef int(* fr_machine_process_t) (fr_machine_t *m, void *uctx)
 
typedef int(* fr_machine_signal_t) (fr_machine_t *m, int sig, void *uctx)
 
typedef struct fr_machine_state_s fr_machine_state_t
 
typedef struct fr_machine_s fr_machine_t
 

Enumerations

enum  fr_machine_hook_sense_t {
  FR_MACHINE_PRE = 0 ,
  FR_MACHINE_POST
}
 
enum  fr_machine_hook_type_t {
  FR_MACHINE_ENTER ,
  FR_MACHINE_PROCESS ,
  FR_MACHINE_EXIT ,
  FR_MACHINE_SIGNAL
}
 

Functions

fr_machine_tfr_machine_alloc (TALLOC_CTX *ctx, fr_machine_def_t const *def, void *uctx)
 Instantiate a state machine. More...
 
int fr_machine_current (fr_machine_t *m)
 Get the current state. More...
 
void * fr_machine_hook (fr_machine_t *m, TALLOC_CTX *ctx, int state, fr_machine_hook_type_t type, fr_machine_hook_sense_t sense, bool oneshot, fr_machine_hook_func_t func, void *uctx)
 Add a hook to a state, with an optional talloc_ctx. More...
 
void fr_machine_pause (fr_machine_t *m)
 Pause any transitions. More...
 
int fr_machine_process (fr_machine_t *m)
 Process the state machine. More...
 
void fr_machine_resume (fr_machine_t *m)
 Resume transitions. More...
 
int fr_machine_signal (fr_machine_t *m, int signal)
 Send an async signal to the state machine. More...
 
char const * fr_machine_state_name (fr_machine_t *m, int state)
 Get the name of a particular state. More...
 
int fr_machine_transition (fr_machine_t *m, int state)
 Transition to a new state. More...
 

Detailed Description

State machine functions.

Definition in file machine.h.


Data Structure Documentation

◆ fr_machine_def_t

struct fr_machine_def_t

Definition at line 52 of file machine.h.

+ Collaboration diagram for fr_machine_def_t:
Data Fields
int free state to run on free
int init state to run on init
int max_signal 1..max signals are permitted
int max_state 1..max states are permitted
fr_machine_state_t state[] states

◆ fr_machine_state_s

struct fr_machine_state_s

Definition at line 40 of file machine.h.

+ Collaboration diagram for fr_machine_state_s:
Data Fields
bool * allowed allow outbound transitions
fr_machine_func_t enter run this when entering the state
fr_machine_func_t exit run this when exiting the state
char const * name state name
int number enum for this state machine
fr_machine_process_t process run this to process the current state
fr_machine_signal_t signal to send async signals to the state machine

Macro Definition Documentation

◆ ALLOW

#define ALLOW (   _x)    .allowed[_x] = true

Definition at line 50 of file machine.h.

◆ ENTER

#define ENTER (   _x)    static int MACHINE ## _enter ## _x(fr_machine_t *m, void *uctx)

Definition at line 93 of file machine.h.

◆ EXIT

#define EXIT (   _x)    static int MACHINE ## _exit ## _x(fr_machine_t *m, void *uctx)

Definition at line 94 of file machine.h.

◆ MACHINE

#define MACHINE   radius

Definition at line 91 of file machine.h.

◆ PROCESS

#define PROCESS (   _x)    static int MACHINE ## _process ## _x(fr_machine_t *m, void *uctx)

Definition at line 95 of file machine.h.

Typedef Documentation

◆ fr_machine_func_t

typedef void(* fr_machine_func_t) (fr_machine_t *m, void *uctx)

Definition at line 32 of file machine.h.

◆ fr_machine_hook_func_t

typedef void(* fr_machine_hook_func_t) (fr_machine_t *m, int, int, void *uctx)

Definition at line 38 of file machine.h.

◆ fr_machine_process_t

typedef int(* fr_machine_process_t) (fr_machine_t *m, void *uctx)

Definition at line 34 of file machine.h.

◆ fr_machine_signal_t

typedef int(* fr_machine_signal_t) (fr_machine_t *m, int sig, void *uctx)

Definition at line 36 of file machine.h.

◆ fr_machine_state_t

Definition at line 1 of file machine.h.

◆ fr_machine_t

typedef struct fr_machine_s fr_machine_t

Definition at line 1 of file machine.h.

Enumeration Type Documentation

◆ fr_machine_hook_sense_t

Enumerator
FR_MACHINE_PRE 
FR_MACHINE_POST 

Definition at line 83 of file machine.h.

◆ fr_machine_hook_type_t

Enumerator
FR_MACHINE_ENTER 
FR_MACHINE_PROCESS 
FR_MACHINE_EXIT 
FR_MACHINE_SIGNAL 

Definition at line 76 of file machine.h.

Function Documentation

◆ fr_machine_alloc()

fr_machine_t* fr_machine_alloc ( TALLOC_CTX *  ctx,
fr_machine_def_t const *  def,
void *  uctx 
)

Instantiate a state machine.

Parameters
ctxthe talloc ctx
defthe definition of the state machine
uctxthe context passed to the callbacks
Returns
  • NULL on error
  • !NULL state machine which can be used.

Definition at line 175 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_current()

int fr_machine_current ( fr_machine_t m)

Get the current state.

Parameters
mThe state machine
Returns
The current state, or 0 for "not in any state"

Definition at line 467 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_hook()

void* fr_machine_hook ( fr_machine_t m,
TALLOC_CTX *  ctx,
int  state_to_hook,
fr_machine_hook_type_t  type,
fr_machine_hook_sense_t  sense,
bool  oneshot,
fr_machine_hook_func_t  func,
void *  uctx 
)

Add a hook to a state, with an optional talloc_ctx.

The hook is removed when the talloc ctx is freed.

You can also remove the hook by freeing the returned pointer.

Definition at line 515 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_pause()

void fr_machine_pause ( fr_machine_t m)

Pause any transitions.

Definition at line 565 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_process()

int fr_machine_process ( fr_machine_t m)

Process the state machine.

Parameters
mThe state machine
Returns
  • 0 for "no transition has occurred"
  • >0 for "we are in a new state". -<0 for "error, you should tear down the state machine".

This function should be called by the user of the machine.

In general, the caller doesn't really care about the return code of this function. The only real utility is >=0 for "continue calling the state machine as necessary", or <0 for "shut down the state machine".

Definition at line 304 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_resume()

void fr_machine_resume ( fr_machine_t m)

Resume transitions.

Definition at line 575 of file machine.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_machine_signal()

int fr_machine_signal ( fr_machine_t m,
int  signal 
)

Send an async signal to the state machine.

Parameters
mThe state machine
signalthe signal to send to the state machne
Returns
  • 0 for "no transition has occurred"
  • >0 for "we are in a new state". -<0 for "error, you should tear down the state machine".

The signal function can return a new state. i.e. some signals get ignored, and others cause transitions.

Definition at line 619 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_state_name()

char const* fr_machine_state_name ( fr_machine_t m,
int  state 
)

Get the name of a particular state.

Parameters
mThe state machine
stateThe state to query
Returns
the name

Definition at line 483 of file machine.c.

+ Here is the call graph for this function:

◆ fr_machine_transition()

int fr_machine_transition ( fr_machine_t m,
int  state 
)

Transition to a new state.

Parameters
mThe state machine
statethe state to transition to
Returns
  • <0 for error
  • 0 for the transition was made (or deferred)

The transition MAY be deferred. Note that only one transition at a time can be deferred.

This function MUST NOT be called from any "hook", or from any enter/exit/process function. It should ONLY be called from the "parent" of the state machine, when it decides that the state machine needs to change.

i.e. from a timer, or an IO callback

Definition at line 394 of file machine.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: