sync/gen_statemachine.ysl2
branchKeySyncWaitForAccept
changeset 1595 ddf2993d75fe
parent 1590 6e007351ccde
child 1597 cc039a6139cb
     1.1 --- a/sync/gen_statemachine.ysl2	Mon Feb 20 10:29:45 2017 +0100
     1.2 +++ b/sync/gen_statemachine.ysl2	Mon Feb 20 14:09:38 2017 +0100
     1.3 @@ -188,7 +188,7 @@
     1.4  
     1.5          // local definitions for «@name»'s state machine 
     1.6  
     1.7 -        `` apply "state", 2 mode="declStatePayload"
     1.8 +        `` apply "state", 0 mode="declStatePayload"
     1.9  
    1.10          // state machine for «@name»
    1.11  
    1.12 @@ -253,10 +253,31 @@
    1.13          ||
    1.14      }
    1.15  
    1.16 +    function "pEp_type" {
    1.17 +        param "type";
    1.18 +
    1.19 +        choose {
    1.20 +            when "$type = 'Identity'" > Identity
    1.21 +            when "$type = 'IdentityList'" > identity_list*
    1.22 +            otherwise value "$type";
    1.23 +        }
    1.24 +    }
    1.25 +
    1.26 +    function "pEp_type_op_radix" {
    1.27 +        param "type";
    1.28 +
    1.29 +        choose {
    1.30 +            when "$type = 'Identity'" > identity
    1.31 +            when "$type = 'IdentityList'" > identity_list
    1.32 +            otherwise call "pEp_type" with "type", "$type";
    1.33 +        }
    1.34 +    }
    1.35 +
    1.36      template "parm" mode="unpackStatePayloadParm" 
    1.37      {
    1.38          param "stateName";
    1.39 -        | «name(*[1])» «name(*[2])» = ((«$stateName»_state_payload_t*)session->sync_state_payload)->«name(*[2])»;
    1.40 +        const "pEpType" call "pEp_type" with "type","name(*[1])"; 
    1.41 +        | «$pEpType» «name(*[2])» = ((«$stateName»_state_payload_t*)session->sync_state_payload)->«name(*[2])»;
    1.42      }
    1.43  
    1.44      template "state" mode="declStatePayload" if "count(parm) > 0"
    1.45 @@ -267,18 +288,29 @@
    1.46  
    1.47      ||
    1.48  
    1.49 -    template "parm" mode="declStatePayloadParm" 
    1.50 -    | «name(*[1])» «name(*[2])»;
    1.51 +    template "parm" mode="declStatePayloadParm" {
    1.52 +        const "pEpType" call "pEp_type" with "type","name(*[1])"; 
    1.53 +        | «$pEpType» «name(*[2])»;
    1.54 +    }
    1.55  
    1.56 -    template "event"
    1.57 -    ||
    1.58 -    case «@name»:
    1.59 -    {
    1.60 -        DEBUG_LOG("FSM event", "«../../@filename»_fsm.c, state=«../@name»", "event=«@name»")
    1.61 -    `` apply "action|transition|condition";
    1.62 -    `` if "name(*[position()=last()]) != 'transition'" |> break;
    1.63 +    template "event" {
    1.64 +        ||
    1.65 +        case «@name»:
    1.66 +        {
    1.67 +            DEBUG_LOG("FSM event", "«../../@filename»_fsm.c, state=«../@name»", "event=«@name»")
    1.68 +        ||
    1.69 +        if "count(parm) > 1" {
    1.70 +            // TODO get ride of void *extra, pass per-event struct incl all params.
    1.71 +            const "extrapEpType" call "pEp_type" with "type","name(parm[2]/*[1])"; 
    1.72 +            const "extraArgName","name(parm[2]/*[2])"; 
    1.73 +            |> «$extrapEpType» «$extraArgName» = («$extrapEpType»)extra;
    1.74 +        }
    1.75 +        ||
    1.76 +        `` apply "action|transition|condition";
    1.77 +        `` if "name(*[position()=last()]) != 'transition'" |> break;
    1.78 +        }
    1.79 +        ||
    1.80      }
    1.81 -    ||
    1.82  
    1.83      template "action" {
    1.84          | DEBUG_LOG("FSM action", "«ancestor::fsm/@filename»_fsm.c, state=«ancestor::state/@name», event=«ancestor::event/@name»", "action=«@name»")
    1.85 @@ -289,7 +321,7 @@
    1.86              otherwise > NULL
    1.87          }
    1.88          choose {
    1.89 -            when "parm[2]" > , extra /*«name(parm[2]/*)»*/
    1.90 +            when "count(parm) > 1" > , «name(parm[2]/*)»
    1.91              otherwise > , NULL
    1.92          }
    1.93          > );\n
    1.94 @@ -359,15 +391,18 @@
    1.95      template "parm" mode="freeStatePayloadParm" 
    1.96      {
    1.97          param "stateName";
    1.98 -        | free_«yml:lcase(name(*[1]))»(((«$stateName»_state_payload_t*)session->sync_state_payload)->«name(*[2])»);
    1.99 +        const "pEpTypeOpRadix" call "pEp_type_op_radix" with "type","name(*[1])"; 
   1.100 +        | free_«$pEpTypeOpRadix»(((«$stateName»_state_payload_t*)session->sync_state_payload)->«name(*[2])»);
   1.101      }
   1.102  
   1.103      template "parm" mode="dupStatePayloadParm" 
   1.104      {
   1.105          param "stateName";
   1.106          param "transitionParms";
   1.107 +        const "pEpTypeOpRadix" call "pEp_type_op_radix" with "type","name(*[1])"; 
   1.108 +        const "pos", "position()";
   1.109          | ((«$stateName»_state_payload_t*)session->sync_state_payload)->«name(*[2])» =
   1.110 -        |     «yml:lcase(name(*[1]))»_dup(«name($transitionParms[position()]/*)»);
   1.111 +        |     «$pEpTypeOpRadix»_dup(«name($transitionParms[$pos]/*)»);
   1.112      }
   1.113  }
   1.114