-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhfsm_hardcoded.h
59 lines (48 loc) · 1.44 KB
/
hfsm_hardcoded.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef HFSM_HARDCODED_H
#define HFSM_HARDCODED_H
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <hfsm.h>
typedef struct hfsm hfsm;
typedef int (*state_handler)(hfsm* me, hfsm_event event);
typedef state_handler (*get_parent)(state_handler child_state);
struct hfsm
{
state_handler current_state;
get_parent get_parent_func;
};
#define RET_HANDLE_BY_SUPERSTATE -1
int hfsm_init(
hfsm* h,
state_handler initial_state,
get_parent get_parent_func);
/*
Supported transitions limited to the following:
- peer states (within the same top-level state).
- super state transitioning to another peer state (all sub-states will exit).
*/
int hfsm_transition_peer(
hfsm* h,
state_handler source_state,
state_handler destination_state);
/*
Supported transitions limited to the following:
- peer state transitioning to first-level inner state.
- super state transitioning to another first-level inner state.
*/
int hfsm_transition_substate(
hfsm* h,
state_handler source_state,
state_handler destination_state);
/*
Supported transitions limited to the following:
- peer state transitioning to first-level inner state.
- super state transitioning to another first-level inner state.
*/
int hfsm_transition_superstate(
hfsm* h,
state_handler source_state,
state_handler destination_state);
int hfsm_post_event(hfsm* h, hfsm_event event);
#endif //!HFSM_HARDCODED_H