sync/gen_statemachine.ysl2
changeset 609 a22a400611ca
parent 608 3bf69b382303
child 610 1e3d39516f43
     1.1 --- a/sync/gen_statemachine.ysl2	Thu May 12 10:45:54 2016 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu May 12 11:21:57 2016 +0200
     1.3 @@ -11,67 +11,78 @@
     1.4      key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
     1.5      variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
     1.6  
     1.7 -    template "/protocol/fsm"
     1.8 -    ||
     1.9 -    // state machine for «@name»
    1.10 +    template "/protocol/fsm" {
    1.11 +        document "../src/sync_fsm.h", "text"
    1.12 +        ||
    1.13 +        #pragma once
    1.14  
    1.15 -    #include "pEpEngine.h"
    1.16 +        // state machine for «@name»
    1.17  
    1.18 -    // types
    1.19 +        #include "pEpEngine.h"
    1.20  
    1.21 -    typedef pEp_identity * Identity;
    1.22 -    typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
    1.23 +        // types
    1.24  
    1.25 -    // error values
    1.26 +        typedef pEp_identity * Identity;
    1.27 +        typedef union _param { const Identity partner; const stringlist_t *keylist; } param_t;
    1.28  
    1.29 -    typedef enum _fsm_error {
    1.30 -        invalid_state = -1,
    1.31 -        invalid_event = -2
    1.32 -    } fsm_error;
    1.33 +        // error values
    1.34  
    1.35 -    // states
    1.36 +        typedef enum _fsm_error {
    1.37 +            invalid_state = -1,
    1.38 +            invalid_event = -2
    1.39 +        } fsm_error;
    1.40  
    1.41 -    typedef enum _«@name»_state {
    1.42 -    `` for "set:distinct(state/@name)" |> «.»`if "position()!=last()" > , `
    1.43 -    } «@name»_state;
    1.44 +        // states
    1.45  
    1.46 -    // events
    1.47 +        typedef enum _«@name»_state {
    1.48 +        `` for "set:distinct(state/@name)" |> «.»`if "position()!=last()" > , `
    1.49 +        } «@name»_state;
    1.50  
    1.51 -    typedef enum _«@name»_event {
    1.52 -    `` for "set:distinct(state/event/@name)" |> «.»`if "position()!=last()" > , `
    1.53 -    } «@name»_event;
    1.54 +        // events
    1.55  
    1.56 -    // actions
    1.57 +        typedef enum _«@name»_event {
    1.58 +        `` for "set:distinct(state/event/@name)" |> «.»`if "position()!=last()" > , `
    1.59 +        } «@name»_event;
    1.60  
    1.61 -    `` for "set:distinct(state/event//action/@name)" | void «.»(const Identity partner);
    1.62 +        // actions
    1.63  
    1.64 -    // decoders
    1.65 +        `` for "set:distinct(state/event//action/@name)" | void «.»(const Identity partner);
    1.66  
    1.67 -    `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'decode'"
    1.68 +        // driver
    1.69  
    1.70 -    // encoders 
    1.71 +        void fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
    1.72  
    1.73 -    `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'encode'"
    1.74 +        // decoders
    1.75  
    1.76 -    // state machine
    1.77 +        `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'decode'"
    1.78  
    1.79 -    «@name»_state fsm_«@name»(
    1.80 -            «@name»_state state,
    1.81 -            «@name»_event event,
    1.82 -            const Identity partner
    1.83 -        )
    1.84 -    {
    1.85 -        switch (state) {
    1.86 -            `` apply "state"
    1.87 -            default:
    1.88 -                return invalid_state;
    1.89 +        // encoders 
    1.90 +
    1.91 +        `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'encode'"
    1.92 +        ||
    1.93 +        ||
    1.94 +        #include "sync_fsm.h"
    1.95 +
    1.96 +        // state machine for «@name»
    1.97 +
    1.98 +        «@name»_state fsm_«@name»(
    1.99 +                «@name»_state state,
   1.100 +                «@name»_event event,
   1.101 +                const Identity partner
   1.102 +            )
   1.103 +        {
   1.104 +            switch (state) {
   1.105 +                `` apply "state"
   1.106 +                default:
   1.107 +                    return invalid_state;
   1.108 +            }
   1.109 +
   1.110 +            return state;
   1.111          }
   1.112  
   1.113 -        return state;
   1.114 +        ||
   1.115      }
   1.116  
   1.117 -    ||
   1.118 -
   1.119      template "state"
   1.120      ||
   1.121      case «@name»: