Skip to content

Commit 0429652

Browse files
Generate code for interfaces in header files (#447)
* Refs #22909. Add file to test interfaces generation. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Add generation of interfaces to TypesHeader template. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Fail for output feed parameters. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Add include directives for input feed. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Add include directives for output feed. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Add include directives for futures. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Address review comment. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Fix namespace. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22909. Update test submodule. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 3bab873 commit 0429652

File tree

6 files changed

+181
-3
lines changed

6 files changed

+181
-3
lines changed

src/main/java/com/eprosima/fastcdr/idl/templates/FastCdrCommon.stg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
1414

1515
group FastCdrCommon;
1616

17+
paramRetType(typecode) ::= <%
18+
$if(typecode)$
19+
$typecode.cppTypename$
20+
$else$
21+
void
22+
$endif$
23+
%>
24+
25+
paramTypeByRef(typecode) ::= <%
26+
$typecode.cppTypename$&
27+
%>
28+
29+
paramTypeByValue(typecode, feed) ::= <%
30+
$if(feed)$
31+
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<$typecode.cppTypename$> >&
32+
$else$
33+
$if(typecode.primitive)$
34+
$typecode.cppTypename$
35+
$else$
36+
const $typecode.cppTypename$&
37+
$endif$
38+
$endif$
39+
%>
40+
41+
paramDeclarations(params, initialSeparator="") ::= <<
42+
$if(params)$$initialSeparator$$endif$$params : {param | /*$param.comment$*/ $if(param.output)$$paramTypeByRef(typecode=param.typecode)$$else$$paramTypeByValue(typecode=param.typecode, feed=param.annotationFeed)$$endif$ $param.name$}; anchor, separator=",\n"$
43+
>>
44+
1745
object_serialization(ctx, object) ::= <<
1846
scdr << eprosima::fastcdr::MemberId($object.id$) << $object.name$();
1947
>>

src/main/java/com/eprosima/fastcdr/idl/templates/TypesHeader.stg

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ $endif$
3333
$if(ctx.thereIsMap)$
3434
#include <map>
3535
$endif$
36+
$if(ctx.thereIsInputFeed || ctx.thereIsOutputFeed)$
37+
#include <memory>
38+
$endif$
3639
$if(ctx.thereIsString)$
3740
#include <string>
3841
$endif$
@@ -57,6 +60,15 @@ $endif$
5760
$if(ctx.thereIsException)$
5861
#include <fastdds/dds/rpc/exceptions/RpcOperationError.hpp>
5962
$endif$
63+
$if(ctx.thereIsOutputFeed)$
64+
#include <fastdds/dds/rpc/interfaces/RpcClientReader.hpp>
65+
$endif$
66+
$if(ctx.thereIsInputFeed)$
67+
#include <fastdds/dds/rpc/interfaces/RpcClientWriter.hpp>
68+
$endif$
69+
$if(ctx.thereIsNonFeedOperation)$
70+
#include <fastdds/dds/rpc/interfaces/RpcFuture.hpp>
71+
$endif$
6072

6173
$ctx.directIncludeDependencies : {include | #include "$include$.hpp"}; separator="\n"$
6274

@@ -189,6 +201,12 @@ public:
189201
};
190202
>>
191203

204+
operation(ctx, parent, operation, param_list, operation_type) ::= <<
205+
virtual $operationRetType(operation)$ $operation.name$(
206+
$paramDeclarations(params=operation.parameters)$) = 0;
207+
208+
>>
209+
192210
const_decl(ctx, parent, const, const_type) ::= <<
193211
$const_type$
194212
const $const.typeCode.cppTypename$ $const.name$ = $const.value$$const_value_prefix(const)$;
@@ -917,6 +935,14 @@ new(&m_$member.name$) $member_type_declaration(member)$();
917935
$endif$
918936
>>
919937

938+
operationRetType(operation) ::= <%
939+
$if(operation.annotationFeed)$
940+
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientReader<$paramRetType(operation.rettype)$> >
941+
$else$
942+
eprosima::fastdds::dds::rpc::RpcFuture<$paramRetType(operation.rettype)$>
943+
$endif$
944+
%>
945+
920946
//{ Fast DDS-Gen extensions
921947
module_conversion(ctx, parent, modules, definition_list) ::= <<
922948
$modules : { module |

src/main/java/com/eprosima/fastdds/idl/grammar/Context.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,39 @@ public boolean isThereIsException()
478478
return there_is_at_least_one_exception;
479479
}
480480

481+
public void setThereIsInputFeed(
482+
boolean value)
483+
{
484+
there_is_at_least_one_input_feed = value;
485+
}
486+
487+
public boolean isThereIsInputFeed()
488+
{
489+
return there_is_at_least_one_input_feed;
490+
}
491+
492+
public boolean setThereIsOutputFeed(
493+
boolean value)
494+
{
495+
return there_is_at_least_one_output_feed = value;
496+
}
497+
498+
public boolean isThereIsOutputFeed()
499+
{
500+
return there_is_at_least_one_output_feed;
501+
}
502+
503+
public boolean setThereIsNonFeedOperation(
504+
boolean value)
505+
{
506+
return there_is_at_least_one_non_feed_operation = value;
507+
}
508+
509+
public boolean isThereIsNonFeedOperation()
510+
{
511+
return there_is_at_least_one_non_feed_operation;
512+
}
513+
481514
/*** Functions inherited from FastCDR Context ***/
482515

483516
@Override
@@ -721,12 +754,22 @@ else if (name.equals(Annotation.external_str))
721754
return super.getAnnotationDeclaration(name);
722755
}
723756

