How to define DDS applications in XML.
How to define DDS applications in XML.
Sections:
Example XML definition
The following is the configuration (ddsApplication.xml
) that we will be using in the examples in this section:
<?xml version="1.0" encoding="UTF-8"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://community.rti.com/schema/current/rti_dds_profiles.xsd">
<types>
<struct name="Shape">
<member name="color" stringMaxLength="128" type="string" key="true"/>
<member name="x" type="int32"/>
<member name="y" type="int32"/>
<member name="shapesize" type="int32"/>
</struct>
</types>
<domain_library name="ExampleDomainLibrary">
<domain name="ExampleDomain" domain_id="0">
<register_type name="Shape" type_ref="Shape"/>
<register_type name="MyType"/>
<topic name="Square" register_type_ref="Shape"/>
<topic name="MyTypeTopic" register_type_ref="MyType"/>
</domain>
</domain_library>
<domain_participant_library name="ExampleParticipantLibrary">
<domain_participant name="ExamplePublicationParticipant"
domain_ref="ExampleDomainLibrary::ExampleDomain">
<publisher name="ExamplePublisher">
<data_writer name="ShapeWriter" topic_ref="Square"/>
</publisher>
</domain_participant>
<domain_participant name="ExampleSubscriptionParticipant"
domain_ref="ExampleDomainLibrary::ExampleDomain">
<data_reader name="ShapeReader" topic_ref="Square">
<content_filter name="ExampleTopic" kind="builtin.sql">
<expression>color='BLUE'</expression>
</content_filter>
</data_reader>
</domain_participant>
<domain_participant name="ExampleIdlParticipant"
domain_ref="ExampleDomainLibrary::ExampleDomain">
<publisher name="ExamplePublisher">
<data_writer name="MyTypeWriter" topic_ref="MyTypeTopic"/>
</publisher>
</domain_participant>
</domain_participant_library>
</dds>
Creating and looking up the DDS entities
Example: Create the participants defined in the XML file
"ExampleParticipantLibrary::ExamplePublicationParticipant");
using var subParticipant = provider.CreateParticipantFromConfig(
"ExampleParticipantLibrary::ExampleSubscriptionParticipant");
Provides access to XML-defined QoS profiles, data types, and complete DDS systems.
Definition: QosProvider.cs:151
DomainParticipant CreateParticipantFromConfig(string configName)
Creates a DomainParticipant given its configuration name from a description provided in an XML config...
Contains infrastructure types.
Definition: AsyncWaitSetProperty.cs:18
Contains the RTI Connext DDS C# API.
Definition: AsyncWaitSetProperty.cs:18
Contains the RTI Connext C# API.
Definition: Logger.cs:20
Example: lookup the DataWriter and publish data
var writer = pubParticipant.LookupDataWriter<DynamicData>(
"ExamplePublisher::ShapeWriter");
DynamicData data = writer.CreateData();
data.SetValue("color", "RED");
data.SetValue("shapesize", 70);
data.SetValue("x", 10);
data.SetValue("y", -10);
writer.Write(data);
Example: lookup the DataReader and receive data
var reader = subParticipant.LookupDataReader<DynamicData>("ShapeReader");
reader.DataAvailable += _ =>
{
using var samples = reader.Take();
foreach (var sample in samples.ValidData())
{
Console.WriteLine(sample);
}
};
Using IDL-based types
The previous examples used DynamicData, but it is also possible to use strongly typed C# classes generated from IDL even if the readers and writers are defined in XML.
Example: Register an IDL type used by a writer or reader defined in XML
DomainParticipantFactory.Instance.RegisterTypeSupport<
Example.
MyType>(
name: "MyType");
DomainParticipantFactory.Instance.RegisterNamespace(
"Example");
var provider = new QosProvider("ddsApplication.xml");
using var participant = provider.CreateParticipantFromConfig(
"ExampleParticipantLibrary::ExampleIdlParticipant");
"ExamplePublisher::MyTypeWriter");
writer.Write(sample);
Console.WriteLine(writer.Topic.TypeName);
Example C# class generated from the IDL struct MyType
Definition: MyType.cs:135