Skip to content

Commit 0dc2f3f

Browse files
JLBuenoLopezIkerLuengoEduPonzrichiware
authored
[13382] Several fixes (#3)
* Prefer the FASTDDS namespace includes over FASTRTPS Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Update test to use callbacks on the reader Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Support callbacks defined in Python This requires: - Compiling the module using directors - Compiling the module using multithreading support on Python - Declaring which classes need directors (the callbacks) Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Fix segmentation fault on Participant destruction Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Create install target Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Remove unnecessary links Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Convert old test into an example Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs 11914. Add a readme to the example Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914. Move target module fastdds_wrapper to fastdds Signed-off-by: Iker Luengo <ikerluengo@eprosima.com> * Refs 11914: Set Fast DDS branch to master Signed-off-by: Eduardo Ponz <eduardoponz@eprosima.com> * Refs #12678: add ContentFilteredTopic related headers Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #12678: update .repos Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #12678: update types (generated with Fast DDS Gen 2.1.0) Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #12678: fix warnings introduced in Fast DDS 2.5.0 (new InstanceHandle operators, ContentFilter interfaces) Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #12678: fix undefined symbol issue Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #13382: fix InstanceHandle class Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #13382: fix warnings Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #13382: update README, limitations Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com> * Refs #13382. Apply suggestions Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> * Refs #13382. Fix installation of examples's C++ library Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> * Refs #13382. Fix example's help message Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> Co-authored-by: Iker Luengo <ikerluengo@eprosima.com> Co-authored-by: Eduardo Ponz <eduardoponz@eprosima.com> Co-authored-by: Ricardo González Moreno <ricardo@richiware.dev>
1 parent f3537b1 commit 0dc2f3f

36 files changed

Lines changed: 484 additions & 222 deletions

CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8.12)
2-
3-
if(NOT CMAKE_VERSION VERSION_LESS 3.0)
4-
cmake_policy(SET CMP0048 NEW)
5-
endif()
1+
cmake_minimum_required(VERSION 3.13)
62

73
# SWIG: use standard target name.
84
if(POLICY CMP0078)
@@ -24,7 +20,7 @@ FIND_PACKAGE(SWIG REQUIRED)
2420
INCLUDE(${SWIG_USE_FILE})
2521
SET(CMAKE_SWIG_FLAGS "")
2622

27-
FIND_PACKAGE(PythonLibs)
23+
FIND_PACKAGE(PythonLibs REQUIRED)
2824
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
2925

3026
FIND_PACKAGE(fastrtps REQUIRED)
@@ -34,5 +30,3 @@ FIND_PACKAGE(fastrtps REQUIRED)
3430
###############################################################################
3531

3632
add_subdirectory(src/swig)
37-
add_subdirectory(test)
38-

