sync/gen_codec.ysl2
author Edouard Tisserant
Thu, 12 May 2016 19:18:14 +0200
changeset 615 52c1a857e73e
parent 613 d59da438b2cb
child 618 32fe7c8bee51
permissions -rw-r--r--
More teaks in sync proto codec gen
     1 // generate encoder and decoders for protocol messages
     2 
     3 // Copyleft (c) 2016, p≡p foundation
     4 
     5 include yslt.yml2
     6 
     7 tstylesheet {
     8 
     9     key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
    10     variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
    11     variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
    12 
    13     template "/protocol" {
    14         ||
    15         // encoders and decoders state for «@name» protocol
    16 
    17         #include "pEpEngine.h"
    18 
    19         // decoders
    20 
    21         ||
    22         apply "$UniqueSendActions",0 mode="proto" {
    23             with "pfx", "'read'";
    24             with "baseParms" > const char *buf, size_t size
    25         }
    26         ||
    27 
    28         // encoders 
    29 
    30         ||
    31         apply "$UniqueSendActions",0 mode="proto" {
    32             with "pfx", "'create'";
    33             with "baseParms" > const char **bufp, size_t *sizep
    34         }
    35     }
    36 
    37     def "xsl:typeOfActionParam" {
    38         param "n", "name(.)";
    39         result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
    40     }
    41     
    42     function "interfaces_params" {
    43         param "ifaceName";
    44         // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
    45         variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
    46         variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
    47 
    48         // if "count($ifaceCommons) != 0" > , 
    49         // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    50 
    51         if "count($ifaceParams) != 0" > , 
    52         for "set:distinct($ifaceParams)" {
    53             > «xsl:typeOfActionParam()» «name(.)»
    54             if "position() != last()" > ,
    55         }
    56 
    57         if "count($ifaceAdditions) != 0" > , 
    58         for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    59     }
    60 
    61     template "action", mode="func_header" {
    62         param "pfx";
    63         param "baseParms";
    64         variable "ifaceName", "substring-after(@name, 'send')";
    65 
    66         > void «$pfx»«$ifaceName»(«$baseParms»
    67         call("interfaces_params") with "ifaceName", "$ifaceName";
    68         > )
    69     }
    70 
    71     template "action", mode="proto" {
    72         param "pfx";
    73         param "baseParms";
    74         apply ".",0 mode="func_header" {
    75             with "pfx", "$pfx" ;
    76             with "baseParms", "$baseParms" ;
    77         }
    78         | ;
    79     }
    80 }
    81