757+
@Override
758+
public Interface createInterface(
759+
String name,
760+
Token token)
761+
{
762+
Interface interfaceObject = new com.eprosima.fastdds.idl.grammar.Interface(
763+
this, getScopeFile(), isInScopedFile(), null, name, token);
764+
return interfaceObject;
765+
}
766+
724767
@Override
725768
public Operation createOperation(
726769
String name,
727770
Token token)
728771
{
729-
Operation operationObject = new Operation(getScopeFile(), isInScopedFile(), null, name, token);
772+
Operation operationObject = new Operation(this, getScopeFile(), isInScopedFile(), null, name, token);
730773
return operationObject;
731774
}
732775

@@ -778,4 +821,10 @@ public Param createParam(
778821
private boolean there_is_at_least_one_union = false;
779822

780823
private boolean there_is_at_least_one_exception = false;
824+
825+
private boolean there_is_at_least_one_input_feed = false;
826+
827+
private boolean there_is_at_least_one_output_feed = false;
828+
829+
private boolean there_is_at_least_one_non_feed_operation = false;
781830
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.eprosima.fastdds.idl.grammar;
16+
17+
import com.eprosima.fastdds.idl.grammar.Operation;
18+
import org.antlr.v4.runtime.Token;
19+
20+
public class Interface extends com.eprosima.idl.parser.tree.Interface
21+
{
22+
public Interface(Context ctx, String scopeFile, boolean isInScope, String scope, String name, Token tk)
23+
{
24+
super(scopeFile, isInScope, scope, name, tk);
25+
m_context = ctx;
26+
}
27+
28+
@Override
29+
public void add(com.eprosima.idl.parser.tree.Export exp)
30+
{
31+
if (exp instanceof Operation)
32+
{
33+
Operation op = (Operation)exp;
34+
if (op.isAnnotationFeed())
35+
{
36+
m_context.setThereIsOutputFeed(true);
37+
}
38+
else
39+
{
40+
m_context.setThereIsNonFeedOperation(true);
41+
}
42+
}
43+
44+
super.add(exp);
45+
}
46+
47+
private Context m_context;
48+
}

src/main/java/com/eprosima/fastdds/idl/grammar/Operation.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
package com.eprosima.fastdds.idl.grammar;
1616

1717
import com.eprosima.idl.parser.exception.RuntimeGenerationException;
18+
import com.eprosima.idl.parser.exception.ParseException;
19+
import com.eprosima.fastdds.idl.grammar.Param;
1820
import org.antlr.v4.runtime.Token;
1921

2022
public class Operation extends com.eprosima.idl.parser.tree.Operation
2123
{
22-
public Operation(String scopeFile, boolean isInScope, String scope, String name, Token tk)
24+
public Operation(Context ctx, String scopeFile, boolean isInScope, String scope, String name, Token tk)
2325
{
2426
super(scopeFile, isInScope, scope, name, tk);
27+
m_context = ctx;
2528
}
2629

2730
/**
@@ -45,4 +48,28 @@ public boolean isAnnotationFeed()
4548
}
4649
return false;
4750
}
51+
52+
@Override
53+
public void add(com.eprosima.idl.parser.tree.Param param)
54+
{
55+
Param p = (Param)param;
56+
// Process feed annotation
57+
if (p.isAnnotationFeed())
58+
{
59+
if (p.isOutput())
60+
{
61+
// Fail if parameter is out and feed
62+
throw new ParseException(null, "Output parameter " + p.getName() + " has '@feed' annotation.");
63+
}
64+
else
65+
{
66+
// Take note that there is at least one input feed
67+
m_context.setThereIsInputFeed(true);
68+
}
69+
}
70+
71+
super.add(param);
72+
}
73+
74+
private Context m_context;
4875
}

thirdparty/dds-types-test

0 commit comments

Comments
 (0)