sync/gen_statemachine.ysl2
branchkeysync
changeset 964 ef02296c41ca
parent 959 c1c463ecf30c
child 985 087d5d60c082
     1.1 --- a/sync/gen_statemachine.ysl2	Mon Aug 01 12:32:04 2016 +0200
     1.2 +++ b/sync/gen_statemachine.ysl2	Tue Aug 02 12:06:45 2016 +0200
     1.3 @@ -45,10 +45,15 @@
     1.4          // error values
     1.5  
     1.6          typedef enum _fsm_error {
     1.7 +            // these error values are corresponding to
     1.8 +            // PEP_SYNC_STATEMACHINE_ERROR - value
     1.9              invalid_state = -2,
    1.10              invalid_event = -3,
    1.11              invalid_condition = -4,
    1.12 -            invalid_action = -5
    1.13 +            invalid_action = -5,
    1.14 +
    1.15 +            // out of memory condition
    1.16 +            invalid_out_of_memory = -128
    1.17          } fsm_error;
    1.18  
    1.19          // conditions
    1.20 @@ -129,9 +134,14 @@
    1.21              if (!session)
    1.22                  return PEP_ILLEGAL_VALUE;
    1.23  
    1.24 -            session->«@filename»_state = fsm_«@name»(session, session->«@filename»_state,
    1.25 -                    event, partner, extra);
    1.26 +            «@name»_state state = fsm_«@name»(session,
    1.27 +                    session->«@filename»_state, event, partner, extra);
    1.28 +            if (state == invalid_out_of_memory)
    1.29 +                return PEP_OUT_OF_MEMORY;
    1.30 +            if (state < 0)
    1.31 +                return PEP_SYNC_STATEMACHINE_ERROR - state;
    1.32  
    1.33 +            session->«@filename»_state = state;
    1.34              return PEP_STATUS_OK;
    1.35          }
    1.36  
    1.37 @@ -150,7 +160,7 @@
    1.38                  void *extra
    1.39              )
    1.40          {
    1.41 -            int cond_result = -1;
    1.42 +            int cond_result;
    1.43              PEP_STATUS status = PEP_STATUS_OK;
    1.44  
    1.45              switch (state) {
    1.46 @@ -192,15 +202,16 @@
    1.47              otherwise > NULL
    1.48          }
    1.49          > , NULL);\n
    1.50 +        | if (status == PEP_OUT_OF_MEMORY)
    1.51 +        |> return invalid_out_of_memory;
    1.52          | if (status != PEP_STATUS_OK)
    1.53          |> return invalid_action;
    1.54      }
    1.55  
    1.56      template "condition" {
    1.57          | cond_result = «@name»(session`apply "parm", 0`);
    1.58 -        | assert(cond_result == 0 || cond_result == 1);
    1.59 -        | if (cond_result == -1)
    1.60 -        |> return invalid_condition;
    1.61 +        | if (cond_result < 0)
    1.62 +        |> return cond_result;
    1.63          | if (cond_result) {
    1.64          apply "action|transition|condition";
    1.65          | }