thermferm/statetbl.h

changeset 654
e981d0185485
child 655
780cc08df263
equal deleted inserted replaced
653:6c4c884be155 654:e981d0185485
1 /**
2 * @brief State table macro's
3 */
4
5 #ifndef STATETBL_H
6 #define STATETBL_H
7
8 #define SM_DECL(proc,name) \
9 int proc(void)\
10 {\
11 int sm_success=0;\
12 char *sm_name=name;
13
14 #define SM_STATES \
15 enum {
16
17 #define SM_NAMES \
18 } sm_state; \
19 char * sm_sname[] = {
20
21 #define SM_EDECL \
22 };
23
24 #define SM_START(x) \
25 sm_state=x;\
26 syslog(LOG_NOTICE, "SM (%s): Start => %s", sm_name, sm_sname[sm_state]); \
27 while (!sm_success) switch (sm_state)\
28 {\
29 default: syslog(LOG_WARNING, "Statemachine %s error: state=%d",sm_name,sm_state);\
30 sm_success=-1;
31
32 #define SM_STATE(x) \
33 break;\
34 case x:
35
36 #define SM_END \
37 }\
38
39 #define SM_RETURN \
40 return (sm_success != 1);\
41 }
42
43 #define SM_PROCEED(x) \
44 if (x != sm_state) {\
45 syslog(LOG_NOTICE, "SM (%s): %s => %s", sm_name, sm_sname[sm_state], sm_sname[x]);\
46 }\
47 sm_state=x; break;
48
49 #define SM_SUCCESS \
50 syslog(LOG_NOTICE, "SM (%s): %s => Success", sm_name, sm_sname[sm_state]);\
51 sm_success=1; break;
52
53 #define SM_ERROR \
54 syslog(LOG_WARNING, "SM (%s): %s => Error", sm_name, sm_sname[sm_state]);\
55 sm_success=-1; break;
56
57 #endif

mercurial