Skip to content

Commit c9ff1be

Browse files
Generate code for interface clients (#464)
* Refs #23017. Add virtual destructor to interface abstract class. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Skeleton for client creation code. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Skeleton for client class. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Generate processing thread code. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Add `process_reply` implementation. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Code for basic requests. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Improve linters. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Code for basic replies. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Add support for operation exceptions. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Skeleton for output feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Generate code for input feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Add cancellation logic to output feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Validation and exceptions in output feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Initial implementation for `read` methods. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Linters. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Improve cancel method. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Process values in output feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Return values before exception. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Exceptions finish the feed instead of cancelling it. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Process incoming exceptions in output feeds. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Fail when reply is for a different operation. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Add feed cancellation to request type. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Implement feed cancellation on client reader. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Fix atomic initialization. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23017. Make generated code compatible with C++11. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent adc08d5 commit c9ff1be

File tree

7 files changed

+836
-1
lines changed

7 files changed

+836
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $typecode.cppTypename$&
2828

2929
paramTypeByValue(typecode, feed) ::= <%
3030
$if(feed)$
31-
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<$typecode.cppTypename$> >&
31+
std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<$typecode.cppTypename$>>&
3232
$else$
3333
$if(typecode.primitive)$
3434
$typecode.cppTypename$

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ interface(ctx, parent, interface, export_list) ::= <<
196196
class $ctx.fileNameUpper$_DllAPI $interface.name$ $if(interface.bases)$: $interface.bases : {base |public $base.scopedname$}; separator=", "$$endif$
197197
{
198198
public:
199+
virtual ~$interface.name$() = default;
199200

200201
$export_list$
201202
};

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ private Project parseIDL(
807807
tmanager.addGroup("com/eprosima/fastdds/idl/templates/TypesCdrAuxHeaderImpl.stg");
808808
tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeHeader.stg");
809809
tmanager.addGroup("com/eprosima/fastdds/idl/templates/DDSPubSubTypeSource.stg");
810+
tmanager.addGroup("com/eprosima/fastdds/idl/templates/ClientHeader.stg");
811+
tmanager.addGroup("com/eprosima/fastdds/idl/templates/ClientSource.stg");
810812

811813
if (generate_typeobjectsupport_)
812814
{
@@ -1055,6 +1057,23 @@ private Project parseIDL(
10551057
}
10561058
}
10571059

1060+
// Generate client code for interfaces
1061+
if (ctx.isThereIsInterface())
1062+
{
1063+
if (returnedValue &=
1064+
Utils.writeFile(output_dir + ctx.getFilename() + "Client.hpp",
1065+
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/ClientHeader.stg"), m_replace))
1066+
{
1067+
project.addCommonIncludeFile(relative_dir + ctx.getFilename() + "Client.hpp");
1068+
}
1069+
if (returnedValue &=
1070+
Utils.writeFile(output_dir + ctx.getFilename() + "Client.cxx",
1071+
maintemplates.getTemplate("com/eprosima/fastdds/idl/templates/ClientSource.stg"), m_replace))
1072+
{
1073+
project.addCommonSrcFile(relative_dir + ctx.getFilename() + "Client.cxx");
1074+
}
1075+
}
1076+
10581077
if (ctx.existsLastStructure())
10591078
{
10601079
m_atLeastOneStructure = true;

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void add(com.eprosima.idl.parser.tree.Export exp)
3838
Operation op = (Operation)exp;
3939
if (op.isAnnotationFeed())
4040
{
41+
m_hasOutputFeeds = true;
4142
m_context.setThereIsOutputFeed(true);
4243
}
4344
else
@@ -49,6 +50,16 @@ public void add(com.eprosima.idl.parser.tree.Export exp)
4950
super.add(exp);
5051
}
5152

53+
/*!
54+
* @brief This function is used to check if the interface has output feeds.
55+
*
56+
* @return True if the interface has output feeds, false otherwise.
57+
*/
58+
public boolean isWithOutputFeeds()
59+
{
60+
return m_hasOutputFeeds;
61+
}
62+
5263
/*!
5364
* @brief This function is used in stringtemplates to generate the typesupport code for the interface.
5465
*
@@ -85,6 +96,16 @@ public StructTypeCode getRequestTypeCode()
8596
});
8697
});
8798

99+
if (m_hasOutputFeeds)
100+
{
101+
// Optional boolean to indicate if the feed is cancelled
102+
Member feed_cancel = new Member(m_context.createPrimitiveTypeCode(
103+
com.eprosima.idl.parser.typecode.Kind.KIND_BOOLEAN), "feed_cancel_");
104+
feed_cancel.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("optional")));
105+
feed_cancel.addAnnotation(m_context, new Annotation(m_context.getAnnotationDeclaration("hashid")));
106+
request_type.addMember(feed_cancel);
107+
}
108+
88109
m_request_type = request_type;
89110
}
90111
return m_request_type;
@@ -142,6 +163,7 @@ private EnumTypeCode get_remoteExceptionCode_t_type()
142163
}
143164

144165
private Context m_context = null;
166+
private boolean m_hasOutputFeeds = false;
145167
private StructTypeCode m_request_type = null;
146168
private StructTypeCode m_reply_type = null;
147169
static private EnumTypeCode m_remoteExceptionCode_t_type = null;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 ProtocolHeader;
16+
17+
import "eprosima.stg"
18+
19+
main(ctx, definitions) ::= <<
20+
$fileHeader(ctx=ctx, file=[ctx.filename, "Client.hpp"], description=["Client implementation for interfaces"])$
21+
22+
#ifndef FAST_DDS_GENERATED__$ctx.headerGuardName$_CLIENT_HPP
23+
#define FAST_DDS_GENERATED__$ctx.headerGuardName$_CLIENT_HPP
24+
25+
#include <memory>
26+
27+
#include <fastdds/dds/domain/DomainParticipant.hpp>
28+
#include <fastdds/dds/domain/qos/RequesterQos.hpp>
29+
30+
#include "$ctx.filename$.hpp"
31+
32+
$definitions; separator="\n"$
33+
34+
#endif // FAST_DDS_GENERATED__$ctx.headerGuardName$_CLIENT_HPP
35+
36+
>>
37+
38+
module(ctx, parent, module, definition_list) ::= <<
39+
namespace $module.name$ {
40+
41+
$definition_list$
42+
43+
} // namespace $module.name$
44+
45+
>>
46+
47+
interface(ctx, parent, interface, export_list) ::= <<
48+
extern $ctx.fileNameUpper$_DllAPI std::shared_ptr<$interface.name$> create_$interface.name$Client(
49+
eprosima::fastdds::dds::DomainParticipant& part,
50+
const char* service_name,
51+
const eprosima::fastdds::dds::RequesterQos& qos);
52+
>>

0 commit comments

Comments
 (0)