Home
XML-Based Application Creation Getting Started Guide
Contents
1. Hello World using XML and Compiled Types 2 2 2 2 2 3 Generate Type Support Code from the Type Definition This step produces code to support the direct use of the structure HelloWorld from application code The code is generated using the provided tool named rtiddsgen The code generation supports many programming languages The XML Based Application Cre ation currently supports C C Java and C We will use C in this example To generate code follow these steps replacing lt architecture gt as needed for your system e g i86Win32VS2008 or i86Linux2 6gcc4 4 5 On a Windows system From your command shell change directory to lt installation directory gt exam ple CPP HelloWorld_xml_compiled and type rtiddsgen language C example lt architecture gt HelloWorld xml On a UNIX based system From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_dynamic and type rtiddsgen language C example lt architecture gt HelloWorld xml As a result of this step you will see the following files appear in the directory HelloWorld_xml_dynamic HelloWorld h HelloWorld cxx HelloWorldPlugin h HelloWorld Plugin cxx HelloWorldSupport h and HelloWorldSupport cxx The most notable thing at this point is the fact that the HelloWorld h file contains the declara tion of the C structure built according to the specification in the XML file static const DDS Long MA
2. Table 4 12 lt domain_participant gt lt domain_participant gt lt subscriber gt lt datawriter_qos gt The lt publisher gt tag defines by default a Publisher It may contain a QoS configuration and a sev eral DataWriters Likewise the lt subscriber gt tag defines by default a Subscriber It may contain a QoS configuration and a several DataReaders Publisher Tag Tags within Des rivti n Number of lt publisher gt P Tags Allowed p Specifies a DataWriter configuration Same as within the lt data_writer gt a 0 or more lt participant gt tag lt publisher_qos gt Publisher QoS configuration Oor1 Subscriber Tag Tags within Description Number of lt subscriber gt P Tags Allowed Specifies a DataReader configuration Same as within the lt data_reader gt as 0 or more lt participant gt tag lt subscriber_qos gt Subscriber QoS configuration Oorl DataWriter Tag Tags within Description Number of lt data_writer gt P Tags Allowed lt datawriter_qos gt DataWriter QoS configuration Oorl DataReader Tags Tags within Description Number of lt data_reader gt P Tags Allowed lt datareader_qos gt DataReader QoS configuration 0 or more 4 10 XML Tags for Configuring Entities Table 4 12 DataReader Tags Number of Tags Allowed Tags within lt data_reader gt Description Enables the creation o
3. DefaultProfile gt lt qos_profile gt lt qos_library gt lt Domain Library gt lt domain library name MyDomainLibrary gt lt domain name HelloWorldDomain domain_id 0 gt lt register_type name HelloWorldType kind userGenerated gt lt topic name HelloWorldTopic register type ref HelloWorldType gt lt topic_qos name HelloWorld_gos base_name qgosLibrary DefaultProfile gt lt topic gt lt domain gt lt domain_library gt lt Participant library gt lt participant library name MyParticipantLibrary gt lt domain participant name PublicationParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt publisher name MyPublisher gt lt data_writer name HelloWorldWriter topic _ref HelloWorldTopic gt lt publisher gt lt domain_participant gt lt domain participant name SubscriptionParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt subscriber name MySubscriber gt lt data_reader name HelloWorldReader topic_ref HelloWorldTopic gt lt datareader_qos name HelloWorld_reader_qos base_name qgosLibrary DefaultProfile gt lt data_reader gt lt subscriber gt lt domain_participant gt lt participant_library gt lt dds gt The examination of this file reveals virtually the same information as was found in the HelloWorld_xml_dynamic example This is no surprise as we are essentially trying to define the same system Please revisit
4. Examine the XML Configuration Files Definition Section 2 1 3 for a 2 13 Hello World using XML and Compiled Types 2 2 6 description of what each section in the XML does Here we highlight the only two differences that can be seeing in the configuration file for the of the HelloWorld_xml_compiled example when compared with that of the HelloWorld_xml_dynamic example L The type definition lt types gt section does not appear in the configuration of the HelloWorld_xml_compiled example l The registration of the data types within the domain is slightly different The type definition section that appears between the tags lt types gt and lt types gt is not there because in this case the data types are compiled in So the type definition has been moved to an external file to facilitate the code generation described in Section Generate Type Support Code from the Type Definition Section 2 2 2 The registration of the data type inside the domain uses the syntax lt register type name HelloWorldType kind userGenerated gt This contrasts with what was used in the HelloWorld_xml_dynamic example lt register_ type name HelloWorldType kind dynamicData type ref HelloWorld gt The modified syntax indicates a kind userGenerated which means that the type will be defined via code generation and not use the DynamicData API Since the type is defined via code generation there is no need to provide a
5. Started Guide which is part ae distribution or you can find it online at http community rti com content page documentation with the XML configuration can also be done with the underlying APIs In this manner an application can be initially developed using XML Based Application Creation and transitioned to the traditional API at a later time This would be useful in case the application has to be deployed on a platform without a file system or needs to be ported to a DDS compliant library that does not support XML based configuration such as RTI Connext Micro Using XML Based Application Creation is easy simply edit USER_QOS_PROFILE xml to define L The data types that will be used to communicate information in the system I The Topics that will be used in the domain associating each Topic with a data type I The DomainParticipants that can potentially be used giving each a participant name LJ The DataWriters and DataReaders present within each DomainParticipant each associated with its corresponding Topic The application code simply indicates the participant configuration name of the DomainPartici pant that the application wants to create The XML Based Application Creation infrastructure takes care of the rest creating the DomainParticipant registering the types and Topics and popu lating all the configured Entities 1 1 When the application needs to read or write data register listeners or perform any other
6. To start the subscribing application on a Windows system From your command shell go to lt installation directory gt exam ple CPP HelloWorld_xml_dynamic and type gt objs lt architecture gt HelloWorld_subscriber exe where lt architecture gt is the architecture you just built look in the objs directory to see the name of the architecture you built For example the Windows architecture name corre sponding to 32 bit Visual Studio 2008 is i86Win32VS2008 To start the subscribing application on a UNIX based systems From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_dynamic and type gt objs lt architecture gt HelloWorld subscriber where lt architecture gt is the architecture you just built look in the objs directory to see the name of the architecture you built For example i86Linux2 6gcc4 4 5 You should immediately see some messages from the publishing application showing that it is writing data and messages from the subscribing application showing the data it receives Do not 2 2 Hello World using XML and Dynamic Data 2 1 3 worry about the contents of the messages They are generated automatically for this example The important thing is to understand how the application is defined which will be explained in the following sections Examine the XML Configuration Files Definition A Connext application is defined in the file USER_QOS_PROFILES xml found
7. Topic Tag Table 4 6 describes a Topic by specifying the name and type of the Topic It may also contain the QoS configuration for that Topic lt domain gt 4 6 XML Tags for Configuring Entities Table 4 6 Topic Tag Tags within lt topic gt Description Number of tags allowed lt registered_name gt Name of the Topic Oorl lt topic_qos gt Topic QoS configuration Oorl Some elements may refer to already specified types and QoS tags The definitions of these refer enced tags may appear either in the same configuration file or in a different one as long as it is one of the ones loaded by Connext as described in Section 4 2 If a QoS is not specified for an Entity then the QoS will be set to a default value that is either the default configured in the XML files or if such default does not exist then the Connext QoS defaults Please see Chapter 15 Configuring QoS with XML in the RTI Core Libraries and Utili ties User s Manual for additional details in configuring QoS via XML For example lt types gt lt types gt lt struct name MyType gt lt member name message type string gt lt member name count type long gt lt struct gt lt types gt lt Domain Library gt lt domain library name MyDomainLibrary gt lt domain name MyDomain domain_id 10 gt lt register type name MyRegisteredType kind dynamicData type _ref MyType gt
8. XML and Compiled Types 2 2 2 2 1 The extra XML within the lt filter gt tag adds a SQL content filter which only accepts samples with the field count greater than two Now run HelloWorld_subscriber without recompiling and check the expected that the behav ior Hello World using XML and Compiled Types The files for this example are located in the directory lt installation directory gt example CPP HelloWorld_xml_compiled This simple scenario consists of two applications identical in pur pose to the one illustrated in Figure2 1 Hello World Domain on page 2 1 HelloWorld_publisher exe which writes to the Topic HelloWorldTopic and HelloWorld_subscriber exe which subscribes to that same Topic In contrast with previous example which uses the DynamicData API this example uses com piled types Compiled types are syntactically nicer to use from application code and provide better perfor mance The drawback is that there is an extra step of code generation involved to create that supporting infrastructure to marshal and unmarshal the types into a format suitable for network communications Define the Data Types using IDL or XML The first step is to describe the data type in a programming language neutral manner Two lan guages are supported by the Connext tools XML and IDL These languages XML and IDL pro vide equivalent type definition capabilities so you can choose either one depending on your personal
9. action it simply looks up the appropriate Entity by name and uses it XML Based Application Creation enables several powerful new work flows L Developers can describe all the Entities that a Connext application will need in an XML file and then create that application with a single function call saving many hundreds of lines of setup code L Application descriptions written in XML are usable from all programming languages I The complete domain including the data types and Topics that can be in the domain may be defined in an XML file and shared amongst all the developers and applications I The Quality of Service QoS that should be used for each DomainParticipant Topic DataReader and DataWriter can be fully specified in the XML and shared amongst a group of developers and applications I The XML description of the application can be used in combination with RTI Prototyper to design and prototype application deployment scenarios allowing quick testing and vali dation without the need for programming To use the companion RTI Connext Prototyper see Chapter 3 1 2 Chapter 2 A Hello World Example 2 1 Figure 2 1 This chapter assumes that you have installed the RTI Connext Core Libraries and Utilities and con figured your environment correctly If you have not done so please follow the steps in the RTI Core Libraries and Utilities Getting Started Guide specifically Chapter 2 Installing RTI Connext and Se
10. be assigned as follows Participant Name N configuration_name 0 configuration_name N 1 N 1 For example if we create three participants from the configuration lib participant the names assigned as the participants are created will be l participant L participant 1 L participant 2 Once a participant is created it can be retrieved by its name at any other place in your program as follows based on the previous example and assuming that only one participant was created participant DDSTheParticipantFactory gt lookup_participant_by_name MyParticipant if participant NULL handle error To provide more flexibility create_participant_from_config_w_params allows you to specify the participant name You can also override the specification in the configuration for the domain ID and QoS profile for the participant and entites in the domain 4 7 2 Creating and Retrieving Publishers and Subscribers Publishers and Subscribers configured in XML are created automatically when a DomainPartici pant is created from the lt domain_participant gt that contains the lt publisher gt and lt subscriber gt configurations Given the following example lt domain participant name MyParticipant domain_ref MyDomainLibrary MyDomain gt lt publisher name MyPublisher multiplicity 2 gt lt publisher gt lt subscriber name MySubscriber gt lt subscriber gt lt dom
11. call can create hundreds of Entities both DataReaders and DataWriters Use of the Entities The remaining part of the function uses the entities that were created to per form the logic of the program This example only needs to read data using the single DataReader So the application looks up the HelloWorldReader DataReader using the fully qualified name MySubscriber HelloWorldReader and narrows it to be a DynamicDataReader DDSDynamicDataReader dynamicReader DDSDynamicDataReader narrow participant gt lookup datareader by name MySubscriber HelloWorldReader To process the data the application installs a Listener on the DataReader The HelloWorldLis tener defined on the same file implements the DataReaderListener interface which the DataReader uses to notify the application of relevant events such as the reception of data 2 8 Hello World using XML and Dynamic Data Create a DataReaderListener HelloWorldListener reader listener new HelloWorldListener set listener retcode dynamicReader gt set_listener reader listener DDS_DATA AVAILABLE STATUS The last part is the implementation of the listener functions In this case we only implement the on_data_available operation which is the one called when data is received The on_data_available function receives all the data into a sequence and then uses the DDS_DynamicData print function to print each data item received voi
12. data can be shared by means of reading and writing the same Topics each Topic having an associated data type Therefore in a lt domain gt tag you can specify Topics and their data types Figure 4 3 Table 4 3 and Table 4 4 describe what tags can be in a lt domain_library gt L The lt register_type gt tag specifies a type definition that will be registered in the DomainParticipants whenever they spec ify a Topic associated with that data type L The lt topic gt tag specifies a Topic by asso ciating it with a lt register_type gt that contains the type information Figure 4 3 Domain Library Tag In a domain you can also specify the domain ID to which the DomainParticipant associated with this domain will be bound Domain Library Tags Tags within Description Number of lt domain_library gt tags allowed Specifies a domain Attributes name Domain name lt domain gt domain_id optional Domain ID default id 0 1 or more Base domain name base_name optional another domain from which prop erties will be inherited Specifies Note that a domain may inherit from another base domain definition by using the base_name attribute A domain that declares a base domain might still override some of the properties in the base domain Overriding is done simply by including elements in the derived domain with the same name as in the base domain 4 5 XML Tags
13. for Configuring Entities Table 4 4 Table 4 5 Domain Tags Tags within Descripti Dead lt domains escription of tags allowed Specifies how a type is registered Attributes Name used to refer to this registered type within the XML file This is also the name name under which the type is registered with the i DomainParticipants unless overridden by the 1 lt register_type gt lt registered_name gt tag li Specifies whether the type is built in dynamic kind data or generated by the user Reference fully qualified name to a defined type_ref optional type within lt types gt Required when kind is dynamic data Specifies a topic associating its data type and optionally QoS Attributes Name of the topic if no lt registered_name gt is name ified lt topic gt sl lanl 1 or more register_type_ref Reference name to a register_type within this domain with which this topic is associated The lt register_type gt tag described in Figure 4 4 and Table 4 5 determines how a type is registered by specifying the type definition and the name with lt domain gt which it is registered Figure 4 4 Register Type Tag lt register_type gt Register Type Tag Tags wale Description Number of tags allowed lt register_type gt lt registered_name gt Name with which the type is registered Oorl The lt topic gt tag described in Figure4 5 and Figure 4 5
14. lt topic name MyTopic register type ref MyType gt lt topic_qos base _name qosLibrary DefaultProfile gt lt topic gt lt domain gt lt domain_library gt The above configuration defines a domain with name MyDomain and domain_id 10 con taining a Topic called MyTopic with type MyType registered with the name MyRegistered Type LI lt register_type gt It defines the registration of a dynamic data type with name MyRegis teredType and definition MyType defined in the same file LI lt topic gt with name MyTopic and whose corresponding type is the one defined above with the name MyRegisteredType found within the same configuration The Topic QoS configuration is the one defined by the profile qosLibrary Default Profile which is defined in a different file Note that the DomainParticipant created from a configuration profile bound this domain will be crated with domain_id 10 unless the domain_id is overridden in the participant configuration 4 7 XML Tags for Configuring Entities 4 5 2 Table 4 7 Participant Library A participant library provides a way to orga Figure 4 6 Participant Library Tag nize a set of participants belonging to the same system A participant configuration specifies all the entities that a DomainParticipant created from this configuration will contain Figure 4 6 Table 4 7 and Table 4 8 shows the description of a lt pa
15. rtiddsprototyper cfgName PublicationParticipant MyParticipantLibrary PublicationParticipant In the other window type all on one line SNDDSHOME scripts rtiddsprototyper cfgName SubscriptionParticipant MyParticipantLibrary SubscriptionParticipant On a UNIX based system From your command shel go to lt installation directory gt example CPP HelloWorld_xml_dynamic Open two console windows In one window type all on one line NDDSHOME scripts rtiddsprototyper cfgName PublicationParticipant MyParticipantLibrary PublicationParticipant In the other window type all on one line NDDSHOME scripts rtiddsprototyper cfgName SubscriptionParticipant MyParticipantLibrary SubscriptionParticipant You can run both of these on the same computer or on separate computers within the same multicast enabled network You should immediately see the subscribing application receive and print the information from the publishing side For more information please read the RII Connext Prototyper Getting Started Guide in lt NDDSHOME gt doc pdf 3 1 Chapter 4 Understanding XML Based Application Creation Figure 4 1 depicts a Connext application built with the aid of both the Connext API and an XML configuration file Using the XML configuration file in combination with the XML Based Appli cation Creation feature simplifies and accelerates application development The Entities defined in the XML configuration fil
16. the development and program ming of RTI Connext applications Connext supports the use of XML for the complete system definition This includes not only the definition of the data types and Quality of Service settings as was possible in previous versions of the product but also the definition of the Topics DomainParticipants and all the Entities they contain Publishers Subscribers DataWriters and DataReaders With the traditional approach an application developer must program explicitly into the code the actions needed to join a domain register the data types it will use create the Topics and all the Entities Publishers Subscribers DataRead ers and DataWriters that the application uses Even for sim ple applications this system creation code can result in hundreds of lines of boiler plate code Beyond being error prone the traditional approach results in larger code bases that are harder to understand and maintain Using XML Based Application Creation can significantly simplify this process XML Based Application Creation is a simple layer that builds on top of the standard APIs Everything that you do This document assumes you have a basic understanding of Connext application development and concepts such as Domains DomainPartictpants Topics DataWriters and DataReaders For an overview of these concepts please read Introduction _ to Connext Section 3 2 in the RTI Core Libraries and Utilities Getting
17. the name MyType with a TypeSupport that is user generated To use this data type the application must also gen erate the TypeSupport code for the appropriate language binding using rtiddsgen and associate the generated TypeSupport with the name MyType This association is made by calling the operation register_type_support on the DomainParticipantFactory 4 18 Creating and Retrieving Entities Configured in an XML File lt domain name MyDomain domain_id 13 gt lt register type name MyType kind userGenerated gt lt domain gt Continuing the example above assume that the structure of MyType is described in the IDL file MyType idl Also assume that you are using the C language API and you have already run rtiddsgen and generated the type support files MyTypeSupport h and MyTypeSup port cxx These files will contain the declaration and implementation of the function MyType Support register_type In this situation you must associate the MyTypeSupport register_type operation with the type name MyType by calling DDSThePa rticipantFactory gt register_type_support from your application code prior to creating the DomainParticipant as shown in the C snippet below DDS ReturnCode_t retCode DDSTheParticipantFactory gt register type support FooTypeSupport register type MyType if retCode DDS RETCODE_OK handle error You can find an example of using a user generated type in lt installation
18. 6Linux2 6gcc4 4 5 This command will build a release executable To build a debug version instead type gmake f Makefile lt architecture gt DEBUG 1 Run the Application The previous step built two executables HelloWorld_subscriber and HelloWorld_publisher These applications should be in proper architecture subdirectory under the objs directory For example objs i86Win32VS2008 in the Windows example cited below and objs i86Linux2 6gcc4 4 5 in the Linux example 1 Start the subscribing application On a Windows system From your command shel go to lt installation directory gt exam ple CPP HelloWorld_xml_compiled and type objs lt architecture gt HelloWorld_subscriber exe where lt architecture gt is the architecture you just built see the contents of the objs directory to see the name of the architecture you built For example the Windows architecture name corresponding to 32 bit Visual Studio 2005 is i86Win32VS2005 On a UNIX based system From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_ compiled and type objs lt architecture gt HelloWorld_subscriber where lt architecture gt is the architecture you just built of the supported architectures examine the contents of the objs directory to see the name of the architecture you built 2 Start the publishing application On a Windows system From your command shel go to lt installation directory gt exa
19. Note that the operations such as set_long are used to set the different attributes of the dynam icData object These operations refer to the attribute names e g count that were defined as part of the data type Subscriber Application Open the file lt installation directory gt examples CPP HelloWorld_subscriber cxx and look at the source code The logic of this simple application is contained in the subscriber_main function Similar to the publisher application the logic can be seen as composed of two parts l Entity Creation LJ Use of the Entities Entity Creation The application first creates a DomainParticipant using the function create_participant_from_config This function takes the configuration name of the participant MyParticipantLibrary SubscriptionParticipant which is the same name that was specified in the XML file Notice that the name in the XML file SubscriptionParticipant has been qualified with the name of the library it belongs to MyParticipantLibrary DDSDomainParticipant participant DDSTheParticipantFactory gt create participant _from_config MyParticipantLibrary SubscriptionParticipant This single function call registers all the necessary data types and creates and the Topics and Entities that were specified in the XML file In this simple case the participant only contains a subscriber MySubscriber with a single DataReader HelloDataReader However in more realistic scenarios this single
20. RTI Connext DDS Core Libraries and Utilities XML Based Application Creation Getting Started Guide Version 5 1 0 t Your systems Working as one 2012 2013 Real Time Innovations Inc All rights reserved Printed in U S A First printing December 2013 Trademarks Real Time Innovations RTI DataBus and Connext are trademarks or registered trademarks of Real Time Innovations Inc All other trademarks used in this document are the property of their respective owners eid and Use Restrictions De tet of this publication may be reproduced stored in a retrieval system or transmitted in any form including electronic mechanical photocopy and facsimile without the eee written permission of Real Time Innovations Inc The software described in this a is furnished under and subject to the RTI software license agreement The software may be used or copied only under the terms of the license agreement Technical Support Real Time Innovations Inc 232 E Java Drive Sunnyvale CA 94089 Phone 408 990 7444 Email support rti com Website https support rti com Contents De HIMMOGUCTION Dee E E E E E EE 1 1 2 A Hello World EXOMP Ie ccccccssseeecccssseeeceeesseeesecesseeeseceeseees 2 1 2 1 Hello World using XML and Dynamic Data cece cece ceceeseenesessseseneneseseeeseseeeeeeseees 2 1 2 10 Buildthe Applicaton sisne ehe ea e e aa pLa a APSE ASEE rE e eesi 2 2 2 1 2 Run the Application
21. X NAME LEN 64 static const DDS Long MAX MSG LEN 128 typedef struct HelloWorld char sender maximum length MAX NAME LEN char message maximum length MAX MSG LEN DDS_ Long count HelloWorld Build the Application The example code is provided in C C and Java The following instructions describe how to build it on Windows and UNIX based systems If you will be using an embedded platform see the RTI Core Libraries and Utilities Getting Started Guide Addendum for Embedded Systems RTI_CoreLibraries AndUtilities_GettingStarted_EmbeddedSystemsAddendum pdf for instructions specific to these platforms C on Windows Systems 1 In the Windows Explorer go to lt installation directory gt exam ple CPP HelloWorld_xml_compiled and open the Microsoft Visual Studio solution file for your architecture For example the file for Visual Studio 2008 for 32 bit platforms is HelloWorld vs2008 sIn 2 The Solution Configuration combo box in the toolbar indicates whether you are building debug or release executables select Release Select Build Solution from the Build menu Hello World using XML and Compiled Types 2 2 4 C on UNIX based Systems 1 From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_compiled 2 Type gmake f Makefile lt architecture gt where lt architecture gt is one of the supported architectures e g Make file i8
22. ag as illustrated below replace 5 x y with the current version number lt xml version 1 0 encoding UTF 8 gt lt dds xmlns xsi http www w3 org 2001 XMLSchema instance xsi noNamespaceSchemaLocation resource qos profiles 5 x y schema rti_dds_profiles xsd version 5 x y gt You may use relative or absolute paths to the schema files These files are provided as part of your distribution in the following location replace 5 x y with the current version number L lt Connext installation directory gt resource qos_profiles_5 x y schema rti_dds_profiles xsd LI lt Connext installation directory gt resource qos_profiles_5 x y schema rti_dds_profiles dtd If you want to use the DTD for syntax validation instead of the XSD use the lt DOCTYPE gt tag Note however that this validation is less strict and will offer far less help in terms of auto com pletion The use of lt DOCTYPE gt is shown below Simply replace NDDSHOME with your Con next installation directory and replace 5 x y with the current version number lt xml version 1 0 encoding UTF 8 gt lt DOCTYPE dds SYSTEM SNDDSHOME resource gos profiles 5 x y schema rti_dds_ profiles dtd gt lt dds gt lt dds gt Accessing Entities Defined in XML Configuration from an Application You can use the operations listed in Table 4 1 to retrieve and then use the Entities defined in your XML configuration files Operations Intended f
23. ain_participant gt Once a DomainParticipant is created as explained in Creating and Retrieving a DomainPartici pant Configured in an XML File Section 4 7 1 Publishers and Subscribers can be retrieved from the created DomainParticipant using their name as follows DDSPublisher publisher participant gt lookup publisher by name MyPublisher if publisher NULL hnandle error 4 16 Creating and Retrieving Entities Configured in an XML File DDSPublisher publisher 1 participant gt lookup publisher by name MyPublisher 1 if publisher NULL hnandle error DDSSubscriber subscriber participant gt lookup_ subscriber by name MySubscriber if subscriber NULL hnandle error 4 7 3 Creating and Retrieving DataWriters and DataReaders DataWriters and DataReaders configured in XML are created automatically when a DomainPartic ipant is created from the lt domain_participant gt that contains the lt data_writer gt and lt data_reader gt configurations Given the following example lt domain participant name MyParticipant domain_ref MyDomainLibrary MyDomain gt lt publisher name MyPublisher gt lt data_writer name MyWriter topic _ref MyTopic gt lt publisher gt lt subscriber name MySubscriber gt lt data_reader name MyReader topic _ref MyTopic gt lt subscriber gt lt domain_participant gt Once a DomainParticipant is created a
24. aining part of the function uses the entities that were created to per form the logic of the program This example only needs to read data using the single DataReader So the application looks up the HelloWorldReader DataReader using the fully qualified name MyPublisher HelloWorl dReader and narrows it to be a HelloWorldDataReader 2 16 Subscriber Application HelloWorldDataReader helloWorldReader HellowWorldDataReader narrow participant gt lookup datareader by name MySubscriber HelloWorldReader To process the data the application installs a Listener on the DataReader The HelloWorldLis tener defined on the same file implements the DataReaderListener interface which the DataReader uses to notify the application of relevant events such as the reception of data Create a data reader listener HelloWorldListener reader_ listener new HelloWorldListener set listener retcode helloWorldReader gt set_listener reader_listener DDS_ DATA AVAILABLE STATUS The last part is the implementation of the listener functions In this case we only implement the on_data_available operation which is called when data is received The on_data_available function receives all the data into a sequence and then uses the Hello WorldTypeSupport print function to print each data item received void HelloWorldListener on_data_available DDSDataReader reader HelloWorldDataReader he
25. aram gt lt parameter_list gt lt filter gt lt data_reader gt lt subscriber gt lt domain_participant gt 4 11 Names Assigned to Entities 4 6 The above configuration defines a lt domain_participant gt that is bound to the lt domain gt MyDomain A DomainParticipant created from this configuration will contain J A Publisher which has a DataWriter created from the Topic MyTopic J A Subscriber which has DataReader created from a ContentFilteredTopic whose related Topic MyTopic uses a SQL filter Names Assigned to Entities Each Entity configured in a XML file is given a unique name This name is used to refer to them from other parts of the XML configuration and also to retrieve them at run time using the Con next API In the context of XML based configuration we should distinguish between two kinds of names L Configuration name The name of a specific Entity s configuration It is given by the name attribute of the corresponding XML element M Entity name The actual name of the Entity within the run time system In most cases the Entity name is the same as the configuration name However there are two excep tions DomainParticipants may be given their Entity names explicitly when they are cre ated using create_participant_from_config_w_params If no explicit name is given as occurs with create_participant_from_config a name will be generated automatically see Creati
26. be specified Using this empty profile results in the default DDS QoS being used lt QoS Library gt lt qos library name qgosLibrary gt lt qos profile name DefaultProfile gt lt qos_profile gt lt qos_library gt 2 1 3 2 Type Definition The data associated with the HelloWorld Topic consists of two strings and a numeric counter The first string contains the name of the sender of the message This field is marked as key as signals the identity of the data object I The second string contains a message I The third field is a simple counter which the application increments with each message This example uses the dynamic data API so the data type must be defined in the XML configu ration This is accomplished by adding the type definition within the lt types gt tag 2 4 Hello World using XML and Dynamic Data 2 1 3 3 2 1 3 4 lt types gt lt const name MAX NAME LEN type long value 64 gt lt const name MAX MSG LEN type long value 128 gt lt struct name HelloWorld gt lt member name sender type string key true stringMaxLength MAX NAME LEN gt lt member name message type string stringMaxLength MAX MSG LEN gt lt member name count type long gt lt struct gt lt types gt The lt types gt tag may be used to define a library containing the types that the different applica tions will need However for this simple example just one data type the Hell
27. char role name The mapping is Field Value name Entity name role_name Configuration name For example for the following configuration lt domain participant name MyParticipant domain _ref MyDomainLibrary MyDomain gt lt publisher name MyPublisher gt lt data_writer name MyWriter topic ref MyTopic gt lt publisher gt lt domain_participant gt The corresponding QoS policies for each entity are Entity QoS Policy Field Values f name participant_name DomainParticipant Entity NameQosPolicy ion role_name MyParticipant i name MyPublisher Publisher Entity NameQosPolicy role_name MyPublisher f i name MyWriter DataWriter Entity NameQosPolicy role_name MyWriter Where participant_name represents the value of the participant entity name specified at creation time Referring to Entities and Other Elements within XML Files Entities and other elements within the XML file are addressed using a hierarchical name that matches their declaration hierarchy This is summarized in the table below See Hierarchical Name Example Use type type_name type_ref MyType qos qos_library_name qos_profile_name base_name qosLibrary DefaultProfile Names Assigned to Entities Entity or Hierarchical Name Example Use Element Eaa domain_ref domain doma
28. ction 3 1 Building and running Hello World in Chapter 3 The guide is part of your dis tribution you can also find it online at http community rti com content page documenta tion The guide will assist you in the correct setting of both your environment variable NDDSHOME and depending on your architecture the environment variable PATH on Win dows Systems LD_LIBRARY_PATH on Linux systems or DYLD_LIBRARY_PATH on MacOS Systems Hello World using XML and Dynamic Data The files for this example are located in the directory lt installation directory gt example CPP HelloWorld_xml_dynamic This simple scenario consists of two applications illustrated in the figure below HelloWorld_publisher exe which writes the Topic HelloWorldTopic and HelloWorld_subscriber exe which subscribes to that Topic Hello World Domain DomainParticipant DomainParticipant DataWriter Hellowoxtd DataReader Topic Publisher Subscriber First we will run the application then we will examine the configuration file and source code 2 1 Hello World using XML and Dynamic Data Build the Application The example code is provided in C C and Java The following instructions describe how to build it on Windows and UNIX based systems If you will be using an embedded platform see the Core Libraries and Utilities Getting Started Guide Addendum for Embedded Systems RTI_CoreLibraries AndUtilities_GettingStarted_EmbeddedSystemsAddendum pd
29. d HelloWorldListener on_data_available DDSDataReader reader DDSDynamicDataReader ddDataReader NULL DDS DynamicDataSeq dataSeq DDS SampleInfoSeq infoSeq DDS _ReturnCode_t retcode DDS RETCODE ERROR DDS Long i 0 ddDataReader DDSDynamicDataReader narrow reader retcode ddDataReader gt take dataSeq infoSeq DDS LENGTH UNLIMITED DDS ANY SAMPLE STATE DDS ANY VIEW STATE DDS ANY INSTANCE STATE printf on_data_available s n ddDataReader gt get_topicdescription gt get_name for i 0 i lt dataSeq length i if infoSeq i valid_data retcode dataSeq i print stdout 0 retcode ddDataReader gt return_loan dataSeq infoSeq Subscribing with a Content Filter To use a content filter modify the SubscriptionParticipant configuration to look like this lt participant library name MyParticipantLibrary gt lt domain participant name SubscriptionParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt subscriber name MySubscriber gt lt data_reader name HelloWorldReader topic _ref HelloWorldTopic gt lt datareader_qos name HelloWorld _reader_qos base_name qgosLibrary DefaultProfile gt lt filter name HelloWorldTopic kind builtin sql gt lt expression gt count gt 2 lt expression gt lt filter gt lt data_reader gt lt subscriber gt lt domain_participant gt lt participant_library gt 2 9 Hello World using
30. data fields helloWorldData gt sender John Smith helloWorldData gt message Hello World helloWorldData gt count count retcode helloWorldWriter gt write helloWorldData DDS HANDLE NIL if retcode DDS RETCODE OK printf write error d n retcode publisher shutdown participant return 1 NDDSUtility sleep send_ period Note that the data object helloWorldData can be manipulated directly as a plain language object This means that in order to set a field in the object the application can refer to it directly as in 2 15 Subscriber Application 2 3 helloWorldData gt count count This plain language object API is both higher performance and friendlier to the programmer than the DynamicData API Subscriber Application Open the file lt installation directory gt examples CPP HelloWorld_subscriber cxx and look at the source code The logic of this simple application is in the subscriber_main function Similar to the publisher application the logic can be seen as composed of three parts L Type registration this step is new compared to the HelloWorld_xml_dynamic l Entity creation L Use of the Entities Type Registration This step is identical to the one for the publisher application The first thing the application does is register the data types that were defined in the code generation step This is accomplished calling the register_type_support functio
31. directory gt examples CPP HelloWorld_xml_compiled Also refer to the description of this example in Hello World using XML and Compiled Types Section 2 2
32. e can be created by a single call to the API Once created all Entities can be retrieved from application code using standard lookup opera tions so they can be used to read and write data Figure 4 1 Using both Connext API and XML Configuration File to Develop an Application Connext Application XML Configuration File Connext API 4 1 Important Points LJ Applications can instantiate a DomainParticipant from a participant configuration described in the XML Configuration file All the Entities defined by such a participant configuration are created automatically as part of DomainParticipant creation In addition multiple participant configurations may be defined within a single XML configuration file J All the Entities created from a participant configuration are automatically assigned an entity name Entities can be retrieved via lookup operations specifying their name Each Entity stores its own name in the QoS policies of the Entity so that they can be retrieved locally via a lookup up and communicated via discovery This is described in 4 1 Loading XML Configuration Files 4 2 4 3 4 3 1 Creating and Retrieving Entities Configured in an XML File Section 4 7 L An XML configuration file is not tied to the application that uses it Different applications may run using the same configuration file A single file may define multiple participant configurations A single application can instantiate as
33. e the DomainParticipants in the system and the DataWrit ers and DataReaders that each participant has DomainParticipants are defined within the lt participant_library gt tag Each DomainParticipant LI Has a unique name within the library which will be used later by the application that creates it LI Is associated with a domain which defines the domain_id Topics and data types the DomainParticipant will use 2 5 Hello World using XML and Dynamic Data L Defines the Publishers and Subscribers within the DomainParticipant Publishers contain DataWriters and Subscribers contain DataReaders L Defines the set of DataReaders it will use to write data Each DataReader has a QoS and a unique name which can be used from application code to retrieve it LJ Defines the set of DataWriters it will use to write data Each DataWriter has a QoS and a unique name which can be used from application code to retrieve it m Optionally the Participants Publishers Subscribers DataWriters and DataReaders can spec ify a QoS profile that will be used to configure them The example below defines two DomainParticipant entities called PublicationParticipant and SubscriptionParticipant lt participant_library name MyParticipantLibrary gt lt domain participant name PublicationParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt publisher name MyPublisher gt lt data_writer name HelloWorldWriter topic _ref Hell
34. f for instructions specific to these platforms To build the example C applications on a Windows System 1 In Windows Explorer go to lt installation directory gt exam ple CPP HelloWorld_xml_dynamic win and open the Microsoft Visual Studio solution file for your architecture For example the file for Visual Studio 2008 32 bit plat forms is HelloWorld vs2008 sIn 2 The Solution Configuration combo box in the toolbar indicates whether you are building debug or release executables select Release Then select Build Solution from the Build menu To build the example C applications on a UNIX based System 1 From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_dynamic 2 Type gt gmake f make Makefile lt architecture gt where lt architecture gt is one of the supported architectures e g Make file i86Linux2 6gcc4 4 5 see the contents of the make directory for a list of available architectures This command will build a release executable To build a debug version instead type gt gmake f make Makefile lt architecture gt DEBUG 1 Run the Application The previous step should have built two executables HelloWorld_subscriber and HelloWorld_publisher These applications should be in proper architecture subdirectory under the objs directory For example objs i86Win32VS2008 in the Windows example cited below and objs i86Linux2 6gcc4 4 5 in the Linux example
35. f DataReader with this configuration from a ContentFilteredTopic Attributes Name of the ContentFilteredTopic The Con tentFilteredTopic will be associated with the lt filter gt Porat same Topic referenced by the containing 0 or 1 lt data_reader gt Specifies which ContentFilter to use It filter_kind defaults to the builtin sq filter The lt filter gt tag within a lt data_reader gt enables content filtering It causes the corresponding DataReader to be created from a ContentFilteredTopic with the specified filter characteristics Table 4 13 Filter Tag Tags within Description Number of lt filter gt P Tags Allowed lt expression gt Filter expression Oorl List of parameters Parameters are specified using lt param gt tags The maximum number of parameters is 100 lt parameter_list gt lt parameter_list gt Oorl lt param gt param_0 lt param gt lt param gt param_1 lt param gt lt parameter_ list gt For example lt domain participant name MyParticipant domain _ref MyDomainLibrary MyDomain gt lt publisher name MyPublisher gt lt data_writer name MyWriter topic _ref MyTopic gt lt publisher gt lt subscriber name MySubscriber gt lt data_reader name MyReader topic_ref MyTopic gt lt filter name MyFilter kind builtin sql gt lt expression gt count gt 0 lt expression gt lt parameter list gt lt param gt 10 lt p
36. hat are multiplicity optional created with this configuration Default is 1 Specifies a Subscriber configuration Attributes name Subscriber configuration name lt subscriber gt 0 or more Number of Subscribers that are multiplicity optional created with this configuration Default is 1 Specifies a DataWriter configuration The DataWriter will be created inside the implicit Publisher Attributes name DataWriter configuration name lt data_writer gt Reference name a lt topic gt 0 or more topic_ref within the lt domain gt referenced by its lt participant gt parent Number of DataWriters that are multiplicity optional created with this configuration Default is 1 Specifies a data reader configuration The DataReader will be created inside the implicit subscriber Attributes name Data reader configuration name lt data_reader gt Reference name a lt topic gt 0 or more topic_ref within the lt domain gt referenced by its lt participant gt parent Number of DataReaders that are multiplicity optional created with this configuration Default is 1 lt participant_qos gt DomainParticipant QoS configuration Oorl XML Tags for Configuring Entities The lt publisher gt lt subscriber gt lt data_writer gt and lt data_reader gt tags are described in Figure 4 7 Table 4 9 Table 4 10 Table 4 11 and Table 4 12 Figure 4 7 Publisher and Subscriber Tags Table 4 9 Table 4 10 Table 4 11
37. icipantFactory gt create participant _from_config MyParticipantLibrary PublicationParticipant This single function call registers all the necessary data types and creates and the Topics and Entities that were specified in the XML file In this simple case the participant only contains a publisher MyPublisher with a single DataWriter HelloDataWriter However in more realis tic scenarios this single call can create hundreds of entities both readers and writers Use of the Entities The remaining part of the function uses the entities that were created to per form the logic of the program This example only needs to write data using the single data writer So the application looks up the HelloWorldWriter DataWriter using the fully qualified name MyPublisher HelloWorld Writer and narrows it to be a HelloWorldDataWriter Note the difference with the HelloWorld_xml_dynamic example Rather than the generic DynamicDataWriter used in the example here we use a DataWriter specific to the HelloWorld data type HelloWorldDataWriter helloWorldWriter HelloWorldDataWriter narrow participant gt lookup datawriter by name MyPublisher HelloWorldWriter Create data HelloWorld helloWorldData HelloWorldTypeSupport create data j Main loop for count 0 sample _ count 0 count lt sample count count printf Writing HelloWorld count d n count Set the
38. in the directory lt installation directory gt example CPP HelloWorld_xml_dynamic Let s review its content to see how this scenario was constructed The main sections in the file are LJ QoS definition section Type definition section I Domain definition section l Participant definition section The entire file is shown below The we will examine the file section by section lt dds xmlns xsi http www w3 org 2001 XMLSchema instance xsi noNamespaceSchemaLocation resource qos profiles _5 1 0 schema rti_dds_profiles xsd version 5 1 0 gt lt QoS Library gt lt qos library name qgosLibrary gt lt qgos profile name DefaultProfile gt lt qos_profile gt lt qos_library gt lt types gt lt types gt lt const name MAX NAME LEN type long value 64 gt lt const name MAX MSG LEN type long value 128 gt lt struct name HelloWorld gt lt member name sender type string key true stringMaxLength MAX NAME LEN gt lt member name message type sString stringMaxLength MAX MSG LEN gt lt member name count type long gt lt struct gt lt types gt lt Domain Library gt lt domain library name MyDomainLibrary gt lt domain name HelloWorldDomain domain_id 0 gt lt register type name HelloWorldType kind dynamicData type _ref HellowWorld gt lt topic name HelloWorldTopic register type ref HelloWorldType gt lt topic_qos na
39. in_libary_name domain_name MyDomainLibrary MyDomain participant_library_name Base name SRI participant iS MyParticipantLibrary PublicationPar participant_name ticipant topic_name topic Must be defined within the scope of the topic_ref MyTopic Domain or the Participant that refer to it subscriber_name publisher Must be defined within the scope of the base_name MyPublisher Participant that refers to it subscriber_name subscriber Must be defined within the scope of the base_name MySubscriber Participant that refers to it data_writer publisher_name datawriter_name If addressing from within the same Pub lisher the publisher_name prefix may be omitted base_name MyPublisher MyWriter base_name MyWriter data_reader subscriber_name datareader_name If addressing from within the same Sub scriber the subscriber_name prefix may be omitted base_name MySubscriber MyReader base_name MyReader The example above corresponds to a configuration such as the one following lt dds xmlns xsi http www w3 org 2001 XMLSchema instance xsi noNamespaceSchemaLocation EEN schema rti_dds_profiles xsd version 5 x y gt lt types gt lt struct name MyType gt resource qos profiles 5 x y lt member name mylong type long gt lt struct gt lt types gt lt domain library name MyDomai
40. ition Section 2 1 3 for an example XML file and a description of its contents Validation at Run Time Connext validates the input XML files using a built in Document Type Definition DTD You can find a copy of the builtin DTD in NDDSHOME resource qos_profiles_ lt version gt schema rti_dds_profiles dtd This is only a copy of the DTD that Connext uses Changing this file has no effect unless you specify its path with the DOCTYPE tag described below You can overwrite the built in DTD by using the XML tag lt DOCTYPE gt For example the fol lowing indicates that Connext must use a different DTD file to perform validation lt DOCTYPE dds SYSTEM local usr rti dds modified_rti_dds_profiles dtd gt 4 2 Accessing Entities Defined in XML Configuration from an Application 4 3 2 4 4 Table 4 1 If you do not specify the DOCTYPE tag in the XML file the built in DTD is used The DTD path can be absolute or relative to the application s current working directory Validation during Editing Connext provides DTD and XSD files that describe the format of the XML content We highly rec ommend including a reference to the XSD in the XML file This provides helpful features in code editors such as Visual Studio Eclipse or Netbeans including validation and auto completion while you are editing the XML file To include a reference to the XSD file use the noNamespaceSchemaLocation attribute inside the opening lt dds gt t
41. lloWorldReader NULL HelloWorldSeq dataSeq DDS SampleInfoSeq infoSeq DDS _ReturnCode_t retcode DDS RETCODE_ ERROR DDS Long i 0 helloWorldReader HelloWorldDataReader narrow reader retcode helloWorldReader gt take dataSeq infoSeq DDS LENGTH UNLIMITED DDS ANY SAMPLE STATE DDS ANY VIEW STATE DDS ANY INSTANCE STATE for i 0 i lt dataSeq length i if infoSeq i valid_data HelloWorldTypeSupport print data amp dataSeq i retcode helloWorldReader gt return_loan dataSeq infoSeq Note that the sequence received is of type HelloWorldSeq which contains the native plain lan guage objects of type HelloWorld This can be manipulated directly by the application For example the fields can be dereferenced as shown in the code snippet below HelloWorld helloWorldData amp dataSeq i printf count s n helloWorldData gt count 2 17 Chapter 3 Using Connext Prototyper RTI Connext Prototyper is a companion tool for use with the XML Based Application Creation feature This tool allows application developers to quickly try out scenarios directly from their XML descriptions without writing any code Prototyper is included with Connext DDS and Con next Mesaging On a Windows system From your command shell go to lt installation directory gt exam ple CPP HelloWorld_xml_dynamic Open two console windows In one window type all on one line SNDDSHOME scripts
42. m ple CPP HelloWorld_xml_compiled and type objs lt architecture gt HelloWorld_publisher exe where lt architecture gt is the architecture you just built see the contents of the objs directory to see the name of the architecture you built On a UNIX based system From your command shell change directory to lt installation directory gt example CPP HelloWorld_xml_ compiled and type objs lt architecture gt HelloWorld_publisher Hello World using XML and Compiled Types 2 2 5 You should immediately see some messages on the publishing application showing that it is writing data and messages in the subscribing application indicating the data it receives Do not worry about the contents of the messages They are generated automatically for this example The important thing is to understand how the application is defined which will be explained in the following subsections Examine the XML Configuration Files Definition This system is defined in the file USER_QOS_PROFILES xml found in the directory lt installa tion directory gt example CPP HelloWorld_xml_compiled Let s look at its content and what are the elements defined to construct this scenario lt dds xmlns xsi http www w3 org 2001 XMLSchema instance xsi noNamespaceSchemaLocation resource qos profiles 5 1 0 schema rti_dds_profiles xsd version 5 1 0 gt lt Qos Library gt lt qos_ library name qgosLibrary gt lt qgos profile name
43. many DomainParticipants as desired L Changes in the XML configuration file do not require recompilation even if Entities are added or removed unless the logic that uses the Entities also needs to change Loading XML Configuration Files Connext loads its XML configuration from multiple locations This section presents the various approaches listed in load order The following locations contain QoS Profiles see Chapter 15 in the RTI Core Libraries and Utilities User s Manual and may also contain Entity configurations L NDDSHOME resource qos_profiles_5 x y xml NDDS_QOS_PROFILES xml This file contains the Connext default QoS values it is loaded automatically if it exists When present this is the first file loaded Where x y represent version numbers J File specified in NDDS_QOS_PROFILES Environment Variable The files or XML strings separated by semicolons referenced in this environment vari able if any are loaded automatically These files are loaded after the NDDS_QOS_PROFILES xml and they are loaded in the order they appear listed in the environment variable L lt working directory gt USER_QOS_PROFILES xml This file is loaded automatically if it exists in the working directory of the application that is the directory from which the application is run This file is loaded last XML Syntax and Validation The configuration files uses XML format Please see Examine the XML Configuration Files Defi n
44. me HelloWorld_qgos base_name qgosLibrary DefaultProfile gt lt topic gt lt domain gt lt domain_library gt 2 3 Hello World using XML and Dynamic Data lt Participant library gt lt participant library name MyParticipantLibrary gt lt domain participant name PublicationParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt publisher name MyPublisher gt lt data_writer name HelloWorldWriter topic_ref HelloWorldTopic gt lt publisher gt lt domain_participant gt lt domain_ participant name SubscriptionParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt subscriber name MySubscriber gt lt data_reader name HelloWorldReader topic_ref HelloWorldTopic gt lt datareader_gqos name HelloWorld_ reader _gos base_name qgosLibrary DefaultProfile gt lt data_reader gt lt subscriber gt lt domain_participant gt lt participant_library gt 2 1 3 1 QoS Definition The DDS Entities that are defined have an associated QoS The QoS section of the XML file pro vides the means to define QoS libraries and profiles that can be used to configure the QoS of the defined Entities The syntax of the QoS libraries and profiles section is described in the RTI Core Libraries and Util ities User s Manual Chapter 17 Configuring QoS with XML In this example the QoS library and profile are empty just to provide a placeholder where the QoS can
45. mple writes data using the single DataWriter So the application looks up the Hello WorldWriter DataWriter using the fully qualified name MyPublisher HelloWorldWriter and nar rows it to be a DynamicDataWriter DDSDynamicDataWriter dynamicWriter DDSDynamicDataWriter narrow participant gt lookup datawriter by name MyPublisher HelloWorldWriter Once the DataWriter is available some data objects need to be created and used to send the data As this example uses dynamic data and the type code is internally created you can use the operations create_data and delete_data in a DataWriter to create and delete a data object This is achieved with the calls seen below Create data DDS DynamicData dynamicData dynamicWriter gt create data DDS DYNAMIC DATA PROPERTY DEFAULT Main loop to repeatedly send data for count 0 count lt 100 count Set the data fields retcode dynamicData gt set_string sender DDS_DYNAMIC DATA MEMBER ID UNSPECIFIED John Smith 2 7 Hello World using XML and Dynamic Data retcode dynamicData gt set_string message DDS_DYNAMIC DATA MEMBER ID UNSPECIFIED Hello World retcode dynamicData gt set_long count DDS_DYNAMIC_ DATA MEMBER ID UNSPECIFIED count Write the data retcode dynamicWriter swrite dynamicData DDS HANDLE NIL Delete data sample dynamicWriter gt delete data dynamicData
46. n on the DomainParticipantFac tory type registration retcode DDSTheParticipantFactory gt register type support HelloWorldTypeSupport register_ type HelloWorldType Please refer to the explanation of the publishing application for more details as this step us regardless of whether the application uses a type to publish or subscribe Entity Creation The steps needed to create the entities are the same as for the HelloWorld_xml_dynamic example The application first creates a DomainParticipant using the function create_participant_from_config this function takes the configuration name of the participant MyParticipantLibrary SubscriptionParticipant which is the same name that was specified in the XML file Note that the name in the XML file SubscriptionParticipant has been qualified with the name of the library it belongs to MyParticipantLibrary DDSDomainParticipant participant DDSTheParticipantFactory gt create participant _from_config MyParticipantLibrary SubscriptionParticipant This single function call registers all the necessary data types and creates and the Topics and Entities that were specified in the XML file In this simple case the participant only contains a Subscriber MySubscriber with a single DataReader HelloDataReader However in more real istic scenarios this single call can create hundreds of entities both DataReaders and DataWriters Use of the Entities The rem
47. nLibrary gt lt domain name MyDomain domain_id 0 gt lt register type name MyRegisteredType kind dynamicData type _ref MyType gt lt topic name MyTopic register type ref MyRegisteredType gt lt domain gt lt domain_library gt lt participant library name MyParticipantLibrary gt lt domain participant name MyParticipant domain_ref MyDomainLibrary MyDomain gt lt publisher name MyPublisher gt Creating and Retrieving Entities Configured in an XML File 4 7 4 7 1 lt data_writer name MyWriter topic ref MyTopic gt lt publisher gt lt subscriber name MySubscriber gt lt data_reader name MyReader topic ref MyTopic gt lt subscriber gt lt domain_participant gt lt participant_library gt lt dds gt Creating and Retrieving Entities Configured in an XML File There are two kinds of operations that affect Entities configured in an XML file I Create the defined entities Only the operation create_participant_from_config in the DomainParticipantFactory triggers the creation of a DomainParticipant and all its con tained Entities given a configuration name I Retrieve the defined entities After creation you can retrieve the defined Entities by using the lookup_by_name operations available in the DomainParticipantFactory DomainParticipant Publisher and Subscriber Creating and Retrieving a DomainParticipant Configured in an XML File To crea
48. ng and Retrieving a DomainParticipant Configured in an XML File Section 4 7 1 Whenever the attribute multiplicity is set to a value greater than one This setting indicates that a set of Entities should be all from the same configuration As each Entity must have a unique name the system will automatically append a number to the configuration name to obtain the Entity name For example if we specified a multiplicity of N then for each index i between 0 and N 1 the system will assign entity names according to the table below Entity Name Index i configuration_name 0 configuration_name i 1 N 1 That is the Entity name followed by the token and an index For example lt publisher name MyPublisher gt lt data_writer name MyWriter multiplicity 3 topic _ref MyTopic gt lt publisher gt For the above XML configuration the name assignment is 4 12 Names Assigned to Entities 4 6 1 Configuration Entity Multiplicity Entity Names My Publisher Publisher 1 My Publisher My Writer My Writer DataWriter 3 MyWriter 1 My Writer 2 The entity name is stored by Connext using the Entity NameQosPolicy QoS policy for DomainPar ticipants Publishers Subscribers DataWriters and DataReaders The policy is represented by the following C structure Struct DDS EntityNameQosPolicy char name
49. oWord type seen above is included Domain Definition The domain section is used to define the system s Topics and the corresponding data types asso ciated with each Topic To define a Topic the associated data type must be registered with the domain giving it a registered type name The registered type name is used to refer to that data type within the domain at the time the Topic is defined In this example the configuration file registers the previously defined HelloWorld type under the name HelloWorldType and then defines a topic with name HelloWorldTopic associated with the registered type referring to it by its registered name HelloWorldType lt Domain Library gt lt domain library name MyDomainLibrary domain_id 0 gt lt domain name HelloWorldDomain gt lt register type name HelloWorldType kind dynamicData type_ref HellowWorld gt lt topic name HelloWorldTopic register type ref HelloWorldType gt lt domain gt lt domain_library gt Note that attribute type_ref in the lt register_type gt element refers to the same HelloWorld type defined in the lt types gt section A domain definition may register as many data types and define as many Topics as it needs In this example a single data type and Topic suffices Note that domain_library can be used to define multiple domains However in this example only one domain is used Participant Definition The participant section is used to defin
50. oWorldTopic gt lt publisher gt lt domain_participant gt lt domain participant name SubscriptionParticipant domain _ref MyDomainLibrary HelloWorldDomain gt lt subscriber name MySubscriber gt lt data_reader name HelloWorldReader topic_ref HelloWorldTopic gt lt datareader_qos name HelloWorld_reader_qos base_name qgosLibrary DefaultProfile gt lt data_reader gt lt subscriber gt lt domain_ participant lt participant_library gt Examining the XML we see that I The PublicationParticipant bound to the domain MyDomainLibrary HelloWorldDo main L The participant contains a single Publisher with name MyPublisher which itself con tains a single DataWriter named HelloWorldWriter L The DataWriter writes the Topic HelloWorldTopic which is defined in the domain MyDo mainLibrary HelloWorldDomain Similarly L The SubscriptionParticipant is also bound to the domain MyDomainLibrary Hello WorldDomain The participant contains a single Subscriber with name MySubscriber which itself con tains a single DataReader named HelloWorldReader L The DataReader reads the topic HelloWorldTopic which is defined in the domain MyDo mainLibrary HelloWorldDomain 2 6 Hello World using XML and Dynamic Data Since both participants are in the same domain and the HelloWorldWriter DataWriter writes the same Topic that the HelloWorldReader DataReader reads the two participants will communica
51. omain_id is specified directly or in the referenced domain then the default domain_id is 0 domain_id optional A lt domain_participant gt may inherit its configuration from another base participant specified using the base_name attribute In this case overriding applies to the base lt domain_participant gt as well as to the referred lt domain gt Note that in DataWriters always belong to a Publisher and DataReaders to a Subscriber For this rea son the lt data_writer gt and lt data_reader gt typically appear nested inside the corresponding lt publisher gt and lt subscriber gt tags However for convenience it is possible to define 4 8 XML Tags for Configuring Entities Table 4 8 lt data_writer gt and lt data_reader gt tags directly under the lt domain_participant gt tag In this case the DataWriters and DataReaders are created inside the implicit Publisher and Subscriber respectively Domain Participant Tag ore Number Tags within Descrivti fT lt domain_participant gt SNP UDN Cee is Allowed Specifies how a type is registered Same as within the lt register_type gt 0 or more lt domain gt tag lt topic gt Specifies a topic Same as within the lt domain gt tag 0 or more Specifies a Publisher configuration Attributes lt publisher gt name Publisher configuration name Jorko Number of Publishers t
52. or Use with XML Based Configuration Working with Configuration Related Operations Reference create_participant_from_config m create_participant_from_config_w_params Section 4 7 1 DomainParticipantFactory soleil portieipant byname register_type_support Section 4 7 5 4 3 XML Tags for Configuring Entities Table 4 1 Operations Intended for Use with XML Based Configuration Working with Configuration Related Operations Reference lookup_publisher_by_name lookup_subscriber_by_name DomainParticipant i Section 4 7 2 lookup_datawriter_by_name lookup_datareader_by_name Publisher lookup_datawriter_by_name Section 4 7 3 Subscriber lookup_datareader_by_name 4 5 XML Tags for Configuring Entities There are two top level tags to configure Entities in the XML configuration files L lt domain_library gt Defines a collection of domains A domain defines a global data space where applications can publish and subscribe to data by referring to the same Topic name Each domain within the domain library defines the Topics and associated data types that can be used within that domain Note that this list is not necessarily exhaus tive The participants defined within the lt participant_library gt might add Topics beyond the ones listed in the domain library L lt participant_library gt Defines a collection of DomainParticipants A DomainParticipant provides the mean
53. peSupport function that defines the data type in compile code In this case it is HelloWorldTypeSupport register_type this function is declared in the HelloWorldSupport h However you cannot see it directly there because it is defined using macros Instead you will find the line Hello World using XML and Compiled Types DDS_TYPESUPPORT_ CPP HelloWorldTypeSupport HelloWorld This line defines the HelloWorldTypeSupport register_type function In general if you include multiple data type definitions in a single XML or IDL file called MyFile xml or MyFile idl you will have multiple TypeSupport types defines within the gener ated file MyFileTypeSupport h You can identify them searching for the DDS_TYPESUPPORT_CPP macro and you should register each of them the ones the applica tion uses using the operation register_type_support as was shown earlier Entity Creation The steps needed to create the entities are the same as for the HelloWorld_xml_dynamic example The application first creates a DomainParticipant using the function create_participant_from_config this function takes the configuration name of the participant MyParticipantLibrary PublicationParticipant which is the same name that was speci fied in the XML file Note that the name in the XML file PublicationParticipant has been qual ified with the name of the library it belongs to MyParticipantLibrary DDSDomainParticipant participant DDSThePart
54. preference You can even transform between one and the other with the RTI tools That said as the rest of the configuration files use XML it is often more convenient to also use XML to describe the data types so they can be shared or moved to other XML configuration files The directory lt installation directory gt example CPP HelloWorld_xml_compiled contains the XML description of the data type in the file HelloWorld xml and it also contains the equivalent IDL description in HelloWorld idl Let s examine the contents of the XML file lt xml version 1 0 encoding UTF 8 gt lt types xmlns xsi http www w3 org 2001 XMLSchema instance xsi noNamespaceSchemaLocation resource rtiddsgen schema rti_dds_topic_types xsd gt lt const name MAX NAME LEN type long value 64 gt lt const name MAX MSG LEN type long value 128 gt lt struct name HelloWorld gt lt member name Sender type sString key true stringMaxLength MAX NAME LEN gt lt member name message type string stringMaxLength MAX MSG LEN gt lt member name count type long gt lt struct gt lt types gt The file defines a structure type called HelloWorld consisting of a string the sender a string the message and an integer count Note that the type declaration syntax is identical the one used within the USER_QOS_PROFILES xml file that we used for the dynamic example section Type Definition Section 2 1 3 2
55. reference to the type definition so the type_ref attribute is not present To sum it up the XML configuration file is essentially the same except that the type definitions of the data types that will be compiled in are not present and that is indicated at the time the data type is registered in the domain by means of the attribute kind userGenerated Publisher Application Open the file lt installation directory gt examples CPP HelloWorld_publisher cxx and look at the source code The logic of this simple application is contained in the publisher_main function The logic can be seen as composed of three parts Type registration this step is new compared to the HelloWorld_xml_dynamic I Entity creation L Use of the Entities Type Registration The first thing the application does is register the data types that were defined in the code generation step This is accomplished by calling the register_type_support function on the DomainParticipantFactory type registration retcode DDSTheParticipantFactory gt register type support HelloWorldTypeSupport register type HelloWorldType The function register_type_support must be called for each code generated data type that will be associated with the Topics published and subscribed by the application In this example there is only one Topic and one data type so only one call to this function is required The function register_type_support takes as a parameter the Ty
56. rticipant_library gt and the tags it contains A lt domain_participant gt can be associated with a domain where topics and their associ ated types are already defined The elements lt register_type gt and lt topic gt may also be defined in a lt domain_participant gt the same way it is done in a lt domain gt This makes it possible to add Topics data types etc beyond the ones defined in the domain or alternatively redefine the elements that are already in the lt domain gt A lt domain_participant gt is defined by specify ing the set of Entities it contains This is done using tags such as lt publisher gt lt subscriber gt lt data_writer gt and lt data_reader gt which specify a Entity of their corresponding type These Entities are created within the DomainParticipant instantiated from the configuration profile that contains the definitions Participant Library Tag Number Description of Tags Allowed Tags within lt participant_library gt Specifies a participant configuration Attributes name Participant configuration name Base participant name It specifies base_name optional another participant from which to inherit the configuration Reference fully qualified name to domain_ref optional a defined lt domain gt in the domain library lt domain_participant gt 1 or more Domain ID If specified overrides the id in the domain it refers to If no d
57. s explained in Section 4 7 1 DataWriters and DataReaders can be retrieved from the created DomainParticipant using their fully qualified name as shown below DDSDataWriter dataWriter participant gt lookup dataWriter_ by name MyPublisher MyWriter if dataWriter NULL handle error DDSDataReader dataReader participant gt lookup datareader _by name MySubscriber MyReader if dataReader NULL hnandle error Or from the created Publisher and Subscriber using their unqualified name as shown below DDSDataWriter dataWriter publisher gt lookup_dataWriter by name MyWriter if dataWriter NULL nandle error 4 17 Creating and Retrieving Entities Configured in an XML File 4 7 4 4 7 5 DDSDataReader dataReader subscriber gt lookup_datareader_by name MyReader Creating Content Filters To use a content filter modify the SubscriptionParticipant configuration to look like this lt participant library name MyParticipantLibrary gt lt domain participant name SubscriptionParticipantWithFilter domain_ref MyDomainLibrary HelloWorldDomain gt lt subscriber name subscriber gt lt data_reader name HelloWorldReader topic_ref HelloWorldTopic gt lt datareader_qos name HelloWorld_reader_qos base_name qosLibrary DefaultProfile gt lt filter name HelloWorldTopic kind builtin sql gt lt expression gt count g
58. s for an application to join a domain The DomainParticipant contains all the Entities needed to publish and subscribe data in the domain Publishers Subscrib ers DataWriters DataReaders etc Figure 4 2 and Table 4 2 describe the top Figure 4 2 Top Level Tags in Configuration File level tags that are allowed within the root lt dds gt tag Table 4 2 Top Level Tags in Configuration File Number Tags within lt dds gt Description of Tags Allowed Specifies a domain library Set of lt domain gt definitions lt domain_library gt Attributes 0 or more name Domain library name 4 4 XML Tags for Configuring Entities Table 4 2 4 5 1 Table 4 3 Top Level Tags in Configuration File Number Tags within lt dds gt Description of Tags Allowed _ i Specifies a participant library Set of lt domain_participant gt definitions lt participant_library gt m 0 or more name Participant library name Specifies a QoS library and profiles lt qos_library gt The contents of this tag are specified in the same manner as fora Con 0 or more next QoS profile file see Chapter 15 in the RTI Core Libraries and Utili ties User s Manual lt types gt Defines types that can be used for dynamic data registered types Oorl Domain Library A domain library provides a way to organize a set of domains that belongs to the same system A domain represents a data space where
59. s ich dash cit Aa eae ati este sire eek 2 2 2 1 3 Examine the XML Configuration Files Definition ccccccecsssssseseseseneneseseseseneesesees 2 3 2 14 Publisher Application 20 eere ee E A eaostnv et ote clase TER e a 2 7 21 5 Subscriber Application x icst ccsceertcisid vseisnhted awadishviaid cto eresi asie 2 8 2 1 6 Subscribing with a Content Filter 0 0 cece sessssseseeesesesesesesessssesesesessesesesessssesesees 2 9 2 2 Hello World using XML and Compiled Types c ccc cece ce ceceeeeseececesesensneseseseneseseseneeeees 2 10 2 2 1 Define the Data Types using IDL or XMLi cece ce ceeeececeneceneneneseneseneneseenenes 2 10 2 2 2 Generate Type Support Code from the Type Definition 0 0 ccc cece teneeeees 2 11 223 Build the Application rie yeee a e e E a a E RA 2 11 224 Run the Applications sssini ot aE ER R A a a ade e 2 12 2 2 5 Examine the XML Configuration Files Definition s sessessssessssssssiesisstsssesieseesesssesieseesee 2 13 22 6 Publisher Applications ensirep dite tetas e e e a r anae e a e eshte tad 2 14 2 3 Subscriber Applicatioun aaa nia ateei itas aaan 2 16 gt Using Connext PIOIOIV DON aaaeaii enaena epa iana ienaa daai aai anana 3 1 4 Understanding XML Based Application Creation sssnnennnnns 4 1 L Important Points ssc cscc cvess ccccasssncytac stone e ioia iea ia e e a ae ese 4 1 42 gt Loading XML Configuration Files cccccccesecscseseseescscsesesescscsc
60. sssesescscsssnsesescecsssnseesecesessnseesecenes 4 2 437 XML Syntax atid Validation sssenssminsnsiisneri pinnana insna 4 2 4 3 1 Validation at Run Time a a a a a aa a r aesa Eaa Ea RUAS 4 2 4 3 2 Validation during Edin nsaan aeae e a e e S a 4 3 4 4 Accessing Entities Defined in XML Configuration from an Application eee 4 3 4 5 XML Tags for Configuring Entities issie ni p a eE a ay a aoa 4 4 451 Domain Libtary ssiece 13 ae cistestentis ete naa a a a RS A SE 4 5 45 2 Participant Library siensia rsi ia esaya eis ines ives SAE Ea GERESET Ni 4 8 4 6 Names Assigned to Entities i imesnienn een i i th Bites e ae a a 4 12 4 6 1 Referring to Entities and Other Elements within XML Files eee eee 4 13 4 7 Creating and Retrieving Entities Configured in an XML File cccceccscsesceteneeseeeeteeseeeeenene 4 15 4 7 1 Creating and Retrieving a DomainParticipant Configured in an XML File 4 15 4 7 2 Creating and Retrieving Publishers and Subscribers cccccsssesecseseseseecsceeseeeeeeees 4 16 4 7 3 Creating and Retrieving DataWriters and DataReade S ccccccccccseseseeceeeeeeeeeees 4 17 474 Creating Content Filters 22 in iateancaitintdivcansisietiesiameteclsinatestipientelewntanas i 4 18 47 9 Usitig User Generated Types cess cccitesescsiieieeseccvsnsvevescesastesvectetenstecctshetacuectshesstucusshesstsevtats 4 18 Chapter 1 Introduction XML Based Application Creation is a mechanism to simplify
61. t count lt 20 lt expression gt lt filter gt lt data_reader gt lt subscriber gt lt domain_participant gt lt participant_library gt It adds a SQL content filter which only accepts samples with the field count greater than two Now run the HelloWorld_subscriber application without recompiling and check that it only receives data when counter less than 20 as expected Using User Generated Types If a user generated type by means of rtiddsgen is desired rather than dynamic data the corre sponding type support must be registered with the DomainParticipantFactory before creating a DomainParticipant To register the type support use the function register_type_support in the DomainParticipantFactory which takes a a pointer to a function that registers a type and b the type name it is registered with Then the specified function will be called automatically by the middleware whenever the type registration is needed The definition of this function is given by typdef DDS ReturnCode_t DomainParticipantFactory RegisterTypeFunction DDSDomainParticipant participant const char type_name This register type function should be generated using the rtiddsgen command line tool from the IDL or XML definition of the data type See Hello World using XML and Compiled Types Section 2 2 for a simple example of how to follow this process For example the following XML snippet defines a data type registered under
62. te as was illustrated in Figure 2 1 Hello World Domain on page 2 1 Publisher Application Open the file lt installation directory gt examples CPP HelloWorld_publisher cxx and look at the source code The logic of this simple application is contained in the publisher_main function The logic can be seen as composed of two parts Entity Creation LJ Use of the Entities Entity Creation The application first creates a DomainParticipant using the function create_participant_from_config this function takes the configuration name of the participant MyParticipantLibrary PublicationParticipant which is the same name that was specified in the XML file Note that the name in the XML file PublicationParticipant has been qualified with the name of the library it belongs to MyParticipantLibrary DDSDomainParticipant participant DDSTheParticipantFactory gt create participant _from_config MyParticipantLibrary PublicationParticipant This single function call registers all the necessary data types and creates and the Topics and Entities that were specified in the XML file In this simple case the participant only contains a Publisher MyPublisher with a single DataWriter HelloDataWriter However in more realistic scenarios this single call can create hundreds of entities both readers and writers Use of the Entities The remaining part of the function uses the created Entities to perform the logic of the program This exa
63. te a DomainParticipant from a configuration profile in XML use the function create_participant_from_config which receives the configuration name and creates all the entities defined by that configuration For example lt participant library MyLibrary gt lt domain participant name MyParticipant domain _ref MyDomainLibrary MyDomain domain _id 1 gt lt domain_participant gt lt participant_library gt Given the above configuration a DomainParticipant is created as follows DDSDomainParticipant participant DDSTheParticipantFactory gt create participant from_config MyLibrary MyParticipant if participant NULL hnandle error The DomainParticipant is bound to the domain_id specified in either the lt domain_participant gt tag this has precedence or the lt domain gt tag In this example the domain_id is set to one When the DomainParticipant is created by means of create_participant_from_config a name will be generated automatically based on the configuration name and the number of existing participants created from the same configuration The generation follows the same strategy explained in Names Assigned to Entities Section 4 6 for the domain entities where the multi 4 15 Creating and Retrieving Entities Configured in an XML File plicity is replaced by the number of existing participants If this is number is identified by N the participant name for a new participant will
Download Pdf Manuals
Related Search
Related Contents
EVO : Installation Guide SPL-100A BPMpro Data Logger User Guide v3 Haier HWM10-01 User's Manual セミナーⅡa Polycom Wireless Server 600V3 Manuel d`utilisation EROS Manual - Gasteiger Group AEG MC2664E-M Инструкция PICA II Copyright © All rights reserved.
Failed to retrieve file