### Install Connext Python API Redistributable Wheel Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This command installs the previously built Connext Python API wheel file. It allows for easy distribution and installation of the API on target machines. ```shell $ pip install rti.connext--.whl ``` -------------------------------- ### Build and Install Connext Python API Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This command compiles the C++ code and installs the Connext Python API package using pip. It performs the final installation step after configuration. ```shell $ pip install . ``` -------------------------------- ### Subscribe to HelloWorld Messages with DataReader in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/hello.rst This example shows how to create a `DomainParticipant`, `Topic`, and `DataReader` to subscribe to `HelloWorld` messages. It uses `rti.asyncio` to asynchronously take and print received data from the topic. ```python # hello_subscriber.py import rti.connextdds as dds import rti.asyncio from hello import HelloWorld participant = dds.DomainParticipant(domain_id=0) topic = dds.Topic(participant, 'HelloWorld Topic', HelloWorld) reader = dds.DataReader(participant.implicit_subscriber, topic) async def print_data(): async for data in reader.take_data_async(): print(f"Received: {data}") rti.asyncio.run(print_data()) ``` -------------------------------- ### Verify Connext Python API Installation Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This snippet demonstrates how to verify the successful installation of the `rti.connextdds` module by importing it in a Python interpreter and accessing a `DomainParticipant` property. ```shell $ python ``` ```python >>> import rti.connextdds as dds >>> participant = dds.DomainParticipant(100) >>> participant.domain_id 100 ``` -------------------------------- ### Clone Connext Python API Repository Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This snippet shows how to clone the `connextdds-py` repository and navigate into its directory using Git commands. It's the first step for both simple and wheel-based installations. ```shell $ git clone https://github.com/rticommunity/connextdds-py.git $ cd connextdds-py ``` -------------------------------- ### Connext Python API configure.py Options Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This section details the command-line options available for the `configure.py` script, used to customize the build process of the Connext Python API. It includes short and long options, along with their descriptions. ```APIDOC configure.py options: -n NDDSHOME, --nddshome NDDSHOME: NDDSHOME directory. Defaults to NDDSHOME environment variable. -j JOBS, --jobs JOBS: Number of concurrent build jobs/processes -t, --tcp: Add the TCP transport plugin -m, --monitoring: Add the RTI Monitoring plugin -s, --secure: Add the RTI Security Plugins + openssl libraries -p PLUGIN, --plugin PLUGIN: Add a user-defined plugin. This option can be specified multiple times -o OPENSSL, --openssl OPENSSL: Location of openssl libraries (defaults to platform library location under NDDSHOME) -r DIR, --python-root DIR: Root directory of Python (prefers 3.x over 2.x if both are under root) -c FILE, --cmake-toolchain FILE: CMake toolchain file to use when cross compiling -d, --debug: Use debug libraries and build debug modules for connext-py -h, --help: Show help message and exit ``` -------------------------------- ### Publish HelloWorld Messages with DataWriter in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/hello.rst This code demonstrates how to create a `DomainParticipant`, `Topic`, and `DataWriter` to publish `HelloWorld` messages. It iteratively writes messages to the topic, pausing for one second between each write. ```python # hello_publisher.py import time import rti.connextdds as dds from hello import HelloWorld participant = dds.DomainParticipant(domain_id=0) topic = dds.Topic(participant, 'HelloWorld Topic', HelloWorld) writer = dds.DataWriter(participant.implicit_publisher, topic) for i in range(10): writer.write(HelloWorld(message=f'Hello World! #{i}')) time.sleep(1) ``` -------------------------------- ### Build Connext Python API Redistributable Wheel Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This command builds a redistributable wheel file for the Connext Python API, which can be used to install the API on other machines with compatible environments. ```shell $ pip wheel . ``` -------------------------------- ### Configure Connext Python API Build Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This command executes the `configure.py` script to prepare the Connext Python API for building. It allows specifying build options like the NDDSHOME directory and number of parallel jobs. ```shell $ python configure.py [options...] ``` ```shell $ python configure.py --nddshome /opt/rti_connext_dds-7.1.0 --jobs 4 x64Linux4gcc7.3.0 ``` -------------------------------- ### Install RTI Connext Python API Source: https://github.com/rticommunity/connextdds-py/blob/master/README.md Installs the RTI Connext Python API using pip, the Python package installer. This command fetches the pre-built package from PyPI, allowing users to integrate Connext DDS functionalities into their Python applications. ```Shell pip install rti.connext ``` -------------------------------- ### Define a Data Type for Connext DDS in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/hello.rst This snippet defines a simple `HelloWorld` data type using `rti.types.idl.struct`. This type will be used for publishing and subscribing messages in the Connext DDS system. ```python # hello.py import rti.types as idl @idl.struct class HelloWorld: message: str = "" ``` -------------------------------- ### Create DDS DomainParticipant with Custom QoS in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/participant.rst This example shows how to configure a DomainParticipant with a specific Quality of Service (QoS) policy. It modifies the database.shutdown_cleanup_period QoS setting before creating the participant, allowing fine-grained control over its behavior. ```python qos = dds.DomainParticipantQos() qos.database.shutdown_cleanup_period = dds.Duration.from_milliseconds(10) participant = dds.DomainParticipant(domain_id=0, qos=qos) ``` -------------------------------- ### Instantiate and Compare Python Dataclass Instances Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This example demonstrates how to instantiate the `Point` dataclass, access its members, and perform comparisons. It highlights the `dataclass` functionality provided by `@idl.struct`, including `__init__`, `__eq__`, and `copy.deepcopy()` support. ```python point1 = Point(x=1, y=2) point2 = Point(y=2) # x=0, y=2 point3 = Point() # x=0, y=0 print(point1) assert point1 != point2 point2.x = 1 assert point1 == point2 point4 = copy.deepcopy(point3) assert point4 == point3 ``` -------------------------------- ### Read Data Samples with Metadata from DataReader (take) in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/reader.rst This example illustrates reading data samples along with their associated metadata using the take() method. Each iteration yields a (data, info) tuple, where info provides details like validity and state changes. Similar to take_data(), this method also removes the samples from the reader. ```python for data, info in reader.take(): if info.valid: print(f"Data received: {data}") else: print(f"State changed: {info.state}") ``` -------------------------------- ### Pytest Commands for Connext DDS Python Tests Source: https://github.com/rticommunity/connextdds-py/blob/master/test/python/README.md This section provides essential shell commands for managing and executing tests within the Connext DDS Python project using the pytest framework. It covers installation, running all tests, and executing specific test files. ```Shell pip3 install pytest ``` ```Shell pytest ./test/python ``` ```Shell pytest ./test/python/NAME_OF_TEST_TO_RUN.py ``` -------------------------------- ### Uninstall Connext Python API Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/building.rst This command uninstalls the Connext Python API package using pip. The `-y` flag confirms the uninstallation without prompting. ```shell $ pip uninstall rti.connext -y ``` -------------------------------- ### Specifying Include Directories (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/distlog/CMakeLists.txt This section specifies the include directories required for compiling the `distlog` target. It ensures that the compiler can find necessary header files from Connext DDS installations and local source directories, resolving dependencies during the build process. ```CMake target_include_directories( distlog PRIVATE ${CONNEXTDDS_INCLUDE_DIRS} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../connextdds/include" ) ``` -------------------------------- ### Integrate Python IDL Types with XML Configuration and Write Data Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/xmlapp.rst This set of examples illustrates how to define custom data types directly in Python using the `@idl.struct` decorator. It then shows how to reference these Python-defined types within an XML configuration file. Finally, it demonstrates the necessary step of registering the Python type with DDS before loading the participant and writing native Python objects using the `DataWriter`. ```python @idl.struct class Point: x: int = 0 y: int = 0 ``` ```xml ``` ```python dds.DomainParticipant.register_idl_type(Point, "Point") qos_provider = dds.QosProvider("my_dds_system.xml") participant = qos_provider.create_participant_from_config("ExamplePublicationParticipant") ``` ```python writer = dds.DataWriter( participant.find_datawriter("ExamplePublisher::ExampleWriter") ) writer.write(Point(x=10, y=20)) ``` -------------------------------- ### Using IDL Mapped Unions in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This Python example demonstrates how to interact with a dataclass mapped from an IDL union. It shows how to instantiate the union, check its default state, select a different member by assigning to its case property, and handles the `ValueError` raised when accessing an unselected member. ```python sample = MyUnion() # By default the case with the lowest discriminator value (0 in this case) # is selected (unless a "default:" label is defined in IDL) assert sample.discriminator == 0 assert sample.value == "" assert sample.string_member == "" # Select a different member: sample.point_member = Point(1, 2) assert sample.discriminator == 2 assert sample.value == Point(1, 2) assert sample.point_member == Point(1, 2) # Attempting to access member that is not selected raises a ValueError: try: print(sample.string_member) except ValueError: ``` -------------------------------- ### Setting Target Properties for Pybind11 Module (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/distlog/CMakeLists.txt This configuration block sets various properties for the `distlog` target, including C++ visibility, output directories for different build configurations (debug/release), and runtime output directories. It also defines the installation RPATH and ensures proper Python module naming conventions (prefix/suffix). ```CMake set_target_properties( distlog PROPERTIES CXX_VISIBILITY_PRESET "default" LIBRARY_OUTPUT_DIRECTORY "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_RELEASE "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${RTI_LOGGING_DISTLOG_LIBRARY_OUTPUT_DIRECTORY}" INSTALL_RPATH "${DISTLOG_INSTALL_RPATH}" PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}" ) ``` -------------------------------- ### Manipulate DDS Sequences of Structures in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This example illustrates how to assign and retrieve sequences of structures within a `dds.DynamicData` instance using Python lists of dictionaries. It shows how to populate a sequence with structured data (e.g., 'Point' objects) and then retrieve the entire sequence as a list of dictionaries. ```python sample["path"] = [{"x": 1, "y": 2}, {"x": 3, "y": 4}] path = list(sample["path"]) ``` -------------------------------- ### Configure Build Properties for Connext DDS Python Module Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This section configures various build properties for the `connextdds` target. It sets C++ visibility, specifies output directories for libraries and runtimes (for both debug and release builds), and defines installation paths and Python module naming conventions. ```CMake set_target_properties( connextdds PROPERTIES CXX_VISIBILITY_PRESET "default" LIBRARY_OUTPUT_DIRECTORY "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_RELEASE "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${RTI_CONNEXTDDS_LIBRARY_OUTPUT_DIRECTORY}" INSTALL_NAME_DIR "@rpath" INSTALL_RPATH "${CONNEXTDDS_INSTALL_RPATH}" PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}" ) ``` -------------------------------- ### Append Platform-Specific Path to CMake Find Root (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This CMake command appends the 'RTI_PLATFORM_DIR' variable to the 'CMAKE_FIND_ROOT_PATH'. This ensures that CMake searches for libraries and packages within the specified RTI platform installation directory, which is crucial for resolving dependencies correctly in cross-platform builds. ```CMake list( APPEND CMAKE_FIND_ROOT_PATH ${RTI_PLATFORM_DIR} ) ``` -------------------------------- ### Configure Runtime Path for ConnextDDS Shared Library (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This section conditionally sets the 'CONNEXTDDS_INSTALL_RPATH' variable based on the operating system. For UNIX-like systems (excluding macOS), it uses '$ORIGIN', and for macOS, it uses '@loader_path'. This configuration ensures that the shared library can correctly locate its dependencies at runtime, regardless of its installation location. ```CMake if(UNIX AND NOT APPLE) set(CONNEXTDDS_INSTALL_RPATH "$ORIGIN") endif() if(APPLE) set(CONNEXTDDS_INSTALL_RPATH "@loader_path") endif() ``` -------------------------------- ### Generate Python Data Types from IDL using rtiddsgen Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This command uses the `rtiddsgen` tool to generate Python data types from an IDL file. The `-language python` flag specifies Python as the target language. The optional `-example universal` flag generates example publisher and subscriber scripts. ```bash rtiddsgen -language python MyTypes.idl [-example universal] ``` -------------------------------- ### Defining IDL Struct with Optional Members Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This IDL example defines a struct named `MyOptionals` that includes both a required member and an optional member. The `@optional` annotation is used to mark a member as optional, meaning it might not always be present in data samples. ```idl struct MyOptionals { double required_value; @optional double optional_value; }; ``` -------------------------------- ### Loan Value for Complex Nested Member Modification in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This example demonstrates using `sample.loan_value()` to obtain a temporary reference (a 'loan') to a complex nested member. This allows for efficient, multiple modifications to its sub-members without repeated lookups, ensuring data consistency within the `dds.DynamicData` object. ```python with sample.loan_value("location") as location: location.data["x"] = 11.5 location.data["y"] = 12.5 ``` -------------------------------- ### Load Participant and Write DynamicData from XML Configuration in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/xmlapp.rst This Python code demonstrates how to load a DomainParticipant and its associated entities from an XML configuration file using `QosProvider.create_participant_from_config`. It then shows how to retrieve a `DataWriter` for `DynamicData` types, create a sample, and write data, assuming the type was defined in XML. ```python qos_provider = dds.QosProvider("my_dds_system.xml") participant = qos_provider.create_participant_from_config( "ExampleParticipantLibrary::ExamplePublicationParticipant" ) ``` ```python writer = dds.DynamicData.DataWriter( participant.find_datawriter("ExamplePublisher::ExampleWriter") ) sample = writer.create_data() sample["x"] = 10 writer.write(sample) ``` -------------------------------- ### Define DDS Entities and Types in XML Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/xmlapp.rst This XML snippet illustrates a comprehensive DDS system definition. It includes the declaration of a `Foo` struct, a domain library with a topic, and two domain participants (one for publication and one for subscription) with their respective data writers and readers. This configuration can be loaded by the `QosProvider`. ```xml ``` -------------------------------- ### Create a DDS DataReader in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/reader.rst This code demonstrates the creation of a DataReader instance. A DataReader requires a Subscriber to own it and a Topic to specify the data type it will receive. Optional QoS parameters and listeners can also be configured during instantiation. ```python subscriber = dds.Subscriber(participant) reader = dds.DataReader(subscriber, topic) ``` -------------------------------- ### rti.connextdds Module API Reference Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/quick.rst Comprehensive list of core classes and types available in the `rti.connextdds` Python module, categorized for easy reference. This includes DDS entities, data types, Quality of Service (QoS) settings, various listeners, and condition types. ```APIDOC Module: rti.connextdds DDS Entities: - DomainParticipant - Publisher - Subscriber - Topic - ContentFilteredTopic - DataReader - DataWriter Data types: - User types - rti.types.builtin - DynamicData Quality of Service (QoS): - QosProvider - DomainParticipantQos - TopicQos - PublisherQos - SubscriberQos - DataReaderQos - DataWriterQos Listeners: - DomainParticipantListener - TopicListener - PublisherListener - SubscriberListener - DataReaderListener - DataWriterListener Conditions: - WaitSet - Condition - GuardCondition - StatusCondition - ReadCondition - QueryCondition ``` -------------------------------- ### rti.asyncio Module API Reference Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/rti.asyncio.rst Detailed API reference for the `rti.asyncio` module, including its purpose, dependencies, and the functions/methods it provides or enhances. ```APIDOC Module: rti.asyncio Description: This module provides asynchronous capabilities for the rti.connextdds library. Requirements: Python 3.7 or newer. Functionality: - Enhances rti.connextdds.DataReader: - take_async(): Asynchronous method for DataReader. - take_data_async(): Asynchronous method for DataReader. - Defines convenience function: - rti.asyncio.run(coroutine): Description: Synchronously runs the main asynchronous function. Similar to asyncio.run. Parameters: coroutine: The coroutine to be run. ``` -------------------------------- ### Create a DataWriter in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/writer.rst This snippet demonstrates how to instantiate a DataWriter for a specific Topic using a Publisher and a DomainParticipant in the `rti.connextdds` library. A Publisher owns and manages DataWriters. ```python publisher = dds.Publisher(participant) writer = dds.DataWriter(publisher, topic) ``` -------------------------------- ### Read Data Samples from DataReader (take_data) in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/reader.rst This snippet shows how to synchronously retrieve data samples from a DataReader using the take_data() method. take_data() removes the samples from the reader after they are accessed, ensuring they are not read again. The loop iterates through the collection of received samples. ```python for sample in reader.take_data(): print(sample) ``` -------------------------------- ### Create a Basic DDS DomainParticipant in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/participant.rst This snippet demonstrates how to instantiate a DomainParticipant object in RTI Connext DDS for a specified domain ID (e.g., domain 0). It imports the rti.connextdds module and creates a participant, which is essential for any DDS communication. ```python import rti.connextdds as dds participant = dds.DomainParticipant(domain_id=0) ``` -------------------------------- ### Dynamic Type Loading and Usage Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst Shows how to dynamically load type definitions from an XML file using `dds.QosProvider` and subsequently use these types to create `DynamicData.Topic` and `DynamicData` objects, allowing for flexible data manipulation and access to members. ```python import rti.connextdds as dds provider = dds.QosProvider("your_types.xml") my_type = provider.type("MyType") ``` ```python topic = dds.DynamicData.Topic(participant, "Example MyType", my_type) sample = dds.DynamicData(my_type) sample["x"] = 42 # assuming MyType has an int32 field ``` ```python # struct Point { ``` -------------------------------- ### Create a DDS Topic in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/topic.rst Demonstrates how to instantiate a Topic object in Python, associating it with a DomainParticipant, a name ('Car Position'), and a data type (Point). This Topic facilitates communication for data described by the Point type. ```python topic = dds.Topic(participant, "Car Position", Point) ``` -------------------------------- ### Publish Data with a DataWriter in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/writer.rst This snippet shows how to create a data sample (e.g., a Point object) and publish it using an existing DataWriter instance. The `write` method sends the data to the associated Topic. ```python data = Point(x=1, y=2) writer.write(data) ``` -------------------------------- ### Populating IDL Mapped Sequences in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This Python code demonstrates how to populate sequences within a dataclass that maps to an IDL structure. It shows appending elements to bounded sequences and assigning new lists to unbounded sequences, including using `dds.Uint32Seq` for efficiency. ```python my_sequences = MySequences() my_sequences.bounded_int64_seq.append(1) my_sequences.bounded_int64_seq.append(2) my_sequences.unbounded_uint32_seq = dds.Uint32Seq([33] * 5) my_sequences.unbounded_foo_seq = [Foo(a=x) for x in range(10)] ``` -------------------------------- ### Connext DDS Python Project CMake Build Configuration Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/CMakeLists.txt This CMake script defines the build process for the Connext DDS Python project. It ensures proper discovery of Connext DDS libraries and headers by manipulating `CMAKE_FIND_ROOT_PATH` and `CMAKE_MODULE_PATH`. It also handles platform-specific RPATH settings for dynamic library loading on Unix and macOS, and checks for C++ compiler standard support. Finally, it integrates various sub-modules like `connextdds`, `distlog`, and `request` into the main build. ```CMake cmake_minimum_required(VERSION 3.15) project(connext-py) include(CheckCXXCompilerFlag) file(TO_CMAKE_PATH ${CONNEXTDDS_DIR} CONNEXTDDS_DIR) if (Python_ROOT_DIR) file(TO_CMAKE_PATH ${Python_ROOT_DIR} Python_ROOT_DIR) endif() list(APPEND CMAKE_FIND_ROOT_PATH ${CONNEXTDDS_DIR} ${CONNEXTDDS_DIR}/bin ${CONNEXTDDS_DIR}/lib/$ENV{CONNEXTDDS_ARCH} ${CONNEXTDDS_DIR}/include/ndds) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../resources/cmake") if(UNIX AND NOT APPLE) set(CMAKE_SKIP_RPATH OFF) set(CMAKE_BUILD_RPATH_USE_ORIGIN ON) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) endif() if(APPLE) set(CMAKE_SKIP_RPATH OFF) set(CMAKE_BUILD_WITH_INSTALL_RPATH ON) endif() string(TOUPPER ${CMAKE_BUILD_TYPE} RTI_LIB_BUILD_TYPE) if(${RTI_LIB_BUILD_TYPE} STREQUAL "DEBUG") set(RTI_DEBUG_SUFFIX "d") endif() check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17) check_cxx_compiler_flag(-std=c++14 HAVE_FLAG_STD_CXX14) add_subdirectory(connextdds) add_subdirectory(distlog) add_subdirectory(request) ``` -------------------------------- ### Connext DDS Python Built-in Types: Definition and Usage Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst Provides the Python definitions for common built-in types (`String`, `KeyedString`, `Bytes`, `KeyedBytes`) available in `rti.types.builtin` and demonstrates how to import and use them in a DDS application to create topics and write data. ```python @idl.struct class String: value: str = "" @idl.struct(member_annotations={'key': [idl.key]}) class KeyedString: key: str = "" value: str = "" @idl.struct class Bytes: value: Sequence[idl.uint8] = field(default_factory=idl.array_factory(idl.uint8)) @idl.struct(member_annotations={'key': [idl.key]}) class KeyedBytes: key: str = "" value: Sequence[idl.uint8] = field(default_factory=idl.array_factory(idl.uint8)) ``` ```python import rti.connextdds as dds from rti.types.builtin import String participant = dds.DomainParticipant(domain_id=0) topic = dds.Topic(participant, "HelloWorld", String) writer = dds.DataWriter(participant, topic) writer.write(String("Hello World!")) ``` -------------------------------- ### Manage DDS DomainParticipant Lifetime with 'with' Statement in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/participant.rst This snippet illustrates the use of Python's 'with' statement to ensure proper resource management for a DomainParticipant. The participant is automatically closed and destroyed when exiting the 'with' block, preventing resource leaks and simplifying cleanup. ```python with dds.DomainParticipant(domain_id=0) as participant: print(participant.domain_id) # ... ``` -------------------------------- ### Define Source Files for Connext DDS Python Binding Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This snippet defines the list of C++ source files that are compiled to create the `connextdds` Python module. These files cover various aspects of the DDS API, including topics, subscriptions, publications, and domain-related functionalities. ```CMake "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/qos/TopicQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/AnyTopicListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/BuiltinTopicKey.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/SubscriptionBuiltinTopicData.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/Filter.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/TopicBuiltinTopicData.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/ParticipantBuiltinTopicData.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/PublicationBuiltinTopicData.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/AnyTopic.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/topic/TopicNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/qos/DataReaderQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/qos/QosNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/qos/SubscriberQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/status/StatusNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/status/DataState.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/cond/ReadCondition.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/cond/CondNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/cond/QueryCondition.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/GenerationCount.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/Query.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/CoherentAccess.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/PyIDataReader.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/SampleInfo.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/Subscriber.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/SubNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/Rank.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/SubscriberListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/AnyDataReaderListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/sub/AnyDataReader.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/qos/QosNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/qos/PublisherQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/qos/DataWriterQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/PubNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/Publisher.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/SuspendedPublication.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/PublisherListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/CoherentSet.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/AnyDataWriterListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/pub/AnyDataWriter.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/qos/DomainParticipantQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/qos/QosNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/qos/DomainParticipantFactoryQos.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/DomainNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/DomainParticipant.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/domain/DomainParticipantListener.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/dds/DDSNamespace.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/core_utils/core_utils.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/connextdds.cpp" ) ``` -------------------------------- ### Configure Compiler Warning Options for ConnextDDS in CMake Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This CMake snippet sets compiler warning options for the 'connextdds' target. For MSVC compilers, it applies the /W4 warning level. For other compilers (e.g., GCC, Clang), it enables a comprehensive set of warnings including -Wall, -Wempty-body, -Wignored-qualifiers, -Wmissing-field-initializers, -Wsign-compare, -Wtype-limits, -Wuninitialized, and -Wunused-parameter. ```CMake if(MSVC) target_compile_options(connextdds PRIVATE /W4) else() target_compile_options(connextdds PRIVATE -Wall -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-parameter) endif() ``` -------------------------------- ### Discovering Required Packages (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/distlog/CMakeLists.txt This snippet demonstrates how CMake's `find_package` command is used to locate essential external dependencies. It ensures that RTI Connext DDS, a compatible Python interpreter with development modules, and the pybind11 library are available for the build process. ```CMake find_package( RTIConnextDDS "7.1.0" REQUIRED COMPONENTS core distributed_logger ) find_package( Python${RTI_PYTHON_MAJOR_VERSION} "${RTI_PYTHON_MAJOR_VERSION}.${RTI_PYTHON_MINOR_VERSION}" EXACT REQUIRED COMPONENTS Interpreter Development.Module ) find_package( pybind11 REQUIRED ) ``` -------------------------------- ### RTI Connext DDS Python API Reference for DataReaders Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/reader.rst This section provides a structured overview of key classes and methods within the rti.connextdds module relevant to DataReaders and data subscription. It details constructors, data access methods, and notification mechanisms, including synchronous and asynchronous patterns. ```APIDOC Module: rti.connextdds Class: DataReader Description: Used by applications to access data received over DDS. Methods: read_data(): Description: Returns a collection of data samples of the Topic's type. Keeps data in the reader. Returns: collection of data samples take_data(): Description: Returns a collection of data samples of the Topic's type. Removes data from the reader. Returns: collection of data samples take(): Description: Returns a collection of (data, info) tuples. Removes data from the reader. Returns: collection of (data, info) tuples read(): Description: Returns a collection of (data, info) tuples. Keeps data in the reader. Returns: collection of (data, info) tuples select(): Description: Allows selecting which data to read. take_data_async(): Description: Asynchronous generator. Returns data as it is received. Requires rti.asyncio. Returns: async generator yielding data samples take_async(): Description: Asynchronous generator. Returns (data, info) as it is received. Requires rti.asyncio. Returns: async generator yielding (data, info) tuples Class: Subscriber Description: Owns and manages DataReaders. Class: ContentFilteredTopic Description: Used to define a content-based subscription with a filter on the data type. Class: StatusCondition Description: Represents a condition that becomes active when an entity's status changes. Properties: enable_statuses: Type: dds.StatusMask Description: Specifies which status changes to get notified about (e.g., dds.StatusMask.DATA_AVAILABLE). Methods: handler(callback_function): Description: Sets the callback function to be executed when the condition becomes active. Class: WaitSet Description: Allows waiting synchronously until one or more attached conditions trigger. Methods: dispatch(timeout: dds.Duration): Description: Executes the condition handlers when they become active. Waits up to 'timeout' duration. Class: DataReaderListener Description: Interface for receiving notifications of status updates, including new data. Recommended for lightweight processing. Class: DataReader.Topic Description: A special DataReader class for DynamicData DataReaders. ``` -------------------------------- ### Creating Python Sample with Optional Members Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This Python snippet shows how to instantiate a dataclass mapped from an IDL struct with optional members. It asserts that the required member has its default value and the optional member is initialized to `None`. ```python sample = MyOptionals() assert sample.required_value == 0.0 assert sample.optional_value is None ``` -------------------------------- ### Link Required Libraries to Pybind11 Module (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/request/CMakeLists.txt This section links all necessary libraries to the `_util_native` module. It includes external Connext DDS libraries, core Connext DDS, and specific runtime libraries found previously, along with pybind11's optimization libraries. ```CMake target_link_libraries( _util_native PRIVATE ${CONNEXTDDS_EXTERNAL_LIBS} connextdds ${rticonnextmsgcpp2_lib} ${nddscpp2_lib} ${nddsc_lib} ${nddscore_lib} pybind11::opt_size ) if (RTI_LINK_OPTIMIZATIONS_ON) target_link_libraries( _util_native PRIVATE pybind11::thin_lto ) endif() ``` -------------------------------- ### Apply Link-Time Optimization for Connext DDS Python Module Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This conditional block applies link-time optimization (LTO) to the `connextdds` target. If the `RTI_LINK_OPTIMIZATIONS_ON` flag is enabled, the `pybind11::thin_lto` library is linked, which can result in smaller and faster binaries. ```CMake if (RTI_LINK_OPTIMIZATIONS_ON) target_link_libraries( connextdds PRIVATE pybind11::thin_lto ) endif() ``` -------------------------------- ### Linking Dependencies to Pybind11 Module (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/distlog/CMakeLists.txt This section defines the libraries that the `distlog` target will link against. It includes external Connext DDS libraries, the core `connextdds` library, the specific libraries found earlier (rtidlc, nddscpp2, etc.), and pybind11's optimization libraries, ensuring all symbols are resolved. ```CMake target_link_libraries( distlog PRIVATE ${CONNEXTDDS_EXTERNAL_LIBS} connextdds ${rtidlc_lib} ${nddscpp2_lib} ${nddsc_lib} ${nddscore_lib} pybind11::opt_size ) if (RTI_LINK_OPTIMIZATIONS_ON) target_link_libraries( distlog PRIVATE pybind11::thin_lto ) endif() ``` -------------------------------- ### Obtaining and Using TypeSupport for Serialization Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst Explains how to retrieve the `TypeSupport` object for an `idl.struct`-decorated class and demonstrates its use for serializing Python objects to a buffer and deserializing them back, ensuring data integrity. ```python import rti.types as idl @idl.struct class Foo: ... foo_support = idl.get_type_support(Foo) ``` ```python foo = Foo() buffer = foo_support.serialize(foo) new_foo = foo_support.deserialize(buffer) assert foo == new_foo ``` -------------------------------- ### Link Connext DDS and Pybind11 Libraries Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This command links the `connextdds` target with external Connext DDS libraries (found previously) and specific Pybind11 components. These components are essential for the Python module's functionality, including core module definition, size optimization, and Windows-specific extras. ```CMake target_link_libraries( connextdds PRIVATE ${CONNEXTDDS_EXTERNAL_LIBS} ${nddscpp2_lib} ${nddsc_lib} ${nddscore_lib} pybind11::module pybind11::opt_size pybind11::windows_extras ) ``` -------------------------------- ### rti.types.builtin Module API Documentation Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/rti.types.rst Documents the `rti.types.builtin` submodule, which defines standard DDS built-in types. These types are designed for convenience in developing publisher and subscriber applications. ```APIDOC Module: rti.types.builtin Purpose: Defines DDS built-in types for convenient publisher/subscriber application development. Members: (Details not provided in source text, implied by automodule directive) ``` -------------------------------- ### Locate Required Development Packages (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/request/CMakeLists.txt This snippet uses `find_package` to locate necessary libraries and tools for building the project. It ensures that RTI Connext DDS, a specific Python version, and pybind11 are available before compilation. ```CMake find_package( RTIConnextDDS "7.1.0" REQUIRED COMPONENTS core messaging_api ) find_package( Python${RTI_PYTHON_MAJOR_VERSION} "${RTI_PYTHON_MAJOR_VERSION}.${RTI_PYTHON_MINOR_VERSION}" EXACT REQUIRED COMPONENTS Interpreter Development.Module ) find_package( pybind11 REQUIRED ) ``` -------------------------------- ### Loan Value for Sequence Elements with Resizing in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst This snippet demonstrates using `loan_value` to efficiently modify elements within a DDS sequence, including automatic resizing when accessing indices beyond the current length. It shows how to loan the sequence, then loan an element within it to set its members, and finally print a specific element. ```python with sample.loan_value("path") as path: with path.data.loan_value(2) as point: point.data["x"] = 111 point.data["y"] = 222 print(sample["path[2].x"]) ``` -------------------------------- ### Configure Runtime Path (RPATH) for Libraries (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/request/CMakeLists.txt These conditional statements set the `REQUEST_INSTALL_RPATH` variable based on the operating system (UNIX or Apple). This ensures that the dynamic linker can find the necessary shared libraries at runtime, relative to the executable or module. ```CMake list( APPEND CMAKE_FIND_ROOT_PATH ${RTI_PLATFORM_DIR} ) if(UNIX AND NOT APPLE) set(REQUEST_INSTALL_RPATH "$ORIGIN:$ORIGIN/..") endif() if(APPLE) set(REQUEST_INSTALL_RPATH "@loader_path;@loader_path/..") endif() ``` -------------------------------- ### Specify Include Directories for Connext DDS Python Module Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/connextdds/CMakeLists.txt This command specifies the private include directories required for compiling the `connextdds` target. It includes general Connext DDS header paths (`CONNEXTDDS_INCLUDE_DIRS`) and source-specific headers located within the current source directory. ```CMake target_include_directories( connextdds PRIVATE "${CONNEXTDDS_INCLUDE_DIRS}" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include" ) ``` -------------------------------- ### IDL Module to Python Package Mapping and Access Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/types.rst Illustrates how IDL files generate Python packages, how IDL modules defined across multiple files map to Python packages, and how to access types within these packages, including partial module definitions and aliasing for convenience. ```python import Foo my_type = Foo.MyType() ``` ```idl # Foo.idl module A { struct MyType1 { ... }; }; struct MyType2 { ... }; ``` ```idl # Bar.idl module A { struct MyType3 { ... }; }; module B { struct MyType4 { ... }; }; ``` ```python import Foo import Bar sample1 = Foo.A.MyType1() sample2 = Foo.MyType2() sample3 = Bar.A.MyType3() sample4 = Bar.B.MyType4() # You can create an alias: MyType3 = Bar.A.MyType3 sample3 = MyType3() ``` -------------------------------- ### Set Build Properties for Pybind11 Module (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/request/CMakeLists.txt This snippet configures various build properties for the `_util_native` module. It sets visibility, output directories for different build types (debug/release), runtime path, and Python module specific prefixes/suffixes. ```CMake set_target_properties( _util_native PROPERTIES CXX_VISIBILITY_PRESET "default" LIBRARY_OUTPUT_DIRECTORY "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" LIBRARY_OUTPUT_DIRECTORY_RELEASE "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" RUNTIME_OUTPUT_DIRECTORY_RELEASE "${RTI_REQUEST__UTIL_NATIVE_LIBRARY_OUTPUT_DIRECTORY}" INSTALL_RPATH "${REQUEST_INSTALL_RPATH}" PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}" ) ``` -------------------------------- ### Configuring Runtime Path (RPATH) for Libraries (CMake) Source: https://github.com/rticommunity/connextdds-py/blob/master/modules/distlog/CMakeLists.txt This section configures the runtime search path (RPATH) for shared libraries, which is crucial for the executable or module to find its dependencies at runtime. It sets platform-specific RPATH values for UNIX-like systems (excluding macOS) and macOS, ensuring portability. ```CMake list( APPEND CMAKE_FIND_ROOT_PATH ${RTI_PLATFORM_DIR} ) if(UNIX AND NOT APPLE) set(DISTLOG_INSTALL_RPATH "$ORIGIN:$ORIGIN/..") endif() if(APPLE) set(DISTLOG_INSTALL_RPATH "@loader_path;@loader_path/..") endif() ``` -------------------------------- ### Synchronous Data Availability Notification using WaitSet in Python Source: https://github.com/rticommunity/connextdds-py/blob/master/docs/source/reader.rst This code demonstrates a synchronous approach to being notified when data is available using a WaitSet and StatusCondition. It configures a StatusCondition on the DataReader to trigger on DATA_AVAILABLE status, attaching a handler function. The WaitSet then dispatches these handlers when conditions become active, allowing the application to process data without continuous polling. ```python def process_data(_): nonlocal reader for sample in reader.take_data(): print(sample) # Each Entity has a StatusCondition status_condition = dds.StatusCondition(reader) # Specify which status to get notified about and set the handler: status_condition.enable_statuses = dds.StatusMask.DATA_AVAILABLE status_condition.handler(process_data) # Attach the condition to a waitset and call dispatch() to execute the # condition handlers when they become active waitset = dds.WaitSet() waitset += status_condition while True: waitset.dispatch(dds.Duration(4)) # Wait up to 4 seconds ```