State machine functions.
More...
#include <freeradius-devel/util/dcursor.h>
Go to the source code of this file.
|
fr_machine_t * | fr_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...
|
|
State machine functions.
- Copyright
- 2021 Network RADIUS SAS (legal.nosp@m.@net.nosp@m.workr.nosp@m.adiu.nosp@m.s.com)
Definition in file machine.h.
◆ fr_machine_def_t
Definition at line 52 of file machine.h.
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 |
◆ ALLOW
◆ ENTER
◆ EXIT
◆ MACHINE
◆ PROCESS
◆ fr_machine_func_t
◆ fr_machine_hook_func_t
◆ fr_machine_process_t
◆ fr_machine_signal_t
◆ fr_machine_state_t
◆ fr_machine_t
◆ 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.
◆ fr_machine_alloc()
Instantiate a state machine.
- Parameters
-
ctx | the talloc ctx |
def | the definition of the state machine |
uctx | the context passed to the callbacks |
- Returns
- NULL on error
- !NULL state machine which can be used.
Definition at line 175 of file machine.c.
◆ fr_machine_current()
Get the current state.
- Parameters
-
- Returns
- The current state, or 0 for "not in any state"
Definition at line 467 of file machine.c.
◆ fr_machine_hook()
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.
◆ fr_machine_pause()
Pause any transitions.
Definition at line 565 of file machine.c.
◆ fr_machine_process()
Process the state machine.
- Parameters
-
- 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.
◆ fr_machine_resume()
Resume transitions.
Definition at line 575 of file machine.c.
◆ fr_machine_signal()
Send an async signal to the state machine.
- Parameters
-
m | The state machine |
signal | the 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.
◆ fr_machine_state_name()
char const* fr_machine_state_name |
( |
fr_machine_t * |
m, |
|
|
int |
state |
|
) |
| |
Get the name of a particular state.
- Parameters
-
m | The state machine |
state | The state to query |
- Returns
- the name
Definition at line 483 of file machine.c.
◆ fr_machine_transition()
Transition to a new state.
- Parameters
-
m | The state machine |
state | the 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.