cleaning up FSM generation code
authorVolker Birk <vb@pep-project.org>
Sat, 09 Jul 2016 11:34:22 +0200
changeset 807a33a5f760372
parent 806 3c66f5d8cfb3
child 808 e5f072423edc
cleaning up FSM generation code
src/sync_actions.c
src/sync_fsm.c
sync/Makefile
sync/gen_actions_skeleton.ysl2
sync/gen_statemachine.ysl2
sync/sync.fsm
     1.1 --- a/src/sync_actions.c	Fri Jul 08 21:34:32 2016 +0200
     1.2 +++ b/src/sync_actions.c	Sat Jul 09 11:34:22 2016 +0200
     1.3 @@ -108,7 +108,7 @@
     1.4  //  params:
     1.5  //      session (in)        session handle
     1.6  //      state (in)          state the state machine is in
     1.7 -//      partner (in)        partner in sync
     1.8 +//      partner (in)        partner to communicate with
     1.9  //
    1.10  //  returns:
    1.11  //      PEP_STATUS_OK or any other value on error
    1.12 @@ -202,7 +202,7 @@
    1.13  //  params:
    1.14  //      session (in)        session handle
    1.15  //      state (in)          state the state machine is in
    1.16 -//      partner (in)        partner in sync
    1.17 +//      partner (in)        partner to communicate with
    1.18  //
    1.19  //  returns:
    1.20  //      PEP_STATUS_OK or any other value on error
    1.21 @@ -238,7 +238,7 @@
    1.22  //  params:
    1.23  //      session (in)        session handle
    1.24  //      state (in)          state the state machine is in
    1.25 -//      partner (in)        partner in sync
    1.26 +//      partner (in)        partner to communicate with
    1.27  //
    1.28  //  returns:
    1.29  //      PEP_STATUS_OK or any other value on error
    1.30 @@ -274,7 +274,7 @@
    1.31  //  params:
    1.32  //      session (in)        session handle
    1.33  //      state (in)          state the state machine is in
    1.34 -//      partner (in)        partner in sync
    1.35 +//      partner (in)        partner to communicate with
    1.36  //
    1.37  //  returns:
    1.38  //      PEP_STATUS_OK or any other value on error
    1.39 @@ -395,3 +395,4 @@
    1.40      return status;
    1.41  }
    1.42  
    1.43 +
     2.1 --- a/src/sync_fsm.c	Fri Jul 08 21:34:32 2016 +0200
     2.2 +++ b/src/sync_fsm.c	Sat Jul 09 11:34:22 2016 +0200
     2.3 @@ -98,3 +98,4 @@
     2.4  
     2.5      return state;
     2.6  }
     2.7 +
     3.1 --- a/sync/Makefile	Fri Jul 08 21:34:32 2016 +0200
     3.2 +++ b/sync/Makefile	Sat Jul 09 11:34:22 2016 +0200
     3.3 @@ -1,16 +1,16 @@
     3.4  include ../Makefile.conf
     3.5  
     3.6 -all: ../src/sync_fsm.c
     3.7 +all: .statemachines
     3.8  
     3.9 -skeleton: ../src/sync_actions.c.skeleton
    3.10 +skeleton: .skeletons
    3.11  
    3.12 -../src/sync_actions.c.skeleton: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    3.13 +.skeletons: sync.fsm gen_actions_skeleton.ysl2 fsm.yml2 functions.ysl2
    3.14  	$(YML2PROC) -y gen_actions_skeleton.ysl2 $< -o $@
    3.15  
    3.16 -../src/sync_fsm.c: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    3.17 +.statemachines: sync.fsm gen_statemachine.ysl2 fsm.yml2 functions.ysl2
    3.18  	$(YML2PROC) -y gen_statemachine.ysl2 $< -o $@
    3.19  
    3.20  .PHONY: clean
    3.21  
    3.22  clean:
    3.23 -	rm -f *.xml *.xsl ../src/sync_fsm.* ../src/*.skeleton
    3.24 +	rm -f *.xml *.xsl ../src/sync_fsm.* ../src/*.skeleton .statemachines .skeletons
     4.1 --- a/sync/gen_actions_skeleton.ysl2	Fri Jul 08 21:34:32 2016 +0200
     4.2 +++ b/sync/gen_actions_skeleton.ysl2	Sat Jul 09 11:34:22 2016 +0200
     4.3 @@ -9,21 +9,22 @@
     4.4  tstylesheet {
     4.5      include ./functions.ysl2
     4.6  
     4.7 -    template "/protocol/fsm" {
     4.8 +    template "/protocol/fsm" document "../src/{@filename}_actions.c.skeleton", "text" {
     4.9 +        const "name", "@name";
    4.10 +        const "filename", "@filename";
    4.11      ||
    4.12 -    `` const "name", "@name"
    4.13      // Actions for «@name» state machine
    4.14  
    4.15      #include <assert.h>
    4.16      #include "pEp_internal.h"
    4.17      #include "keymanagement.h"
    4.18      #include "message.h"
    4.19 -    #include "sync_fsm.h"
    4.20 +    #include "«@filename»_fsm.h"
    4.21      #include "baseprotocol.h"
    4.22      #include "map_asn1.h"
    4.23      `` for "func:distinctName(//action)" if "substring(@name, 1, 4) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
    4.24  
    4.25 -    `` for "func:distinctName(//action)" call "action" with "action", ".", with "fsm", "$name";
    4.26 +    `` for "func:distinctName(//action)" call "action" with "action", ".", with "fsm", "$name", with "filename", "$filename";
    4.27  
    4.28      ||
    4.29      }
    4.30 @@ -31,13 +32,14 @@
    4.31      function "action" {
    4.32          param "action";
    4.33          param "fsm";
    4.34 +        param "filename", "'###'";
    4.35          choose {
    4.36              when "substring($action/@name, 1, 4) = 'send'"
    4.37                  call "send_action" with "action", "$action",
    4.38 -                     with "fsm", "$fsm";
    4.39 +                     with "fsm", "$fsm", with "filename", "$filename";
    4.40              otherwise
    4.41                  call "other_action" with "action", "$action",
    4.42 -                     with "fsm", "$fsm";
    4.43 +                     with "fsm", "$fsm", with "filename", "$filename";
    4.44          }
    4.45      }
    4.46  
    4.47 @@ -63,6 +65,7 @@
    4.48      function "other_action" {
    4.49          param "action";
    4.50          param "fsm";
    4.51 +        param "filename", "'###'";
    4.52  
    4.53          ||
    4.54  
    4.55 @@ -71,7 +74,7 @@
    4.56          //  params:
    4.57          //      session (in)        session handle
    4.58          //      state (in)          state the state machine is in
    4.59 -        `` if "parm"        | //      partner (in)        partner in sync
    4.60 +        `` if "parm"        | //      partner (in)        partner to communicate with
    4.61          `` if "not(parm)"   | //      partner (in)        (must be NULL)
    4.62          //
    4.63          //  returns:
    4.64 @@ -105,6 +108,7 @@
    4.65      function "send_action" {
    4.66          param "action";
    4.67          param "fsm";
    4.68 +        param "filename", "'###'";
    4.69          const "name", "substring($action/@name, 5, 255)";
    4.70  
    4.71          ||
    4.72 @@ -114,7 +118,7 @@
    4.73          //  params:
    4.74          //      session (in)        session handle
    4.75          //      state (in)          state the state machine is in
    4.76 -        `` if "parm"        | //      partner (in)        partner in sync
    4.77 +        `` if "parm"        | //      partner (in)        partner to communicate with
    4.78          `` if "not(parm)"   | //      partner (in)        (must be NULL)
    4.79          //
    4.80          //  returns:
    4.81 @@ -189,7 +193,7 @@
    4.82              free_identity(me);
    4.83              me = NULL;
    4.84  
    4.85 -            status = session->messageToSend(session->sync_obj, _message);
    4.86 +            status = session->messageToSend(session->«$filename»_obj, _message);
    4.87  
    4.88              free_message(_message);
    4.89              ASN_STRUCT_FREE(asn_DEF_«$name», msg);
     5.1 --- a/sync/gen_statemachine.ysl2	Fri Jul 08 21:34:32 2016 +0200
     5.2 +++ b/sync/gen_statemachine.ysl2	Sat Jul 09 11:34:22 2016 +0200
     5.3 @@ -10,7 +10,7 @@
     5.4      include ./functions.ysl2
     5.5  
     5.6      template "/protocol/fsm" {
     5.7 -        document "../src/sync_fsm.h", "text" {
     5.8 +        document "../src/{@filename}_fsm.h", "text" {
     5.9          ||
    5.10          #pragma once
    5.11  
    5.12 @@ -85,7 +85,7 @@
    5.13  
    5.14          ||
    5.15          }
    5.16 -        document "../src/sync_driver.c", "text"
    5.17 +        document "../src/{@filename}_driver.c", "text"
    5.18          ||
    5.19          // Driver for «@name» state machine
    5.20  
    5.21 @@ -102,15 +102,16 @@
    5.22          {
    5.23              PEP_STATUS status = PEP_STATUS_OK;
    5.24  
    5.25 -            session->sync_state = fsm_«@name»(session, session->sync_state,
    5.26 +            session->«@filename»_state = fsm_«@name»(session, session->«@filename»_state,
    5.27                      event, partner, state_partner);
    5.28  
    5.29              return status;
    5.30          }
    5.31  
    5.32          ||
    5.33 +        document "../src/{@filename}_fsm.c", "text"
    5.34          ||
    5.35 -        #include "sync_fsm.h"
    5.36 +        #include "«@filename»_fsm.h"
    5.37  
    5.38          // state machine for «@name»
    5.39  
     6.1 --- a/sync/sync.fsm	Fri Jul 08 21:34:32 2016 +0200
     6.2 +++ b/sync/sync.fsm	Sat Jul 09 11:34:22 2016 +0200
     6.3 @@ -9,7 +9,7 @@
     6.4  protocol DeviceGroup {
     6.5      // all messages have a timestamp, time out and are removed after timeout
     6.6  
     6.7 -    fsm DeviceState {
     6.8 +    fsm DeviceState filename=sync {
     6.9          state InitState {
    6.10              on Init {
    6.11                  if (storedGroupKeys)