The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
machine.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** State machine functions
19  *
20  * @file src/lib/util/machine.h
21  *
22  * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
23  */
24 RCSIDH(machine_h, "$Id: 2aebc0e75c54b66970a6dba6d0d557057a829b86 $")
25 
26 #include <freeradius-devel/util/dcursor.h>
27 
29 
30 typedef struct fr_machine_s fr_machine_t;
31 
32 typedef void (*fr_machine_func_t)(fr_machine_t *m, void *uctx);
33 
34 typedef int (*fr_machine_process_t)(fr_machine_t *m, void *uctx);
35 
36 typedef int (*fr_machine_signal_t)(fr_machine_t *m, int sig, void *uctx);
37 
38 typedef void (*fr_machine_hook_func_t)(fr_machine_t *m, int, int, void *uctx);
39 
41  char const *name; //!< state name
42  int number; //!< enum for this state machine
43  fr_machine_func_t enter; //!< run this when entering the state
44  fr_machine_process_t process; //!< run this to process the current state
45  fr_machine_func_t exit; //!< run this when exiting the state
46  fr_machine_signal_t signal; //!< to send async signals to the state machine
47  bool *allowed; //!< allow outbound transitions
48 };
49 
50 #define ALLOW(_x) .allowed[_x] = true
51 
52 typedef struct {
53  int max_state; //!< 1..max states are permitted
54  int max_signal; //!< 1..max signals are permitted
55  int init; //!< state to run on init
56  int free; //!< state to run on free
57  fr_machine_state_t state[]; //!< states
59 
60 fr_machine_t *fr_machine_alloc(TALLOC_CTX *ctx, fr_machine_def_t const *def, void *uctx);
61 
63 
64 int fr_machine_transition(fr_machine_t *m, int state);
65 
66 int fr_machine_signal(fr_machine_t *m, int signal);
67 
69 
71 
73 
74 char const *fr_machine_state_name(fr_machine_t *m, int state);
75 
76 typedef enum {
82 
83 typedef enum {
87 
88 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,
89  bool oneshot, fr_machine_hook_func_t func, void *uctx);
90 
91 #define MACHINE radius
92 
93 #define ENTER(_x) static int MACHINE ## _enter ## _x(fr_machine_t *m, void *uctx)
94 #define EXIT(_x) static int MACHINE ## _exit ## _x(fr_machine_t *m, void *uctx)
95 #define PROCESS(_x) static int MACHINE ## _process ## _x(fr_machine_t *m, void *uctx)
96 
#define RCSIDH(h, id)
Definition: build.h:482
fr_dcursor_eval_t void const * uctx
Definition: dcursor.h:546
Hooks.
Definition: machine.c:43
int max_signal
1..max signals are permitted
Definition: machine.h:54
int fr_machine_signal(fr_machine_t *m, int signal)
Send an async signal to the state machine.
Definition: machine.c:619
int(* fr_machine_signal_t)(fr_machine_t *m, int sig, void *uctx)
Definition: machine.h:36
fr_machine_hook_type_t
Definition: machine.h:76
@ FR_MACHINE_PROCESS
Definition: machine.h:78
@ FR_MACHINE_SIGNAL
Definition: machine.h:80
@ FR_MACHINE_ENTER
Definition: machine.h:77
@ FR_MACHINE_EXIT
Definition: machine.h:79
int free
state to run on free
Definition: machine.h:56
int fr_machine_process(fr_machine_t *m)
Process the state machine.
Definition: machine.c:304
fr_machine_process_t process
run this to process the current state
Definition: machine.h:44
fr_machine_func_t exit
run this when exiting the state
Definition: machine.h:45
int(* fr_machine_process_t)(fr_machine_t *m, void *uctx)
Definition: machine.h:34
int number
enum for this state machine
Definition: machine.h:42
char const * fr_machine_state_name(fr_machine_t *m, int state)
Get the name of a particular state.
Definition: machine.c:483
char const * name
state name
Definition: machine.h:41
void(* fr_machine_func_t)(fr_machine_t *m, void *uctx)
Definition: machine.h:32
void fr_machine_resume(fr_machine_t *m)
Resume transitions.
Definition: machine.c:575
int fr_machine_transition(fr_machine_t *m, int state)
Transition to a new state.
Definition: machine.c:394
void(* fr_machine_hook_func_t)(fr_machine_t *m, int, int, void *uctx)
Definition: machine.h:38
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.
Definition: machine.c:515
void fr_machine_pause(fr_machine_t *m)
Pause any transitions.
Definition: machine.c:565
int init
state to run on init
Definition: machine.h:55
int max_state
1..max states are permitted
Definition: machine.h:53
fr_machine_signal_t signal
to send async signals to the state machine
Definition: machine.h:46
fr_machine_hook_sense_t
Definition: machine.h:83
@ FR_MACHINE_POST
Definition: machine.h:85
@ FR_MACHINE_PRE
Definition: machine.h:84
int fr_machine_current(fr_machine_t *m)
Get the current state.
Definition: machine.c:467
fr_machine_t * fr_machine_alloc(TALLOC_CTX *ctx, fr_machine_def_t const *def, void *uctx)
Instantiate a state machine.
Definition: machine.c:175
fr_machine_func_t enter
run this when entering the state
Definition: machine.h:43
bool * allowed
allow outbound transitions
Definition: machine.h:47
fr_aka_sim_id_type_t type