8 /* Callback funtions prototypes */
9 static unsigned int fsm_hashf(const void *key
);
10 static int fsm_cmpf(const void *arg1
, const void *arg2
);
11 static void fsm_printf(const void *key
, const void *data
);
13 fsmret_t
fsm_init(fsm_t
**fsm
, size_t size
, unsigned int factor
)
15 /* Allocate memory fsm's state table */
16 if ((*fsm
= malloc(sizeof *fsm
)) == NULL
)
19 if (((*fsm
)->sttable
= malloc(sizeof *(*fsm
)->sttable
)) == NULL
) {
24 if (htable_init((*fsm
)->sttable
, size
, factor
,
25 fsm_hashf
, fsm_cmpf
, fsm_printf
) == HT_NOMEM
) {
26 free((*fsm
)->sttable
);
34 fsmret_t
fsm_add_state(fsm_t
*fsm
, unsigned int key
, state_t
*state
)
38 /* Allocate memory for new key */
39 if ((pkey
= malloc(sizeof *pkey
)) == NULL
)
44 /* Insert event to hash table */
45 if (htable_insert(fsm
->sttable
, pkey
, state
) == HT_EXISTS
) {
53 fsmret_t
fsm_free(fsm_t
*fsm
)
55 htable_free_all_obj(fsm
->sttable
, 0);
56 htable_free(fsm
->sttable
);
63 void fsm_print_states(const fsm_t
*fsm
)
65 htable_print(fsm
->sttable
);
68 /* Callback funtions */
69 static unsigned int fsm_hashf(const void *key
)
71 return *(const unsigned int *)key
;
74 static int fsm_cmpf(const void *arg1
, const void *arg2
)
76 unsigned int a
= *(const unsigned int *)arg1
;
77 unsigned int b
= *(const unsigned int *)arg2
;
87 static void fsm_printf(const void *key
, const void *data
)
90 *(const unsigned int *)key
);