sync/gen_statemachine.ysl2
changeset 690 3ae86b68fdfe
parent 654 0aa96447e38f
child 711 d88dea0f5448
     1.1 --- a/sync/gen_statemachine.ysl2	Fri May 27 11:46:24 2016 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Sun May 29 12:21:50 2016 +0200
     1.3 @@ -37,18 +37,21 @@
     1.4          // states
     1.5  
     1.6          typedef enum _«@name»_state {
     1.7 +            «@name»_state_NONE = 0,
     1.8          `` for "func:distinctName(state)" |> «@name»`if "position()!=last()" > , `
     1.9          } «@name»_state;
    1.10  
    1.11          // events
    1.12  
    1.13          typedef enum _«@name»_event {
    1.14 +            «@name»_event_NONE = 0,
    1.15          `` for "func:distinctName(state/event)" |> «@name»`if "position()!=last()" > , `
    1.16          } «@name»_event;
    1.17  
    1.18          // actions
    1.19  
    1.20 -        `` for "func:distinctName(//action)" | PEP_STATUS «@name»(PEP_SESSION session, const Identity partner);
    1.21 +        `` const "name", "@name"
    1.22 +        `` for "func:distinctName(//action)" | PEP_STATUS «@name»(PEP_SESSION session, «$name»_state state, const Identity partner);
    1.23  
    1.24          // state machine
    1.25  
    1.26 @@ -56,18 +59,49 @@
    1.27                  PEP_SESSION session,
    1.28                  «@name»_state state,
    1.29                  «@name»_event event,
    1.30 -                const Identity partner
    1.31 +                const Identity partner,
    1.32 +                «@name»_state state_partner
    1.33              );
    1.34  
    1.35          // driver
    1.36  
    1.37 -        PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event);
    1.38 +        PEP_STATUS fsm_«@name»_inject(
    1.39 +                PEP_SESSION session,
    1.40 +                «@name»_event event,
    1.41 +                Identity partner,
    1.42 +                «@name»_state state_partner
    1.43 +            );
    1.44  
    1.45          #ifdef __cplusplus
    1.46          }
    1.47          #endif
    1.48  
    1.49          ||
    1.50 +        document "../src/sync_driver.c", "text"
    1.51 +        ||
    1.52 +        // Driver for «@name» state machine
    1.53 +
    1.54 +        #include <assert.h>
    1.55 +        #include "pEp_internal.h"
    1.56 +
    1.57 +
    1.58 +        PEP_STATUS fsm_«@name»_inject(
    1.59 +                PEP_SESSION session,
    1.60 +                «@name»_event event,
    1.61 +                Identity partner,
    1.62 +                «@name»_state state_partner
    1.63 +            )
    1.64 +        {
    1.65 +            PEP_STATUS status = PEP_STATUS_OK;
    1.66 +
    1.67 +            session->sync_state = InitState;
    1.68 +            session->sync_state = fsm_«@name»(session, session->sync_state,
    1.69 +                    event, partner, state_partner);
    1.70 +
    1.71 +            return status;
    1.72 +        }
    1.73 +
    1.74 +        ||
    1.75          ||
    1.76          #include "sync_fsm.h"
    1.77  
    1.78 @@ -77,7 +111,8 @@
    1.79                  PEP_SESSION session,
    1.80                  «@name»_state state,
    1.81                  «@name»_event event,
    1.82 -                const Identity partner
    1.83 +                const Identity partner,
    1.84 +                «@name»_state state_partner
    1.85              )
    1.86          {
    1.87              switch (state) {
    1.88 @@ -113,7 +148,7 @@
    1.89  
    1.90      template "action" {
    1.91          indent(0);
    1.92 -        > «@name»(session, 
    1.93 +        > «@name»(session, state, 
    1.94          choose {
    1.95              when "parm" > «name(parm/*)»
    1.96              otherwise > NULL