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
Edouard@613
     1
// generate encoder and decoders for protocol messages
Edouard@613
     2
Edouard@613
     3
// Copyleft (c) 2016, p≡p foundation
Edouard@613
     4
Edouard@613
     5
include yslt.yml2
Edouard@613
     6
Edouard@613
     7
tstylesheet {
Edouard@613
     8
Edouard@613
     9
    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
Edouard@613
    10
    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
Edouard@613
    11
    variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
Edouard@613
    12
Edouard@613
    13
    template "/protocol"
Edouard@613
    14
    ||
Edouard@613
    15
    // encoders and decoders state for «@name» protocol
Edouard@613
    16
Edouard@613
    17
    #include "pEpEngine.h"
Edouard@613
    18
Edouard@613
    19
    // decoders
Edouard@613
    20
Edouard@613
    21
    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'decode'"
Edouard@613
    22
Edouard@613
    23
    // encoders 
Edouard@613
    24
Edouard@613
    25
    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'encode'"
Edouard@613
    26
Edouard@613
    27
    ||
Edouard@613
    28
Edouard@613
    29
    def "xsl:typeOfActionParam" {
Edouard@613
    30
        param "n", "name(.)";
Edouard@613
    31
        result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
Edouard@613
    32
    }
Edouard@613
    33
    
Edouard@613
    34
    function "interfaces_params" {
Edouard@613
    35
        param "ifaceName";
Edouard@613
    36
        // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
Edouard@613
    37
        variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
Edouard@613
    38
        variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
Edouard@613
    39
Edouard@613
    40
        // if "count($ifaceCommons) != 0" > , 
Edouard@613
    41
        // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
Edouard@613
    42
Edouard@613
    43
        if "count($ifaceParams) != 0" > , 
Edouard@613
    44
        for "set:distinct($ifaceParams)" {
Edouard@613
    45
            > «xsl:typeOfActionParam()» «name(.)»
Edouard@613
    46
            if "position() != last()" > ,
Edouard@613
    47
        }
Edouard@613
    48
Edouard@613
    49
        if "count($ifaceAdditions) != 0" > , 
Edouard@613
    50
        for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
Edouard@613
    51
    }
Edouard@613
    52
Edouard@613
    53
    template "action", mode="func_header" {
Edouard@613
    54
        param "pfx";
Edouard@613
    55
        variable "ifaceName", "substring-after(@name, 'send')";
Edouard@613
    56
Edouard@613
    57
        > void «$pfx»«$ifaceName»(const char **bufp, size_t *sizep
Edouard@613
    58
        call("interfaces_params") with "ifaceName", "$ifaceName";
Edouard@613
    59
        > )
Edouard@613
    60
    }
Edouard@613
    61
Edouard@613
    62
    template "action", mode="proto" {
Edouard@613
    63
        param "pfx";
Edouard@613
    64
        apply ".",0 mode="func_header" with "pfx", "$pfx" ;
Edouard@613
    65
        | ;
Edouard@613
    66
    }
Edouard@613
    67
}
Edouard@613
    68