sync/gen_codec.ysl2
changeset 613 d59da438b2cb
child 615 52c1a857e73e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sync/gen_codec.ysl2	Thu May 12 18:26:19 2016 +0200
     1.3 @@ -0,0 +1,68 @@
     1.4 +// generate encoder and decoders for protocol messages
     1.5 +
     1.6 +// Copyleft (c) 2016, p≡p foundation
     1.7 +
     1.8 +include yslt.yml2
     1.9 +
    1.10 +tstylesheet {
    1.11 +
    1.12 +    key "ActionByNames", "/protocol/fsm/state/event//action", "@name";
    1.13 +    variable "UniqueActions", "/protocol/fsm/state/event//action[generate-id()=generate-id(key('ActionByNames',@name)[1])]";
    1.14 +    variable "UniqueSendActions", "$UniqueActions[starts-with(@name,'send')]";
    1.15 +
    1.16 +    template "/protocol"
    1.17 +    ||
    1.18 +    // encoders and decoders state for «@name» protocol
    1.19 +
    1.20 +    #include "pEpEngine.h"
    1.21 +
    1.22 +    // decoders
    1.23 +
    1.24 +    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'decode'"
    1.25 +
    1.26 +    // encoders 
    1.27 +
    1.28 +    `` apply "$UniqueSendActions",0 mode="proto" with "pfx", "'encode'"
    1.29 +
    1.30 +    ||
    1.31 +
    1.32 +    def "xsl:typeOfActionParam" {
    1.33 +        param "n", "name(.)";
    1.34 +        result "name(ancestor::event/child::parm[child::*[position()=2 and name(.)=$n]]/child::*[position()=1])";
    1.35 +    }
    1.36 +    
    1.37 +    function "interfaces_params" {
    1.38 +        param "ifaceName";
    1.39 +        // variable "ifaceCommons", "/protocol/interface[@name = 'commons']/*";
    1.40 +        variable "ifaceParams", "$UniqueActions[@name = concat('send',$ifaceName)]/parm/*";
    1.41 +        variable "ifaceAdditions", "/protocol/interface[@name = $ifaceName]/*";
    1.42 +
    1.43 +        // if "count($ifaceCommons) != 0" > , 
    1.44 +        // for "$ifaceCommons" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    1.45 +
    1.46 +        if "count($ifaceParams) != 0" > , 
    1.47 +        for "set:distinct($ifaceParams)" {
    1.48 +            > «xsl:typeOfActionParam()» «name(.)»
    1.49 +            if "position() != last()" > ,
    1.50 +        }
    1.51 +
    1.52 +        if "count($ifaceAdditions) != 0" > , 
    1.53 +        for "$ifaceAdditions" > «name(.)» *«name(./*)»`if "position() != last()" > ,`
    1.54 +    }
    1.55 +
    1.56 +    template "action", mode="func_header" {
    1.57 +        param "pfx";
    1.58 +        variable "ifaceName", "substring-after(@name, 'send')";
    1.59 +
    1.60 +        > void «$pfx»«$ifaceName»(const char **bufp, size_t *sizep
    1.61 +        call("interfaces_params") with "ifaceName", "$ifaceName";
    1.62 +        > )
    1.63 +    }
    1.64 +
    1.65 +    template "action", mode="proto" {
    1.66 +        param "pfx";
    1.67 +        apply ".",0 mode="func_header" with "pfx", "$pfx" ;
    1.68 +        | ;
    1.69 +    }
    1.70 +}
    1.71 +