sync/gen_statemachine.ysl2
author Volker Birk <vb@pep-project.org>
Thu, 05 May 2016 14:21:40 +0200
changeset 579 99a3e946928a
parent 578 b313077e13f2
child 580 99cd18ba8a1b
permissions -rw-r--r--
...
     1 // generate state machine code
     2 
     3 // Copyleft (c) 2016, p≡p foundation
     4 
     5 // Written by Volker Birk
     6 
     7 include yslt.yml2
     8 
     9 tstylesheet {
    10     template "/protocol/fsm"
    11     ||
    12     // state machine for «@name»
    13 
    14     #include "pEpEngine.h"
    15 
    16     typedef enum _fsm_error {
    17         invalid_state = -1,
    18         invalid_event = -2
    19     } fsm_error;
    20 
    21     typedef enum _«@name»_state {
    22     `` apply "state", mode=declare
    23     } «@name»_state;
    24 
    25     typedef enum _«@name»_event {
    26     `` apply "state/event", mode=declare
    27     } «@name»_event;
    28 
    29     «@name»_state fsm_«@name»(«@name»_state state, «@name»_event event)
    30     {
    31         switch (state) {
    32             `` apply "state", mode=implement
    33             default:
    34                 return invalid_state;
    35         }
    36     }
    37 
    38     ||
    39 
    40     template "state", mode=declare
    41         | «@name»`if "position()!=last()" > , `
    42 
    43     template "state", mode=implement
    44     ||
    45     case «@name»:
    46         switch (event) {
    47         `` apply "event", 2
    48         default:
    49             return invalid_event;
    50         }
    51         break;
    52 
    53     ||
    54 
    55     template "event", mode=declare
    56         | «@name»`if "position()!=last()" > , `
    57 
    58     template "event"
    59     ||
    60     case «@name»:
    61     `` apply "action|transition";
    62         break;
    63     ||
    64 
    65     template "action" | «@name»();
    66     template "transition" | return «@target»;
    67 }
    68