Skip to content

Commit 061cd6f

Browse files
Generate request / reply data structures (#451)
* Refs #22917. Add check method in Context. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22917. Set scope when creating interfaces. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22917. Generate basic details file. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22917. Generate Reply struct. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22917. Generate Request struct. * Refs #22917. Generate operation details. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22917. Include interface details in `TypesCdrAuxHeader`. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 0429652 commit 061cd6f

File tree

4 files changed

+171
-1
lines changed

4 files changed

+171
-1
lines changed

src/main/java/com/eprosima/fastdds/fastddsgen.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ private Project parseIDL(
802802
// Load Types common templates
803803
if (generate_typesupport_)
804804
{
805+
tmanager.addGroup("com/eprosima/fastdds/idl/templates/InterfaceDetails.stg");
805806
tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg");
806807
tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg");
807808
tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg");
@@ -1013,6 +1014,14 @@ private Project parseIDL(
10131014
}
10141015
}
10151016

1017+
if (ctx.isThereIsInterface())
1018+
{
1019+
// Generate Interface details
1020+
returnedValue &=
1021+
Utils.writeFile(output_dir + ctx.getFilename() + "_details.hpp",
1022+
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/InterfaceDetails.stg"), m_replace);
1023+
}
1024+
10161025
if (ctx.isThereIsStructOrUnion() || ctx.isThereIsException())
10171026
{
10181027
if (returnedValue &=

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

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

481+
public boolean isThereIsInterface()
482+
{
483+
return there_is_at_least_one_interface;
484+
}
485+
481486
public void setThereIsInputFeed(
482487
boolean value)
483488
{
@@ -760,7 +765,8 @@ public Interface createInterface(
760765
Token token)
761766
{
762767
Interface interfaceObject = new com.eprosima.fastdds.idl.grammar.Interface(
763-
this, getScopeFile(), isInScopedFile(), null, name, token);
768+
this, getScopeFile(), isInScopedFile(), getScope(), name, token);
769+
there_is_at_least_one_interface = true;
764770
return interfaceObject;
765771
}
766772

@@ -827,4 +833,6 @@ public Param createParam(
827833
private boolean there_is_at_least_one_output_feed = false;
828834

829835
private boolean there_is_at_least_one_non_feed_operation = false;
836+
837+
private boolean there_is_at_least_one_interface = false;
830838
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
group InterfaceDetails;
16+
17+
import "eprosima.stg"
18+
19+
main(ctx, definitions) ::= <<
20+
$fileHeader(ctx=ctx, file=[ctx.filename, "_details.hpp"], description=["This header file contains support data structures for RPC communication."])$
21+
22+
#ifndef FAST_DDS_GENERATED__$ctx.headerGuardName$_DETAILS_HPP
23+
#define FAST_DDS_GENERATED__$ctx.headerGuardName$_DETAILS_HPP
24+
25+
#include <fastcdr/xcdr/optional.hpp>
26+
#include <fastdds/dds/rpc/RemoteExceptionCode_t.hpp>
27+
#include <fastdds/dds/rpc/interfaces/RpcStatusCode.hpp>
28+
29+
#include "$ctx.filename$.hpp"
30+
31+
$definitions; separator="\n"$
32+
33+
#endif //FAST_DDS_GENERATED__$ctx.headerGuardName$_DETAILS_HPP
34+
>>
35+
36+
struct_type(ctx, parent, struct, member_list) ::= <<>>
37+
38+
union_type(ctx, parent, union, switch_type) ::= <<>>
39+
40+
bitmask_type(ctx, parent, bitmask) ::= <<>>
41+
42+
bitset_type(ctx, parent, bitset) ::= <<>>
43+
44+
module(ctx, parent, module, definition_list) ::= <<
45+
namespace $module.name$ {
46+
$definition_list$
47+
} // namespace $module.name$
48+
>>
49+
50+
interface(ctx, parent, interface, export_list) ::= <<
51+
namespace detail {
52+
53+
//{ $interface.name$ interface
54+
55+
$interface.all_operations : { operation | $operation_details(interface, operation)$ }; separator="\n"$
56+
57+
//{ top level
58+
59+
struct $interface.name$_Request
60+
{
61+
$interface.all_operations : { operation | $operation_request_members(interface, operation)$ }; separator="\n"$
62+
};
63+
64+
struct $interface.name$_Reply
65+
{
66+
$interface.all_operations : { operation | $operation_reply_members(interface, operation)$ }; separator="\n"$
67+
eprosima::fastcdr::optional<eprosima::fastdds::dds::rpc::RemoteExceptionCode_t\> remoteEx;
68+
};
69+
70+
//} // top level
71+
72+
//} // $interface.name$ interface
73+
74+
} // namespace detail
75+
>>
76+
77+
operation_details(interface, operation) ::= <<
78+
//{ $operation.name$
79+
$operation_in_struct(interface, operation)$
80+
81+
$operation.inputparam : { param | $if (param.annotationFeed)$$operation_feed_struct(interface, operation, param)$$endif$ }$
82+
83+
$operation_out_struct(interface, operation)$
84+
85+
$operation_result_struct(interface, operation)$
86+
87+
//} // $operation.name$
88+
89+
>>
90+
91+
operation_in_struct(interface, operation) ::= <<
92+
struct $interface.name$_$operation.name$_In
93+
{
94+
$if(operation.inputparam)$
95+
$operation.inputparam : { param | $if (!param.annotationFeed)$$parameter_declaration(param)$$endif$ }; separator="\n"$
96+
$endif$
97+
};
98+
>>
99+
100+
operation_feed_struct(interface, operation, param) ::= <<
101+
struct $interface.name$_$operation.name$_$param.name$_Feed
102+
{
103+
eprosima::fastcdr::optional<$param.typecode.cppTypename$> value;
104+
eprosima::fastcdr::optional<eprosima::fastdds::dds::rpc::RpcStatusCode> finished_;
105+
};
106+
>>
107+
108+
operation_out_struct(interface, operation) ::= <<
109+
struct $interface.name$_$operation.name$_Out
110+
{
111+
$if(operation.annotationFeed)$
112+
eprosima::fastcdr::optional<$operation.rettypeparam.typecode.cppTypename$\> $operation.rettypeparam.name$;
113+
eprosima::fastcdr::optional<bool\> finished_;
114+
$else$
115+
$if([operation.outputparam, operation.rettypeparam])$
116+
$[operation.outputparam, operation.rettypeparam]:{param | $parameter_declaration(param)$}; separator="\n"$
117+
$endif$
118+
$endif$
119+
};
120+
>>
121+
122+
operation_result_struct(interface, operation) ::= <<
123+
struct $interface.name$_$operation.name$_Result
124+
{
125+
eprosima::fastcdr::optional<$interface.name$_$operation.name$_Out\> result;
126+
$operation.exceptions : { exception |$operation_result_exception(typename=exception.scopedname, name=[exception.formatedScopedname, "_ex"])$}; separator="\n"$
127+
};
128+
>>
129+
130+
parameter_declaration(param) ::= <%
131+
$param.typecode.cppTypename$ $param.name$;
132+
%>
133+
134+
operation_result_exception(typename, name) ::= <%
135+
eprosima::fastcdr::optional<$typename$> $name$;
136+
%>
137+
138+
operation_request_members(interface, operation) ::= <%
139+
eprosima::fastcdr::optional<$interface.name$_$operation.name$_In> $operation.name$;
140+
$operation.inputparam : { param | $if (param.annotationFeed)$$operation_request_feed(interface, operation, param)$$endif$ }$
141+
%>
142+
143+
operation_request_feed(interface, operation, param) ::= <<
144+
145+
eprosima::fastcdr::optional<$interface.name$_$operation.name$_$param.name$_Feed\> $operation.name$_$param.name$;
146+
>>
147+
148+
operation_reply_members(interface, operation) ::= <<
149+
eprosima::fastcdr::optional<$interface.name$_$operation.name$_Result\> $operation.name$;
150+
>>

src/main/java/com/eprosima/fastdds/idl/templates/TypesCdrAuxHeader.stg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "CdrAux.hpp"], description=["This sourc
2323
#define FAST_DDS_GENERATED__$ctx.headerGuardName$CDRAUX_HPP
2424

2525
#include "$ctx.filename$.hpp"
26+
$if(ctx.thereIsInterface)$
27+
#include "$ctx.filename$_details.hpp"
28+
$endif$
2629

2730
$if(ctx.anyCdr)$
2831
$ctx.types:{ type | $if(type.inScope)$$if(type.typeCode.isStructType)$

0 commit comments

Comments
 (0)