]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
fsm: Allow specifying state function visibility
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 14 May 2010 12:55:07 +0000 (14:55 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 14 May 2010 12:55:07 +0000 (14:55 +0200)
This is to allow declaration of some states as static and therefore
the same state name can be used in multiple files.

We use this to implement different strategies in different files and we
want to have less work inventing state names :-)

src/fsm/fsm.h

index 1cb497af4951d111fb99e79304efc70430afbc36..172613b848935c860c127db1c0f81e731f6baa3f 100644 (file)
@@ -448,6 +448,14 @@ static inline void call_transition_callback(struct robo_fsm *fsm)
 /* High level FSM API */
 /**********************/
 
+/**
+ * Specifies state function visibility.
+ *
+ * If this macro is redefined from "" (empty) to static, then the
+ * state functions are declared as static.
+ */
+#define FSM_STATE_VISIBILITY
+
 #define ___fsm_func_name(fsm, state, suf) fsm_state_##fsm##_##state##suf
 #define __fsm_func_name(fsm, state, suf) ___fsm_func_name(fsm, state, suf)
 
@@ -473,7 +481,7 @@ static inline void call_transition_callback(struct robo_fsm *fsm)
 #ifdef __FSM_NAME
 #define FSM_STATE(name)                                                        \
        static inline void __fsm_func_name(__FSM_NAME, name, _impl)(struct robo_fsm *fsm, int *__ret); \
-        int __fsm_func_name(__FSM_NAME, name,)(struct robo_fsm *fsm) { \
+        FSM_STATE_VISIBILITY int __fsm_func_name(__FSM_NAME, name,)(struct robo_fsm *fsm) { \
                int ret=RC_WAIT;                                        \
                DBG_FSM_STATE(#name);                                   \
                fsm->state_name = #name;                                \
@@ -492,7 +500,7 @@ static inline void call_transition_callback(struct robo_fsm *fsm)
  */
 #ifdef __FSM_NAME
 #define FSM_STATE_DECL(name) \
-int __fsm_func_name(__FSM_NAME, name,)(struct robo_fsm *fsm)
+FSM_STATE_VISIBILITY int __fsm_func_name(__FSM_NAME, name,)(struct robo_fsm *fsm)
 #else
 #define FSM_STATE_DECL(name) error FSM_XXX_not_defined
 #endif