sync/gen_actions.ysl2
author Volker Birk <vb@pep.foundation>
Thu, 30 Aug 2018 04:33:59 +0200
branchsync
changeset 2913 b2c2eed5be7a
parent 2906 2d5db5aa47d6
child 2914 f14346676e85
permissions -rw-r--r--
notify the app
     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 tstylesheet {
    21     include standardlib.ysl2
    22     include ./functions.ysl2
    23 
    24     include ./cond_act_*.yml2
    25 
    26     template "/protocol" {
    27         document "generated/{@name}_actions.c", "text" {
    28             ||
    29             // This file is under GNU General Public License 3.0
    30             // see LICENSE.txt
    31 
    32             #include "pEp_internal.h"
    33             #include "map_asn1.h"
    34 
    35             #include "«@name»_impl.h"
    36             `` for "fsm" | #include "«@name»_fsm.h"
    37 
    38             static bool _TID_greater(TID_t *t1, TID_t *t2)
    39             {
    40                 assert(t1 && t2);
    41                 if (t1 && !t2)
    42                     return true;
    43                 if (!t1)
    44                     return false;
    45 
    46                 if (t1->size > t2->size)
    47                     return true;
    48                 if (t2->size > t1->size)
    49                     return false;
    50 
    51                 for (int i=0; i<t1->size; i++) {
    52                     if (t1->buf[i] > t2->buf[i])
    53                         return true;
    54                     if (t2->buf[i] > t1->buf[i])
    55                         return false;
    56                 }
    57 
    58                 return false;
    59             }
    60 
    61             ||
    62             apply "func:distinctName(//condition)", 0;
    63             apply "func:distinctName(//action)", 0;
    64             callTimeoutHandler KeySync;
    65         }
    66     }
    67 
    68     template "condition" | #error condition «@name» not implemented\n
    69     template "action" | #error action «@name» not implemented\n
    70 
    71     function "condition" {
    72         param "content";
    73         ||
    74         PEP_STATUS «@name»(PEP_SESSION session, bool *result)
    75         {
    76             assert(session && result);
    77             if (!(session && result))
    78                 return PEP_ILLEGAL_VALUE;
    79 
    80         ||
    81         copy "$content";
    82         ||
    83 
    84             return PEP_STATUS_OK;
    85         }
    86 
    87         ||
    88     }
    89 
    90     function "action" {
    91         param "content";
    92         ||
    93         PEP_STATUS «@name»(PEP_SESSION session)
    94         {
    95             assert(session);
    96             if (!session)
    97                 return PEP_ILLEGAL_VALUE;
    98 
    99         ||
   100         copy "$content";
   101         ||
   102 
   103             return PEP_STATUS_OK;
   104         }
   105 
   106         ||
   107     }
   108 }
   109