README.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@ This project is on the very early stages of development, and there are many feat
6666
* QoS modification is not supported on python. It is possible to create a QoS object with the default constructor
6767
or retrieve it with the `get_qos` methods of the entities, but it is not possible to modify the QoS values.
6868
If you need to use non-default QoS, please use XML configuration files.
69-
* Status listeners are not available. Even though python will not complain if you add a listener to an entity, the listener will not be triggered.
70-
* Support in [*Fast DDS gen*](https://fast-dds.docs.eprosima.com/en/latest/fastddsgen/usage/usage.html) is also limited to structs of simple types (no nested structs nor arrays or maps).
71-
7269

7370
## Python example
7471

75-
The *Fast DDS* functionality is contained in the `fastdds_wrapper` module, so you will need to include that module in your script. You will also need to create the python binding for your data type and include its module. This example will guide you through these steps in a simple example.
72+
The *Fast DDS* functionality is contained in the `fastdds` module, so you will need to include that module in your script. You will also need to create the python binding for your data type and include its module. This example will guide you through these steps in a simple example.
7673

7774
### Generate a data type
7875

@@ -105,32 +102,32 @@ This will create a `HelloWorld.py` file with a `HelloWorld` module that you will
105102

106103
### Creating the DataWriter
107104

108-
Import the `fastdds_wrapper` and the `HelloWorld` modules and follow the usual steps to create a DataWriter:
105+
Import the `fastdds` and the `HelloWorld` modules and follow the usual steps to create a DataWriter:
109106

110107
```python
111-
import fastdds_wrapper
108+
import fastdds
112109
import HelloWorld
113110

114111
domain = 5;
115-
factory = fastdds_wrapper.DomainParticipantFactory.get_instance()
116-
participant_qos = fastdds_wrapper.DomainParticipantQos()
112+
factory = fastdds.DomainParticipantFactory.get_instance()
113+
participant_qos = fastdds.DomainParticipantQos()
117114
factory.get_default_participant_qos(participant_qos)
118115
participant = factory.create_participant(domain, participant_qos)
119116

120117
topic_data_type = HelloWorld.HelloWorldPubSubType()
121118
topic_data_type.setName("HelloWorldDataType")
122-
type_support = fastdds_wrapper.TypeSupport(topic_data_type)
119+
type_support = fastdds.TypeSupport(topic_data_type)
123120
participant.register_type(type_support)
124121

125-
topic_qos = fastdds_wrapper.TopicQos()
122+
topic_qos = fastdds.TopicQos()
126123
participant.get_default_topic_qos(topic_qos)
127124
topic = self.participant.create_topic("myTopic", topic_data_type.getName(), topic_qos)
128125

129-
publisher_qos = fastdds_wrapper.PublisherQos()
126+
publisher_qos = fastdds.PublisherQos()
130127
participant.get_default_publisher_qos(publisher_qos)
131128
publisher = participant.create_publisher(publisher_qos)
132129

133-
writer_qos = fastdds_wrapper.DataWriterQos()
130+
writer_qos = fastdds.DataWriterQos()
134131
publisher.get_default_datawriter_qos(writer_qos)
135132
writer = self.publisher.create_datawriter(topic, writer_qos)
136133
```
@@ -148,32 +145,32 @@ writer.write(data)
148145

149146
### Creating the DataReader
150147

151-
Import the `fastdds_wrapper` and the `HelloWorld` modules and follow the usual steps to create a DataReader:
148+
Import the `fastdds` and the `HelloWorld` modules and follow the usual steps to create a DataReader:
152149

153150
```python
154-
import fastdds_wrapper
151+
import fastdds
155152
import HelloWorld
156153

157154
domain = 5;
158-
factory = fastdds_wrapper.DomainParticipantFactory.get_instance()
159-
participant_qos = fastdds_wrapper.DomainParticipantQos()
155+
factory = fastdds.DomainParticipantFactory.get_instance()
156+
participant_qos = fastdds.DomainParticipantQos()
160157
factory.get_default_participant_qos(participant_qos)
161158
participant = factory.create_participant(domain, participant_qos)
162159

163160
topic_data_type = HelloWorld.HelloWorldPubSubType()
164161
topic_data_type.setName("HelloWorldDataType")
165-
type_support = fastdds_wrapper.TypeSupport(topic_data_type)
162+
type_support = fastdds.TypeSupport(topic_data_type)
166163
participant.register_type(type_support)
167164

168-
topic_qos = fastdds_wrapper.TopicQos()
165+
topic_qos = fastdds.TopicQos()
169166
participant.get_default_topic_qos(topic_qos)
170167
topic = participant.create_topic("myTopic", topic_data_type.getName(), topic_qos)
171168

172-
subscriber_qos = fastdds_wrapper.SubscriberQos()
169+
subscriber_qos = fastdds.SubscriberQos()
173170
participant.get_default_subscriber_qos(subscriber_qos)
174171
subscriber = participant.create_subscriber(subscriber_qos)
175172

176-
reader_qos = fastdds_wrapper.DataReaderQos()
173+
reader_qos = fastdds.DataReaderQos()
177174
subscriber.get_default_datareader_qos(reader_qos)
178175
reader = subscriber.create_datareader(topic, reader_qos)
179176
```
@@ -183,7 +180,7 @@ reader = subscriber.create_datareader(topic, reader_qos)
183180
You can read a sample the same way you would do it in C++:
184181

185182
```python
186-
info = fastdds_wrapper.SampleInfo()
183+
info = fastdds.SampleInfo()
187184
data = HelloWorld.HelloWorld()
188185
reader.take_next_sample(data, info)
189186

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
# Using minimum CMake version 3.13 to prevent issues with the SWIG include
3+
# directories propagation happening with CMake 3.12 and prior
4+
5+
cmake_minimum_required(VERSION 3.13)
6+
7+
# SWIG: use standard target name.
8+
if(POLICY CMP0078)
9+
cmake_policy(SET CMP0078 NEW)
10+
endif()
11+
12+
# SWIG: use SWIG_MODULE_NAME property.
13+
if(POLICY CMP0086)
14+
cmake_policy(SET CMP0086 NEW)
15+
endif()
16+
17+
###############################################################################
18+
# Library for types defined in HelloWorld IDL
19+
###############################################################################
20+
21+
message(STATUS "Configuring python wrapper for types in HelloWorld...")
22+
23+
###############################################################################
24+
# Type library on C++
25+
26+
project(HelloWorld)
27+
28+
find_package(fastcdr REQUIRED)
29+
find_package(fastrtps REQUIRED)
30+
31+
32+
set(${PROJECT_NAME}_FILES
33+
HelloWorld.cxx
34+
HelloWorldPubSubTypes.cxx
35+
)
36+
37+
include_directories()
38+
39+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
40+
41+
#Create library for C++ types
42+
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_FILES})
43+
target_link_libraries(${PROJECT_NAME} PUBLIC fastcdr fastrtps)
44+
45+
###############################################################################
46+
# Python bindings for type
47+
48+
find_package(SWIG REQUIRED)
49+
include(${SWIG_USE_FILE})
50+
set(CMAKE_SWIG_FLAGS "")
51+
52+
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
53+
set(PYTHON_INCLUDE_PATH ${Python3_INCLUDE_DIRS})
54+
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
55+
set(PYTHON_LIBRARIES ${Python3_LIBRARY})
56+
57+
include_directories(${PYTHON_INCLUDE_PATH})
58+
59+
set(${PROJECT_NAME}_MODULE
60+
HelloWorldWrapper
61+
)
62+
63+
set(${PROJECT_NAME}_MODULE_FILES
64+
${PROJECT_NAME}.i
65+
)
66+
67+
SET_SOURCE_FILES_PROPERTIES(
68+
${${PROJECT_NAME}_MODULE_FILES}
69+
PROPERTIES CPLUSPLUS ON
70+
USE_TARGET_INCLUDE_DIRECTORIES TRUE
71+
)
72+
73+
include_directories(
74+
${PROJECT_SOURCE_DIR}
75+
)
76+
77+
SWIG_ADD_LIBRARY(${${PROJECT_NAME}_MODULE}
78+
TYPE SHARED
79+
LANGUAGE python
80+
SOURCES ${${PROJECT_NAME}_MODULE_FILES})
81+
82+
SWIG_LINK_LIBRARIES(${${PROJECT_NAME}_MODULE}
83+
${PYTHON_LIBRARIES}
84+
fastrtps
85+
${PROJECT_NAME}
86+
)
87+
88+
# Find the installation path
89+
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}' ) )"
90+
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
91+
OUTPUT_STRIP_TRAILING_WHITESPACE
92+
)
93+
get_filename_component (_ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE)
94+
file (RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH})
95+
SET (PYTHON_MODULE_PATH
96+
${_REL_PYTHON_MODULE_PATH}
97+
)
98+
99+
# Install
100+
install(TARGETS ${PROJECT_NAME}
101+
RUNTIME DESTINATION bin/
102+
LIBRARY DESTINATION lib/
103+
ARCHIVE DESTINATION lib/
104+
)
105+
install(TARGETS ${${PROJECT_NAME}_MODULE} DESTINATION ${PYTHON_MODULE_PATH})
106+
get_property(support_files TARGET ${${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES)
107+
install(FILES ${support_files} DESTINATION ${PYTHON_MODULE_PATH})
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ using namespace eprosima::fastcdr::exception;
3636

3737
HelloWorld::HelloWorld()
3838
{
39-
// m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@32eebfca
39+
// m_index com.eprosima.idl.parser.typecode.PrimitiveTypeCode@74a10858
4040
m_index = 0;
41-
// m_message com.eprosima.idl.parser.typecode.StringTypeCode@543c6f6d
41+
// m_message com.eprosima.idl.parser.typecode.StringTypeCode@23fe1d71
4242
m_message ="";
4343

4444
}
@@ -83,6 +83,19 @@ HelloWorld& HelloWorld::operator =(
8383
return *this;
8484
}
8585

86+
bool HelloWorld::operator ==(
87+
const HelloWorld& x) const
88+
{
89+
90+
return (m_index == x.m_index && m_message == x.m_message);
91+
}
92+
93+
bool HelloWorld::operator !=(
94+
const HelloWorld& x) const
95+
{
96+
return !(*this == x);
97+
}
98+
8699
size_t HelloWorld::getMaxCdrSerializedSize(
87100
size_t current_alignment)
88101
{
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* This file was generated by the tool gen.
2020
*/
2121

22-
#ifndef _HELLOWORLD_H_
23-
#define _HELLOWORLD_H_
22+
#ifndef _FAST_DDS_GENERATED_HELLOWORLD_H_
23+
#define _FAST_DDS_GENERATED_HELLOWORLD_H_
2424

2525

2626
#include <stdint.h>
@@ -107,6 +107,20 @@ class HelloWorld
107107
eProsima_user_DllExport HelloWorld& operator =(
108108
HelloWorld&& x);
109109

110+
/*!
111+
* @brief Comparison operator.
112+
* @param x HelloWorld object to compare.
113+
*/
114+
eProsima_user_DllExport bool operator ==(
115+
const HelloWorld& x) const;
116+
117+
/*!
118+
* @brief Comparison operator.
119+
* @param x HelloWorld object to compare.
120+
*/
121+
eProsima_user_DllExport bool operator !=(
122+
const HelloWorld& x) const;
123+
110124
/*!
111125
* @brief This function sets a value in member index
112126
* @param _index New value for member index
@@ -215,4 +229,4 @@ class HelloWorld
215229
std::string m_message;
216230
};
217231

218-
#endif // _HELLOWORLD_H_
232+
#endif // _FAST_DDS_GENERATED_HELLOWORLD_H_
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
%module HelloWorld
2323

2424
// SWIG helper modules
25-
%include "std_string.i"
2625
%include "typemaps.i"
26+
%include "std_string.i"
27+
%include "std_vector.i"
28+
%include "std_array.i"
29+
%include "std_map.i"
2730

2831
// Assignemt operators are ignored, as there is no such thing in Python.
2932
// Trying to export them issues a warning
@@ -33,20 +36,21 @@
3336

3437
typedef char int8_t;
3538
typedef short int16_t;
36-
typedef long int32_t;
37-
typedef long long int64_t;
39+
typedef int int32_t;
40+
typedef long int64_t;
3841

3942
typedef unsigned char uint8_t;
4043
typedef unsigned short uint16_t;
41-
typedef unsigned long uint32_t;
42-
typedef unsigned long long uint64_t;
44+
typedef unsigned int uint32_t;
45+
typedef unsigned long uint64_t;
4346

4447

45-
// Macro delcarations
48+
// Macro declarations
4649
// Any macro used on the Fast DDS header files will give an error if it is not redefined here
4750
#define RTPS_DllAPI
4851
#define eProsima_user_DllExport
4952

53+
5054
%{
5155
#include "HelloWorld.h"
5256
%}
@@ -61,9 +65,19 @@ typedef unsigned long long uint64_t;
6165

6266
// Overloaded getter methods shadow each other and are equivalent in python
6367
// Avoid a warning ignoring all but one
68+
%ignore HelloWorld::index(uint32_t&&);
69+
70+
// Overloaded getter methods shadow each other and are equivalent in python
71+
// Const accesors produced constant enums instead of arrays/dictionaries when used
72+
// We ignore them to prevent this
6473
%ignore HelloWorld::index();
6574
%rename("%s") HelloWorld::index() const;
6675

76+
%ignore HelloWorld::message(std::string&&);
77+
78+
// Overloaded getter methods shadow each other and are equivalent in python
79+
// Const accesors produced constant enums instead of arrays/dictionaries when used
80+
// We ignore them to prevent this
6781
%ignore HelloWorld::message();
6882
%rename("%s") HelloWorld::message() const;
6983

0 commit comments

Comments
 (0)