sync/gen_codec.ysl2
author Edouard Tisserant
Thu, 12 May 2016 18:26:19 +0200
changeset 613 d59da438b2cb
child 615 52c1a857e73e
permissions -rw-r--r--
Added sync some protocol payload definitions
     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     `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'decode'"
    22 
    23     // encoders 
    24 
    25     `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'encode'"
    26 
    27     ||
    28 
    29     def "xsl:typeOfActionParam" {
    30         param "n", "name(.)";
    31         result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
    32     }
    33     
    34     function "interfaces_params" {
    35         param "ifaceName";
    36         // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
    37         variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
    38         variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
    39 
    40         // if "count($ifaceCommons) != 0" > , 
    41         // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    42 
    43         if "count($ifaceParams) != 0" > , 
    44         for "set:distinct($ifaceParams)" {
    45             > «xsl:typeOfActionParam()» «name(.)»
    46             if "position() != last()" > ,
    47         }
    48 
    49         if "count($ifaceAdditions) != 0" > , 
    50         for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    51     }
    52 
    53     template "action", mode="func_header" {
    54         param "pfx";
    55         variable "ifaceName", "substring-after(@name, 'send')";
    56 
    57         > void «$pfx»«$ifaceName»(const char **bufp, size_t *sizep
    58         call("interfaces_params") with "ifaceName", "$ifaceName";
    59         > )
    60     }
    61 
    62     template "action", mode="proto" {
    63         param "pfx";
    64         apply ".",0 mode="func_header" with "pfx", "$pfx" ;
    65         | ;
    66     }
    67 }
    68