From 9edcbafa2821f058b892a6121b92dbef4998b0ac Mon Sep 17 00:00:00 2001 From: Gunnar Andersson Date: Wed, 23 Aug 2023 12:16:05 +0200 Subject: [PATCH] protobuf: WIP update to use interface node Signed-off-by: Gunnar Andersson --- ifex/templates/protobuf/AST_protobuf.tpl | 134 ++++++++++++----------- 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/ifex/templates/protobuf/AST_protobuf.tpl b/ifex/templates/protobuf/AST_protobuf.tpl index de5e4bf..ab5baff 100755 --- a/ifex/templates/protobuf/AST_protobuf.tpl +++ b/ifex/templates/protobuf/AST_protobuf.tpl @@ -59,73 +59,79 @@ message {{x.name}} { } {% endfor %} - {% for x in n.methods %} -// IFEX Method {{x.name}} -message {{ x.name }}_request { - {% for x in x.input %} - {% if x.datatype in typedefs %} - {% set type = typedefs[x.datatype] %} - {% else %} - {% set type = x.datatype %} - {% endif %} - {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; - {% endfor %} -} - -message {{ x.name }}_response { - {% for x in x.output %} - {% if x.datatype in typedefs %} - {% set type = typedefs[x.datatype] %} - {% else %} - {% set type = x.datatype %} - {% endif %} - {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; - {% endfor %} -} -service {{ x.name }}_service { - rpc {{ x.name }}({{ x.name }}_request) returns ({{ x.name }}_response); -} + {% if item.interface != None %} + {% for x in n.methods %} + // IFEX: Method {{x.name}} + message {{ x.name }}_request { + {% for x in x.input %} + {% if x.datatype in typedefs %} + {% set type = typedefs[x.datatype] %} + {% else %} + {% set type = x.datatype %} + {% endif %} + {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; + {% endfor %} + } + + message {{ x.name }}_response { + {% for x in x.output %} + {% if x.datatype in typedefs %} + {% set type = typedefs[x.datatype] %} + {% else %} + {% set type = x.datatype %} + {% endif %} + {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; + {% endfor %} + } + + {% endfor %} + service {{ n.name }}_service { + {% for x in n.methods %} + rpc {{ x.name }}({{ x.name }}_request) returns ({{ x.name }}_response); + {% endfor %} + } {% endfor %} - {% for x in n.events %} -// IFEX Event {{x.name}} - {# Limitation: for now just creating a message #} -message {{ x.name }} { - {% for x in x.input %} - {% if x.datatype in typedefs %} - {% set type = typedefs[x.datatype] %} - {% else %} - {% set type = x.datatype %} - {% endif %} - {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; - {% endfor %} -} - - {% endfor %} - - {% for x in n.properties %} -// IFEX Property {{x.name}} -message {{ x.name }}_value { - {% if x.datatype in typedefs %} - {% set type = typedefs[x.datatype] %} - {% else %} - {% set type = x.datatype %} - {% endif %} - {{type|replace(".", "_")}} value = 1; -} - -// To request value in read operation -message {{ x.name }}_request {} - - {# With current specification all properties are read/write #} -service {{ x.name }} { - rpc {{ x.name }}_read({{ x.name }}_request) returns ({{ x.name }}_value); - rpc {{ x.name }}_write({{ x.name }}_value) returns (operation_result); -} - - {% endfor %} - {% endfor %} + {% for x in n.events %} + // IFEX Event {{x.name}} + {# Limitation: for now just creating a message #} + message {{ x.name }} { + {% for x in x.input %} + {% if x.datatype in typedefs %} + {% set type = typedefs[x.datatype] %} + {% else %} + {% set type = x.datatype %} + {% endif %} + {{type|replace(".", "_")}} {{ x.name }} = {{ loop.index }}; + {% endfor %} + } + + {% endfor %} + + {% for x in n.properties %} + // IFEX Property {{x.name}} + message {{ x.name }}_value { + {% if x.datatype in typedefs %} + {% set type = typedefs[x.datatype] %} + {% else %} + {% set type = x.datatype %} + {% endif %} + {{type|replace(".", "_")}} value = 1; + } + + // To request value in read operation + message {{ x.name }}_request {} + + {# With current specification all properties are read/write #} + service {{ x.name }} { + rpc {{ x.name }}_read({{ x.name }}_request) returns ({{ x.name }}_value); + rpc {{ x.name }}_write({{ x.name }}_value) returns (operation_result); + } + + {% endfor %} + {% endif %} +{% endfor %}