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