Skip to content

Commit adc08d5

Browse files
Generate ServiceTypeSupport for interfaces (#459)
* Refs #22996. Skeleton for TypesCdrAuxHeaderImpl. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Added code to get reply type. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Added Operation `getOutTypeCode` and `getResultTypeCode` Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Added typecode for Exception. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Generate serialization code for replies. * Refs #22996. Generate serialization code for operation inputs. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Generate serialization code for input feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Generate serialization code for requests. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Generate code in PubSubTypeHeader. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Skeleton for code generation in PubSubTypeSource. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #22996. Code generation in PubSubTypeSource. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 061cd6f commit adc08d5

File tree

9 files changed

+773
-9
lines changed

9 files changed

+773
-9
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,11 +1038,8 @@ private Project parseIDL(
10381038
Utils.writeFile(output_dir + ctx.getFilename() + "PubSubTypes.hpp",
10391039
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg"), m_replace);
10401040
project.addCommonIncludeFile(relative_dir + ctx.getFilename() + "PubSubTypes.hpp");
1041-
if (ctx.existsLastStructure())
1041+
if (ctx.existsLastStructure() || ctx.isThereIsInterface())
10421042
{
1043-
m_atLeastOneStructure = true;
1044-
project.setHasStruct(true);
1045-
10461043
if (returnedValue &=
10471044
Utils.writeFile(output_dir + ctx.getFilename() + "PubSubTypes.cxx",
10481045
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg"), m_replace))
@@ -1056,6 +1053,12 @@ private Project parseIDL(
10561053
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg"), m_replace);
10571054
}
10581055
}
1056+
}
1057+
1058+
if (ctx.existsLastStructure())
1059+
{
1060+
m_atLeastOneStructure = true;
1061+
project.setHasStruct(true);
10591062

10601063
if (m_exampleOption != null)
10611064
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ public com.eprosima.idl.parser.tree.Exception createException(
316316
there_is_at_least_one_exception = true;
317317
}
318318

319-
return super.createException(name, token);
319+
Exception ex = new Exception(this, getScopeFile(), isInScopedFile(), getScope(), name, token);
320+
addException(ex);
321+
return ex;
320322
}
321323

322324

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.parser.typecode.StructTypeCode;
18+
19+
import com.eprosima.idl.parser.typecode.Kind;
20+
import com.eprosima.idl.parser.typecode.Member;
21+
import com.eprosima.idl.parser.typecode.PrimitiveTypeCode;
22+
import com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind;
23+
24+
import org.antlr.v4.runtime.Token;
25+
26+
public class Exception extends com.eprosima.idl.parser.tree.Exception
27+
{
28+
public Exception(Context ctx, String scopeFile, boolean isInScope, String scope, String name, Token token)
29+
{
30+
super(scopeFile, isInScope, scope, name, token);
31+
m_context = ctx;
32+
}
33+
34+
public StructTypeCode getTypeCode()
35+
{
36+
if (m_typecode == null)
37+
{
38+
m_typecode = new StructTypeCode(getScope(), getName());
39+
// Add inheritance
40+
m_typecode.addInheritance(m_context, getRpcOperationErrorTypeCode());
41+
// Add annotations
42+
getAnnotations().forEach((name, ann) -> m_typecode.addAnnotation(m_context, ann));
43+
// Add members
44+
getMembers().forEach(member -> m_typecode.addMember(member));
45+
// Default to final extensibility
46+
m_typecode.get_extensibility(ExtensibilityKind.FINAL);
47+
}
48+
49+
return m_typecode;
50+
}
51+
52+
private StructTypeCode getRpcOperationErrorTypeCode()
53+
{
54+
if (m_rpcOperationErrorTypeCode == null)
55+
{
56+
m_rpcOperationErrorTypeCode = new StructTypeCode("eprosima::fastdds::dds::rpc", "RpcOperationError");
57+
m_rpcOperationErrorTypeCode.get_extensibility(ExtensibilityKind.FINAL);
58+
int kind = com.eprosima.idl.parser.typecode.Kind.KIND_STRING;
59+
Member msg_member = new Member(m_context.createStringTypeCode(kind, null), "_error_message_");
60+
m_rpcOperationErrorTypeCode.addMember(msg_member);
61+
}
62+
return m_rpcOperationErrorTypeCode;
63+
}
64+
65+
private Context m_context = null;
66+
private StructTypeCode m_typecode = null;
67+
static private StructTypeCode m_rpcOperationErrorTypeCode = null;
68+
}

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

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

1717
import com.eprosima.fastdds.idl.grammar.Operation;
18+
import com.eprosima.fastdds.idl.parser.typecode.EnumTypeCode;
19+
import com.eprosima.fastdds.idl.parser.typecode.StructTypeCode;
20+
import com.eprosima.idl.parser.typecode.Member;
21+
import com.eprosima.idl.parser.typecode.EnumMember;
22+
import com.eprosima.idl.parser.typecode.TypeCode.ExtensibilityKind;
1823
import org.antlr.v4.runtime.Token;
1924

2025
public class Interface extends com.eprosima.idl.parser.tree.Interface
@@ -44,5 +49,100 @@ public void add(com.eprosima.idl.parser.tree.Export exp)
4449
super.add(exp);
4550
}
4651

47-
private Context m_context;
52+
/*!
53+
* @brief This function is used in stringtemplates to generate the typesupport code for the interface.
54+
*
55+
* @return The typecode of the request type.
56+
*/
57+
public StructTypeCode getRequestTypeCode()
58+
{
59+
if (m_request_type == null)
60+
{
61+
String scope = getHasScope() ? getScope() + "::detail" : "detail";
62+
StructTypeCode request_type = new StructTypeCode(scope, getName() + "_Request");
63+
64+
// The request type should be a `@choice`, which means that it should have MUTABLE extensibility,
65+
// and also treat all fields as optional.
66+
request_type.get_extensibility(ExtensibilityKind.MUTABLE);
67+
68+
getAll_operations().forEach(operation -> {
69+
Operation op = (Operation)operation;
70+
Member member = new Member(op.getInTypeCode(), op.getName());
71+
// Add `@optional` and `@hashid` annotations
72+
member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional")));
73+
member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid")));
74+
request_type.addMember(member);
75+
// Add input feed parameters
76+
op.getParameters().forEach(param -> {
77+
Param p = (Param)param;
78+
if (p.isInput() && p.isAnnotationFeed())
79+
{
80+
Member feed_member = new Member(p.getFeedTypeCode(), op.getName() + "_" + p.getName());
81+
feed_member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional")));
82+
feed_member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid")));
83+
request_type.addMember(feed_member);
84+
}
85+
});
86+
});
87+
88+
m_request_type = request_type;
89+
}
90+
return m_request_type;
91+
}
92+
93+
/*!
94+
* @brief This function is used in stringtemplates to generate the typesupport code for the interface.
95+
*
96+
* @return The typecode of the reply type.
97+
*/
98+
public StructTypeCode getReplyTypeCode()
99+
{
100+
if (m_reply_type == null)
101+
{
102+
String scope = getHasScope() ? getScope() + "::detail" : "detail";
103+
StructTypeCode reply_type = new StructTypeCode(scope, getName() + "_Reply");
104+
105+
// The reply type should be a `@choice`, which means that it should have MUTABLE extensibility,
106+
// and also treat all fields as optional.
107+
reply_type.get_extensibility(ExtensibilityKind.MUTABLE);
108+
109+
getAll_operations().forEach(operation -> {
110+
Operation op = (Operation)operation;
111+
Member member = new Member(op.getResultTypeCode(), op.getName());
112+
// Add `@optional` and `@hashid` annotations
113+
member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional")));
114+
member.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid")));
115+
reply_type.addMember(member);
116+
});
117+
118+
Member remoteEx = new Member(get_remoteExceptionCode_t_type(), "remoteEx");
119+
remoteEx.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional")));
120+
remoteEx.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid")));
121+
reply_type.addMember(remoteEx);
122+
123+
m_reply_type = reply_type;
124+
}
125+
return m_reply_type;
126+
}
127+
128+
private EnumTypeCode get_remoteExceptionCode_t_type()
129+
{
130+
if (m_remoteExceptionCode_t_type == null)
131+
{
132+
EnumTypeCode type = new EnumTypeCode("eprosima::fastdds::dds::rpc", "RemoteExceptionCode_t");
133+
type.addMember(new EnumMember("REMOTE_EX_OK"));
134+
type.addMember(new EnumMember("REMOTE_EX_UNSUPPORTED"));
135+
type.addMember(new EnumMember("REMOTE_EX_INVALID_ARGUMENT"));
136+
type.addMember(new EnumMember("REMOTE_EX_OUT_OF_RESOURCES"));
137+
type.addMember(new EnumMember("REMOTE_EX_UNKNOWN_OPERATION"));
138+
type.addMember(new EnumMember("REMOTE_EX_UNKNOWN_EXCEPTION"));
139+
m_remoteExceptionCode_t_type = type;
140+
}
141+
return m_remoteExceptionCode_t_type;
142+
}
143+
144+
private Context m_context = null;
145+
private StructTypeCode m_request_type = null;
146+
private StructTypeCode m_reply_type = null;
147+
static private EnumTypeCode m_remoteExceptionCode_t_type = null;
48148
}

0 commit comments

Comments
 (0)