...
authorVolker Birk <vb@pep-project.org>
Thu, 05 May 2016 14:18:42 +0200
changeset 578b313077e13f2
parent 577 26ebb2727295
child 579 99a3e946928a
...
sync/gen_statemachine.ysl2
     1.1 --- a/sync/gen_statemachine.ysl2	Thu May 05 13:46:01 2016 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu May 05 14:18:42 2016 +0200
     1.3 @@ -13,23 +13,56 @@
     1.4  
     1.5      #include "pEpEngine.h"
     1.6  
     1.7 +    typedef enum _fsm_error {
     1.8 +        invalid_state = -1,
     1.9 +        invalid_event = -2
    1.10 +    } fsm_error;
    1.11  
    1.12 -    void sm_«@name»(«@name»_state state)
    1.13 +    typedef enum _«@name»_state {
    1.14 +    `` apply "state", mode=declare
    1.15 +    } «@name»_state;
    1.16 +
    1.17 +    typedef enum _«@name»_event {
    1.18 +    `` apply "state/event", mode=declare
    1.19 +    } «@name»_event;
    1.20 +
    1.21 +    «@name»_state sm_«@name»(«@name»_state state, «@name»_event event)
    1.22      {
    1.23          switch (state) {
    1.24 -            `` apply "state"
    1.25 +            `` apply "state", mode=implement
    1.26 +            default:
    1.27 +                return invalid_state;
    1.28          }
    1.29      }
    1.30  
    1.31      ||
    1.32  
    1.33 -    template "state"
    1.34 +    template "state", mode=declare
    1.35 +        | «@name»`if "position()!=last()" > , `
    1.36 +
    1.37 +    template "state", mode=implement
    1.38      ||
    1.39      case «@name»:
    1.40 -        // bla
    1.41 +        switch (event) {
    1.42 +        `` apply "event", 2
    1.43 +        default:
    1.44 +            return invalid_event;
    1.45 +        }
    1.46          break;
    1.47  
    1.48      ||
    1.49 +
    1.50 +    template "event", mode=declare
    1.51 +        | «@name»`if "position()!=last()" > , `
    1.52 +
    1.53 +    template "event"
    1.54 +    ||
    1.55 +    case «@name»:
    1.56 +    `` apply "action|transition";
    1.57 +        break;
    1.58 +    ||
    1.59 +
    1.60 +    template "action" | «@name»();
    1.61 +    template "transition" | return «@target»;
    1.62  }
    1.63  
    1.64 -