Expand description
§RTI Connector for Rust example for Shape types
This example demonstrates how to use the RTI Connector for Rust to publish and subscribe to Shape data types in a DDS domain.
§Usage
It uses a command-line interface to allow users to choose between publishing and subscribing modes, as well as configure parameters such as the number of samples and timeouts.
> cargo run -q --example shapes -- --help
RTI Connector for Rust example for Shape data
Usage: shapes [OPTIONS] <COMMAND>
Commands:
pub Publish shape data to DDS
sub Subscribe to shape data from DDS
help Print this message or the help of the given subcommand(s)
Options:
--typed Enable typed mode for shapes
-h, --help Print help§Publisher Command
Publishes samples of ShapeType data at specified intervals
It can be invoked from the command line as follows:
> cargo run -q --example shapes -- pub --help
Publish shape data to DDS
Usage: shapes pub [OPTIONS]
Options:
-s, --samples <SAMPLES>
Total number of samples to publish [default: unlimited]
-w, --wait-ms <WAIT_MS>
Sleep duration between samples in milliseconds (0 = no wait) [default: 200]
-d, --wait-for-subscriptions-ms <WAIT_FOR_SUBSCRIPTIONS_MS>
Wait for subscriptions timeout in milliseconds (0 = infinite) [default: 3000]
-h, --help
Print help§Subscriber Command
Subscribes to samples of ShapeType data and prints
them to the console
It can be invoked from the command line as follows:
> cargo run -q --example shapes -- sub --help
Subscribe to shape data from DDS
Usage: shapes sub [OPTIONS]
Options:
-s, --samples <SAMPLES>
Total number of samples to read [default: unlimited]
-w, --wait-ms <WAIT_MS>
Wait timeout in milliseconds (0 = infinite) [default: 500]
-d, --wait-for-publications-ms <WAIT_FOR_PUBLICATIONS_MS>
Wait for publications timeout in milliseconds (0 = infinite) [default: 3000]
-h, --help
Print help§XML Configuration
The example uses an XML configuration file (Shapes.xml) with the following content:
<?xml version="1.0"?>
<!--
(c) 2005-2015 Copyright, Real-Time Innovations, Inc. All rights reserved.
RTI grants Licensee a license to use, modify, compile, and create derivative
works of the Software. Licensee has the right to distribute object form only
for use with RTI products. The Software is provided "as is", with no warranty
of any type, including any warranty for fitness for any purpose. RTI is under
no obligation to maintain or support the Software. RTI shall not be liable for
any incidental or consequential damages arising out of the use or inability to
use the software.
-->
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/7.3.0/rti_dds_profiles.xsd"
version="7.3.0">
<!-- Qos Library -->
<qos_library name="QosLibrary">
<qos_profile name="ShapeProfile"
base_name="BuiltinQosLibExp::Generic.BestEffort"
is_default_qos="true">
<participant_qos>
<!-- Turn on monitoring -->
<!-- Begin Monitoring
<property>
<value>
<element>
<name>rti.monitor.library</name>
<value>rtimonitoring</value>
</element>
<element>
<name>rti.monitor.create_function_ptr</name>
<value>$(NDDS_MONITOR)</value>
</element>
</value>
</property>
End Monitoring -->
</participant_qos>
</qos_profile>
</qos_library>
<!-- types -->
<types>
<struct name="ShapeType" extensibility="extensible">
<member name="color" stringMaxLength="128" id="0" type="string" key="true" />
<member name="x" id="1" type="long" />
<member name="y" id="2" type="long" />
<member name="shapesize" id="3" type="long" />
</struct>
<enum name="ShapeFillKind" extensibility="extensible">
<enumerator name="SOLID_FILL" value="0" />
<enumerator name="TRANSPARENT_FILL" value="1" />
<enumerator name="HORIZONTAL_HATCH_FILL" value="2" />
<enumerator name="VERTICAL_HATCH_FILL" value="3" />
</enum>
<struct name="ShapeTypeExtended" baseType="ShapeType" extensibility="extensible">
<member name="fillKind" id="4" type="nonBasic" nonBasicTypeName="ShapeFillKind" />
<member name="angle" id="5" type="float" />
</struct>
</types>
<!-- Domain Library -->
<domain_library name="ShapeDomainLibrary">
<domain name="ShapeDomain" domain_id="0">
<register_type name="ShapeType" type_ref="ShapeType" />
<topic name="Square" register_type_ref="ShapeType" />
</domain>
</domain_library>
<!-- Participant library -->
<domain_participant_library name="ShapeParticipantLibrary">
<domain_participant name="Zero" domain_ref="ShapeDomainLibrary::ShapeDomain">
<publisher name="ShapePublisher">
<data_writer name="ShapeSquareWriter" topic_ref="Square" />
</publisher>
<subscriber name="ShapeSubscriber">
<data_reader name="ShapeSquareReader" topic_ref="Square" />
</subscriber>
</domain_participant>
<domain_participant name="Pub" domain_ref="ShapeDomainLibrary::ShapeDomain">
<publisher name="ShapePublisher">
<data_writer name="ShapeSquareWriter" topic_ref="Square" />
</publisher>
</domain_participant>
<domain_participant name="Sub" domain_ref="ShapeDomainLibrary::ShapeDomain">
<subscriber name="ShapeSubscriber">
<data_reader name="ShapeSquareReader" topic_ref="Square" />
</subscriber>
</domain_participant>
</domain_participant_library>
</dds>Structs§
- Shape
Type - Structure matching the ShapeType DDS data model.
Enums§
- Typed
Mode - Indicates whether typed serialization is enabled or disabled