sync/gen_statemachine.ysl2
changeset 605 70e80b27b624
parent 589 bdff8843f086
child 608 3bf69b382303
     1.1 --- a/sync/gen_statemachine.ysl2	Thu May 12 00:23:23 2016 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Thu May 12 03:10:33 2016 +0200
     1.3 @@ -7,12 +7,18 @@
     1.4  include yslt.yml2
     1.5  
     1.6  tstylesheet {
     1.7 +
     1.8 +    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
     1.9 +    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
    1.10 +
    1.11      template "/protocol/fsm"
    1.12      ||
    1.13      // state machine for «@name»
    1.14  
    1.15      #include "pEpEngine.h"
    1.16  
    1.17 +    typedef union _param { const pEp_identity *partner; const stringlist_t *keylist; } param_t;
    1.18 +
    1.19      // error values
    1.20  
    1.21      typedef enum _fsm_error {
    1.22 @@ -36,6 +42,14 @@
    1.23  
    1.24      `` for "set:distinct(state/event//action/@name)" | void «.»(const pEp_identity *partner);
    1.25  
    1.26 +    // decoders
    1.27 +
    1.28 +    `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'decode'"
    1.29 +
    1.30 +    // encoders 
    1.31 +
    1.32 +    `` apply "$UniqueActions[starts-with(@name,'send')]",0 mode="proto" with "pfx", "'encode'"
    1.33 +
    1.34      // state machine
    1.35  
    1.36      «@name»_state fsm_«@name»(
    1.37 @@ -84,6 +98,23 @@
    1.38          > );\n
    1.39      }
    1.40  
    1.41 +    def "xsl:typeOfActionParam" {
    1.42 +        param "n", "name(.)";
    1.43 +        result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
    1.44 +    }
    1.45 +
    1.46 +    template "action", mode="proto" {
    1.47 +        param "pfx";
    1.48 +        > void «$pfx»«substring-after(@name, 'send')»(
    1.49 +        if "count(parm/*) = 0"
    1.50 +            > void
    1.51 +        for "set:distinct(parm/*)" {
    1.52 +            > «xsl:typeOfActionParam()» «name(.)»
    1.53 +            if "position() != last()" > ,
    1.54 +        }
    1.55 +        | );
    1.56 +    }
    1.57 +
    1.58      template "transition" | return «@target»;
    1.59  }
    1.60