Haka: include/haka/state_machine.h Source File

Haka

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

state_machine.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 #ifndef STATE_MACHINE_H
6 #define STATE_MACHINE_H
7
8 #include <haka/container/vector.h>
9 #include <haka/time.h>
10
11
12 struct state;
13 struct state_machine;
14 struct transition_data;
15 struct state_machine_instance;
16
17 typedef struct state *(*transition_callback)(struct state_machine_instance *state_machine, struct transition_data *data);
18
19 struct transition_data {
20 transition_callback callback;
21 void (*destroy)(struct transition_data *data);
22 };
23
24 struct state_machine_context {
25 void (*destroy)(struct state_machine_context *data);
26 };
27
28 struct state_machine *state_machine_create(const char *name);
29 void state_machine_destroy(struct state_machine *machine);
30 bool state_machine_compile(struct state_machine *machine);
31 struct state *state_machine_create_state(struct state_machine *state_machine, const char *name);
32 extern struct state * const state_machine_fail_state;
33 extern struct state * const state_machine_finish_state;
34 bool state_machine_set_initial(struct state_machine *machine, struct state *initial);
35
36 bool state_add_timeout_transition(struct state *state, struct time *timeout, struct transition_data *data);
37 bool state_set_fail_transition(struct state *state, struct transition_data *data);
38 bool state_set_enter_transition(struct state *state, struct transition_data *data);
39 bool state_set_leave_transition(struct state *state, struct transition_data *data);
40 bool state_set_init_transition(struct state *state, struct transition_data *data);
41 bool state_set_finish_transition(struct state *state, struct transition_data *data);
42 const char *state_name(struct state *state);
43
44 struct state_machine_instance *state_machine_instance(struct state_machine *machine, struct state_machine_context *context);
45 struct state_machine *state_machine_instance_get(struct state_machine_instance *instance);
46 struct state_machine_context *state_machine_instance_context(struct state_machine_instance *instance);
47 void state_machine_instance_init(struct state_machine_instance *instance);
48 void state_machine_instance_finish(struct state_machine_instance *instance);
49 void state_machine_instance_destroy(struct state_machine_instance *instance);
50 void state_machine_instance_update(struct state_machine_instance *instance, struct state *newstate);
51 void state_machine_instance_fail(struct state_machine_instance *instance);
52 struct state *state_machine_instance_state(struct state_machine_instance *instance);
53 bool state_machine_instance_isfinished(struct state_machine_instance *instance);
54 bool state_machine_instance_isfailed(struct state_machine_instance *instance);
55
56 #endif /* STATE_MACHINE_H */
time.h
time
Definition: time.h:21