Skip to content

Commit 019c783

Browse files
Add RPC interfaces, exceptions, and example (#233)
* Refs #23079. Add rpc interfaces to python bindings. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Add rpc exceptions to python bindings. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Add calculator IDL and example python code. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Generate code with fastddsgen. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Build new example. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Add new example to regeneration script. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Move generated code to a different folder. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Add readme for RPC example. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23079. Move HelloWorld generated code to a different folder. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 48b3fe0 commit 019c783

34 files changed

Lines changed: 8553 additions & 23 deletions

fastdds_python/src/swig/fastdds.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,5 @@ namespace xtypes {
241241
%include "fastdds/dds/domain/DomainParticipant.i"
242242
%include "fastdds/dds/domain/DomainParticipantFactory.i"
243243
%include "fastdds/dds/xtypes/type_representation/TypeObject.i"
244+
%include "fastdds/dds/rpc/interfaces.i"
245+
%include "fastdds/dds/rpc/exceptions.i"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
%{
16+
#include "fastdds/dds/rpc/exceptions.hpp"
17+
%}
18+
19+
// Base class should be included first
20+
%include "fastdds/dds/rpc/exceptions/RpcException.hpp"
21+
// Include first level inheritance
22+
%include "fastdds/dds/rpc/exceptions/RpcBrokenPipeException.hpp"
23+
%include "fastdds/dds/rpc/exceptions/RpcFeedCancelledException.hpp"
24+
%include "fastdds/dds/rpc/exceptions/RpcOperationError.hpp"
25+
%include "fastdds/dds/rpc/exceptions/RpcTimeoutException.hpp"
26+
// This is the base class for second level inheritance
27+
%include "fastdds/dds/rpc/RemoteExceptionCode_t.hpp"
28+
%include "fastdds/dds/rpc/exceptions/RpcRemoteException.hpp"
29+
// Include second level inheritance
30+
%include "fastdds/dds/rpc/exceptions/RemoteInvalidArgumentError.hpp"
31+
%include "fastdds/dds/rpc/exceptions/RemoteOutOfResourcesError.hpp"
32+
%include "fastdds/dds/rpc/exceptions/RemoteUnknownExceptionError.hpp"
33+
%include "fastdds/dds/rpc/exceptions/RemoteUnknownOperationError.hpp"
34+
%include "fastdds/dds/rpc/exceptions/RemoteUnsupportedError.hpp"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
%{
16+
#include "fastdds/dds/rpc/interfaces.hpp"
17+
%}
18+
19+
%include "fastdds/dds/rpc/interfaces/RpcStatusCode.hpp"

fastdds_python_examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ project(FastDdsPythonExamples)
2020
# Examples subdirectory
2121
###############################################################################
2222

23-
add_subdirectory(HelloWorldExample)
23+
add_subdirectory(HelloWorldExample/generated_code)
24+
add_subdirectory(RPCExample/generated_code)

fastdds_python_examples/HelloWorldExample/CMakeLists.txt renamed to fastdds_python_examples/HelloWorldExample/generated_code/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11

2+
# Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
216
cmake_minimum_required(VERSION 3.20)
317

418
# SWIG: use standard target name.
@@ -69,7 +83,7 @@ set(${PROJECT_NAME}_MODULE
6983
)
7084

7185
set(${PROJECT_NAME}_MODULE_FILES
72-
${PROJECT_NAME}.i
86+
HelloWorld.i
7387
)
7488

7589
SET_SOURCE_FILES_PROPERTIES(

fastdds_python_examples/HelloWorldExample/HelloWorld.hpp renamed to fastdds_python_examples/HelloWorldExample/generated_code/HelloWorld.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @file HelloWorld.hpp
1717
* This header file contains the declaration of the described types in the IDL file.
1818
*
19-
* This file was generated by the tool fastddsgen.
19+
* This file was generated by the tool fastddsgen (version: 4.1.0).
2020
*/
2121

2222
#ifndef FAST_DDS_GENERATED__HELLOWORLD_HPP

fastdds_python_examples/HelloWorldExample/HelloWorld.i renamed to fastdds_python_examples/HelloWorldExample/generated_code/HelloWorld.i

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @file HelloWorld.i
1717
* This header file contains the SWIG interface of the described types in the IDL file.
1818
*
19-
* This file was generated by the tool fastddsgen.
19+
* This file was generated by the tool fastddsgen (version: 4.1.0).
2020
*/
2121

2222
%module(moduleimport="if __import__('os').name == 'nt': import win32api; win32api.LoadLibrary('HelloWorld.dll')\nif __package__ or '.' in __name__:\n from . import _HelloWorldWrapper\nelse:\n import _HelloWorldWrapper") HelloWorld
@@ -49,7 +49,6 @@
4949

5050
%{
5151
#include "HelloWorld.hpp"
52-
5352
#include <fastdds/dds/core/LoanableSequence.hpp>
5453
%}
5554

@@ -121,7 +120,6 @@ namespace swig {
121120

122121
// Include the class interfaces
123122
%include "HelloWorld.hpp"
124-
125123
// Include the corresponding TopicDataType
126124
%include "HelloWorldPubSubTypes.i"
127125

fastdds_python_examples/HelloWorldExample/HelloWorldCdrAux.hpp renamed to fastdds_python_examples/HelloWorldExample/generated_code/HelloWorldCdrAux.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
* @file HelloWorldCdrAux.hpp
1717
* This source file contains some definitions of CDR related functions.
1818
*
19-
* This file was generated by the tool fastddsgen.
19+
* This file was generated by the tool fastddsgen (version: 4.1.0).
2020
*/
2121

2222
#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP
2323
#define FAST_DDS_GENERATED__HELLOWORLDCDRAUX_HPP
2424

2525
#include "HelloWorld.hpp"
26-
2726
constexpr uint32_t HelloWorld_max_cdr_typesize {268UL};
2827
constexpr uint32_t HelloWorld_max_key_cdr_typesize {0UL};
2928

fastdds_python_examples/HelloWorldExample/HelloWorldCdrAux.ipp renamed to fastdds_python_examples/HelloWorldExample/generated_code/HelloWorldCdrAux.ipp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @file HelloWorldCdrAux.ipp
1717
* This source file contains some declarations of CDR related functions.
1818
*
19-
* This file was generated by the tool fastddsgen.
19+
* This file was generated by the tool fastddsgen (version: 4.1.0).
2020
*/
2121

2222
#ifndef FAST_DDS_GENERATED__HELLOWORLDCDRAUX_IPP

fastdds_python_examples/HelloWorldExample/HelloWorldPubSubTypes.cxx renamed to fastdds_python_examples/HelloWorldExample/generated_code/HelloWorldPubSubTypes.cxx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @file HelloWorldPubSubTypes.cpp
1717
* This header file contains the implementation of the serialization functions.
1818
*
19-
* This file was generated by the tool fastddsgen.
19+
* This file was generated by the tool fastddsgen (version: 4.1.0).
2020
*/
2121

2222
#include "HelloWorldPubSubTypes.hpp"
@@ -56,7 +56,7 @@ bool HelloWorldPubSubType::serialize(
5656
SerializedPayload_t& payload,
5757
DataRepresentationId_t data_representation)
5858
{
59-
const HelloWorld* p_type = static_cast<const HelloWorld*>(data);
59+
const ::HelloWorld* p_type = static_cast<const ::HelloWorld*>(data);
6060

6161
// Object that manages the raw buffer.
6262
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
@@ -95,7 +95,7 @@ bool HelloWorldPubSubType::deserialize(
9595
try
9696
{
9797
// Convert DATA to pointer of your type
98-
HelloWorld* p_type = static_cast<HelloWorld*>(data);
98+
::HelloWorld* p_type = static_cast<::HelloWorld*>(data);
9999

100100
// Object that manages the raw buffer.
101101
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
@@ -129,7 +129,7 @@ uint32_t HelloWorldPubSubType::calculate_serialized_size(
129129
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
130130
size_t current_alignment {0};
131131
return static_cast<uint32_t>(calculator.calculate_serialized_size(
132-
*static_cast<const HelloWorld*>(data), current_alignment)) +
132+
*static_cast<const ::HelloWorld*>(data), current_alignment)) +
133133
4u /*encapsulation*/;
134134
}
135135
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
@@ -140,13 +140,13 @@ uint32_t HelloWorldPubSubType::calculate_serialized_size(
140140

141141
void* HelloWorldPubSubType::create_data()
142142
{
143-
return reinterpret_cast<void*>(new HelloWorld());
143+
return reinterpret_cast<void*>(new ::HelloWorld());
144144
}
145145

146146
void HelloWorldPubSubType::delete_data(
147147
void* data)
148148
{
149-
delete(reinterpret_cast<HelloWorld*>(data));
149+
delete(reinterpret_cast<::HelloWorld*>(data));
150150
}
151151

152152
bool HelloWorldPubSubType::compute_key(
@@ -159,7 +159,7 @@ bool HelloWorldPubSubType::compute_key(
159159
return false;
160160
}
161161

162-
HelloWorld data;
162+
::HelloWorld data;
163163
if (deserialize(payload, static_cast<void*>(&data)))
164164
{
165165
return compute_key(static_cast<void*>(&data), handle, force_md5);
@@ -178,7 +178,7 @@ bool HelloWorldPubSubType::compute_key(
178178
return false;
179179
}
180180

181-
const HelloWorld* p_type = static_cast<const HelloWorld*>(data);
181+
const ::HelloWorld* p_type = static_cast<const ::HelloWorld*>(data);
182182

183183
// Object that manages the raw buffer.
184184
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),

0 commit comments

Comments
 (0)