sync/gen_actions_skeleton.ysl2
author Volker Birk <vb@pep-project.org>
Wed, 18 May 2016 00:05:39 +0200
changeset 650 accc0ad7d32c
parent 627 ef1fdfde8ced
child 651 3543ea5e8b02
permissions -rw-r--r--
...
vb@623
     1
// generate actions skeleton
vb@623
     2
vb@623
     3
// Copyleft (c) 2016, p≡p foundation
vb@623
     4
vb@623
     5
// Written by Volker Birk
vb@623
     6
vb@623
     7
include yslt.yml2
vb@623
     8
vb@623
     9
tstylesheet {
vb@623
    10
    include ./functions.ysl2
vb@623
    11
vb@623
    12
    template "/protocol/fsm" {
vb@625
    13
    document "../src/sync_driver.c", "text"
vb@623
    14
    ||
vb@623
    15
    // Driver for «@name» state machine
vb@623
    16
vb@623
    17
    #include <assert.h>
vb@623
    18
    #include "sync_fsm.h"
vb@623
    19
vb@623
    20
vb@623
    21
    PEP_STATUS fsm_«@name»_inject(PEP_SESSION session, «@name»_event event)
vb@623
    22
    {
vb@623
    23
        PEP_STATUS status = PEP_STATUS_OK;
vb@623
    24
vb@626
    25
        static «@name»_state state = InitState;
vb@626
    26
        static Identity partner = NULL;
vb@624
    27
vb@627
    28
        state = fsm_«@name»(session, state, event, partner);
vb@623
    29
        return status;
vb@623
    30
    }
vb@626
    31
vb@623
    32
    ||
vb@623
    33
    ||
vb@623
    34
    // Actions for «@name» state machine
vb@623
    35
vb@623
    36
    #include <assert.h>
vb@623
    37
    #include "sync_fsm.h"
vb@650
    38
    #include "map_asn1.h"
vb@650
    39
    `` for "func:distinctName(//action)" if "substring(@name, 0, 5) = 'send'" | #include "../asn.1/«substring(@name, 5, 255)».h"
vb@623
    40
vb@623
    41
    `` for "func:distinctName(//action)" call "action" with "action", ".";
vb@623
    42
vb@623
    43
    ||
vb@623
    44
    }
vb@623
    45
vb@623
    46
    function "action" {
vb@623
    47
        param "action";
vb@650
    48
        choose {
vb@650
    49
            when "substring($action/@name, 0, 5) = 'send'"
vb@650
    50
                call "send_action" with "action", "$action";
vb@650
    51
            otherwise
vb@650
    52
                call "other_action" with "action", "$action";
vb@650
    53
        }
vb@650
    54
    }
vb@650
    55
vb@650
    56
    function "other_action" {
vb@650
    57
        param "action";
vb@623
    58
vb@623
    59
        ||
vb@650
    60
vb@650
    61
        // «$action/@name»() - send
vb@623
    62
        //
vb@623
    63
        //  params:
vb@627
    64
        //      session (in)        session handle
vb@623
    65
        `` if "parm"        | //      partner (in)        partner in sync
vb@623
    66
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@623
    67
        //
vb@623
    68
        //  returns:
vb@623
    69
        //      PEP_STATUS_OK or any other value on error
vb@623
    70
vb@627
    71
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@623
    72
        {
vb@623
    73
            PEP_STATUS status = PEP_STATUS_OK;
vb@623
    74
vb@650
    75
            assert(session);
vb@623
    76
        `` if "parm"        |> assert(partner);
vb@650
    77
        `` if "parm"        |> if (!(session && partner))
vb@623
    78
        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
vb@650
    79
        `` if "not(parm)"   |> assert(!partner);
vb@650
    80
        `` if "not(parm)"   |> if (!(session && !partner))
vb@623
    81
        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
vb@623
    82
vb@623
    83
            // working code
vb@623
    84
vb@623
    85
vb@623
    86
            return status;
vb@650
    87
vb@650
    88
        enomem:
vb@650
    89
            status = PEP_OUT_OF_MEMORY;
vb@650
    90
        error:
vb@650
    91
            // free...
vb@650
    92
            return status;
vb@650
    93
        }
vb@650
    94
vb@650
    95
        ||
vb@650
    96
    }
vb@650
    97
vb@650
    98
    function "send_action" {
vb@650
    99
        param "action";
vb@650
   100
        const "name", "substring($action/@name, 5, 255)";
vb@650
   101
vb@650
   102
        ||
vb@650
   103
vb@650
   104
        // «$action/@name»() - send «$name» message
vb@650
   105
        //
vb@650
   106
        //  params:
vb@650
   107
        //      session (in)        session handle
vb@650
   108
        `` if "parm"        | //      partner (in)        partner in sync
vb@650
   109
        `` if "not(parm)"   | //      partner (in)        (must be NULL)
vb@650
   110
        //
vb@650
   111
        //  returns:
vb@650
   112
        //      PEP_STATUS_OK or any other value on error
vb@650
   113
vb@650
   114
        PEP_STATUS «$action/@name»(PEP_SESSION session, const Identity partner)
vb@650
   115
        {
vb@650
   116
            PEP_STATUS status = PEP_STATUS_OK;
vb@650
   117
vb@650
   118
            assert(session);
vb@650
   119
        `` if "parm"        |> assert(partner);
vb@650
   120
        `` if "parm"        |> if (!(session && partner))
vb@650
   121
        `` if "parm"        |>> return PEP_ILLEGAL_VALUE;
vb@650
   122
        `` if "not(parm)"   |> assert(!partner);
vb@650
   123
        `` if "not(parm)"   |> if (!(session && !partner))
vb@650
   124
        `` if "not(parm)"   |>> return PEP_ILLEGAL_VALUE;
vb@650
   125
vb@650
   126
            «$name»_t *msg = («$name»_t *) calloc(1, sizeof(«$name»_t));
vb@650
   127
            assert(msg);
vb@650
   128
            if (!msg)
vb@650
   129
                goto enomem;
vb@650
   130
vb@650
   131
            
vb@650
   132
            return status;
vb@650
   133
vb@650
   134
        enomem:
vb@650
   135
            status = PEP_OUT_OF_MEMORY;
vb@650
   136
        error:
vb@650
   137
            ASN_STRUCT_FREE(asn_DEF_«$name», msg);
vb@650
   138
            return status;
vb@623
   139
        }
vb@623
   140
vb@623
   141
        ||
vb@623
   142
    }
vb@623
   143
}
vb@623
   144