HERMES Modem
Hermes ARQ/Broadcast modem
Loading...
Searching...
No Matches
fsm.h
Go to the documentation of this file.
1/* HERMES Modem
2 *
3 * Copyright (C) 2025 Rhizomatica
4 * Author: Rafael Diniz <rafael@riseup.net>
5 *
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef FSM_H
22#define FSM_H
23
24#include <pthread.h>
25
26/* ---- FSM Definitions ---- */
27
28/* FSM Events */
29// TNC TCP client event
30#define EV_CLIENT_CONNECT 0
31#define EV_CLIENT_DISCONNECT 1
32
33#define EV_START_LISTEN 2
34#define EV_STOP_LISTEN 3
35
36#define EV_LINK_CALL_REMOTE 4
37#define EV_LINK_INCOMING_CALL 5
38#define EV_LINK_DISCONNECT 6
39
40#define EV_LINK_ESTABLISHMENT_TIMEOUT 7
41
42#define EV_LINK_ESTABLISHED 8
43
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49extern const char* fsm_event_names[];
50
51#ifdef __cplusplus
52}
53#endif
54
56typedef void (*fsm_state)(int event);
57
59typedef struct {
61 pthread_mutex_t lock;
63
69void fsm_init(fsm_handle* fsm, fsm_state initial_state);
70
76void fsm_dispatch(fsm_handle* fsm, int event);
77
82void fsm_destroy(fsm_handle* fsm);
83
84#endif // FSM_H
void(* fsm_state)(int event)
State-handler function signature used by FSM dispatcher.
Definition fsm.h:56
void fsm_destroy(fsm_handle *fsm)
Destroy FSM synchronization resources.
Definition fsm.c:76
void fsm_dispatch(fsm_handle *fsm, int event)
Dispatch an event into current FSM state.
Definition fsm.c:53
const char * fsm_event_names[]
Definition fsm.c:28
void fsm_init(fsm_handle *fsm, fsm_state initial_state)
Initialize FSM instance.
Definition fsm.c:41
Thread-safe finite-state machine wrapper.
Definition fsm.h:59
pthread_mutex_t lock
Definition fsm.h:61
fsm_state current
Definition fsm.h:60