sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Thu, 30 Aug 2018 08:17:34 +0200
branchsync
changeset 2914 f14346676e85
parent 2913 b2c2eed5be7a
child 2915 f53f154a4fc2
permissions -rw-r--r--
better this way
krista@2271
     1
// This file is under GNU General Public License 3.0
krista@2271
     2
// see LICENSE.txt
krista@2271
     3
vb@2829
     4
// generate conditions and actions
krista@2271
     5
vb@2906
     6
// Copyleft (c) 2017, 2018, p≡p foundation
krista@2271
     7
krista@2271
     8
// Written by Volker Birk
krista@2271
     9
krista@2271
    10
include yslt.yml2
krista@2271
    11
vb@2829
    12
decl _func *name (*type) alias - {
vb@2829
    13
    template %name=*name, %type=*type, "%type[@name='%name']"
vb@2829
    14
        call *type with "content" content;
vb@2829
    15
};
vb@2829
    16
vb@2829
    17
decl condition is _func (*type="condition");
vb@2829
    18
decl action is _func (*type="action");
vb@2829
    19
vb@2914
    20
decl timeout *name alias - {
vb@2914
    21
    template %name=*name, "fsm[@name='%name']", mode=handler
vb@2914
    22
        call "fsm" with "content" content;
vb@2914
    23
};
vb@2914
    24
krista@2271
    25
tstylesheet {
krista@2271
    26
    include standardlib.ysl2
krista@2271
    27
    include ./functions.ysl2
krista@2271
    28
vb@2844
    29
    include ./cond_act_*.yml2
vb@2829
    30
krista@2271
    31
    template "/protocol" {
vb@2829
    32
        document "generated/{@name}_actions.c", "text" {
vb@2829
    33
            ||
vb@2829
    34
            // This file is under GNU General Public License 3.0
vb@2829
    35
            // see LICENSE.txt
krista@2271
    36
vb@2830
    37
            #include "pEp_internal.h"
vb@2830
    38
            #include "map_asn1.h"
vb@2830
    39
vb@2829
    40
            #include "«@name»_impl.h"
vb@2829
    41
            `` for "fsm" | #include "«@name»_fsm.h"
krista@2271
    42
vb@2902
    43
            static bool _TID_greater(TID_t *t1, TID_t *t2)
vb@2902
    44
            {
vb@2903
    45
                assert(t1 && t2);
vb@2903
    46
                if (t1 && !t2)
vb@2903
    47
                    return true;
vb@2903
    48
                if (!t1)
vb@2903
    49
                    return false;
vb@2903
    50
vb@2902
    51
                if (t1->size > t2->size)
vb@2902
    52
                    return true;
vb@2902
    53
                if (t2->size > t1->size)
vb@2902
    54
                    return false;
vb@2902
    55
vb@2902
    56
                for (int i=0; i<t1->size; i++) {
vb@2902
    57
                    if (t1->buf[i] > t2->buf[i])
vb@2902
    58
                        return true;
vb@2904
    59
                    if (t2->buf[i] > t1->buf[i])
vb@2904
    60
                        return false;
vb@2902
    61
                }
vb@2902
    62
vb@2902
    63
                return false;
vb@2902
    64
            }
vb@2902
    65
krista@2271
    66
            ||
vb@2829
    67
            apply "func:distinctName(//condition)", 0;
vb@2913
    68
            apply "func:distinctName(//action)", 0;
vb@2914
    69
            apply "/protocol/fsm", 0, mode=handler;
krista@2271
    70
        }
krista@2271
    71
    }
krista@2271
    72
vb@2829
    73
    template "condition" | #error condition «@name» not implemented\n
vb@2829
    74
    template "action" | #error action «@name» not implemented\n
vb@2829
    75
vb@2829
    76
    function "condition" {
vb@2829
    77
        param "content";
vb@2829
    78
        ||
vb@2829
    79
        PEP_STATUS «@name»(PEP_SESSION session, bool *result)
vb@2829
    80
        {
vb@2829
    81
            assert(session && result);
vb@2829
    82
            if (!(session && result))
vb@2829
    83
                return PEP_ILLEGAL_VALUE;
krista@2271
    84
krista@2271
    85
        ||
vb@2829
    86
        copy "$content";
vb@2829
    87
        ||
krista@2271
    88
vb@2829
    89
            return PEP_STATUS_OK;
krista@2271
    90
        }
krista@2271
    91
krista@2271
    92
        ||
krista@2271
    93
    }
krista@2271
    94
vb@2829
    95
    function "action" {
vb@2829
    96
        param "content";
vb@2829
    97
        ||
vb@2829
    98
        PEP_STATUS «@name»(PEP_SESSION session)
vb@2829
    99
        {
vb@2829
   100
            assert(session);
vb@2829
   101
            if (!session)
vb@2829
   102
                return PEP_ILLEGAL_VALUE;
krista@2271
   103
krista@2271
   104
        ||
vb@2829
   105
        copy "$content";
krista@2271
   106
        ||
krista@2271
   107
krista@2271
   108
            return PEP_STATUS_OK;
krista@2271
   109
        }
krista@2271
   110
krista@2271
   111
        ||
krista@2271
   112
    }
vb@2914
   113
vb@2914
   114
    function "fsm" {
vb@2914
   115
        param "content";
vb@2914
   116
        ||
vb@2914
   117
        PEP_STATUS «@name»TimeoutHandler(PEP_SESSION session)
vb@2914
   118
        {
vb@2914
   119
            assert(session);
vb@2914
   120
            if (!session)
vb@2914
   121
                return PEP_ILLEGAL_VALUE;
vb@2914
   122
vb@2914
   123
        ||
vb@2914
   124
        copy "$content";
vb@2914
   125
        ||
vb@2914
   126
vb@2914
   127
            return PEP_STATUS_OK;
vb@2914
   128
        }
vb@2914
   129
vb@2914
   130
        ||
vb@2914
   131
    }
krista@2271
   132
}
krista@2271
   133