4.3. Create an Application¶
The rest of this guide will walk you through the steps to create an application and will provide example code snippets. It assumes that you have defined your types (see Define a Data Type) and have used rtiddsgen to generate their support code (see Generate Type Support Code with rtiddsgen).
4.3.1. Registry Configuration¶
The DomainParticipantFactory, in addition to its standard role of creating and deleting DomainParticipants, contains the RT Registry that a new application registers with some necessary components.
The Connext Micro architecture defines a run-time (RT) component interface that provides a generic framework for organizing and extending functionality of an application. An RT component is created and deleted with an RT component factory. Each RT component factory must be registered within an RT registry in order for its components to be usable by an application.
Connext Micro automatically registers components that provide necessary functionality. These include components for DDS Writers and Readers, the RTPS protocol, and the UDP transport.
In addition, every DDS application must register three components:
Writer History. Queue of written samples of a DataWriter. Must be registered with the name “wh”.
Reader History. Queue of received samples of a DataReader. Must be registered with the name “rh”.
Discovery (DPDE or DPSE). Discovery component. Choose either dynamic (DPDE) or static (DPSE) endpoint discovery.
Example source:
Get the RT Registry from the DomainParticipantFactory singleton:
DDS_DomainParticipantFactory *factory = NULL; RT_Registry_T *registry = NULL; factory = DDS_DomainParticipantFactory_get_instance(); registry = DDS_DomainParticipantFactory_get_registry(factory);
Register the Writer History and Reader History components with the registry:
/* Register Writer History */ if (!RT_Registry_register(registry, "wh", WHSM_HistoryFactory_get_interface(), NULL, NULL)) { /* failure */ } /* Register Reader History */ if (!RT_Registry_register(registry, "rh", RHSM_HistoryFactory_get_interface(), NULL, NULL)) { /* failure */ }
Only one discovery component can be registered, either DPDE or DPSE. Each has its own properties that can be configured upon registration.
Register DPDE for dynamic participant, dynamic endpoint discovery:
struct DPDE_DiscoveryPluginProperty discovery_plugin_properties = DPDE_DiscoveryPluginProperty_INITIALIZER; /* Configure properties */ discovery_plugin_properties.participant_liveliness_assert_period.sec = 5; discovery_plugin_properties.participant_liveliness_assert_period.nanosec = 0; discovery_plugin_properties.participant_liveliness_lease_duration.sec = 30; discovery_plugin_properties.participant_liveliness_lease_duration.nanosec = 0; /* Register DPDE with updated properties */ if (!RT_Registry_register(registry, "dpde", DPDE_DiscoveryFactory_get_interface(), &discovery_plugin_properties._parent, NULL)) { /* failure */ }
Register DPSE for dynamic participant, static endpoint discovery:
struct DPSE_DiscoveryPluginProperty discovery_plugin_properties = DPSE_DiscoveryPluginProperty_INITIALIZER; /* Configure properties */ discovery_plugin_properties.participant_liveliness_assert_period.sec = 5; discovery_plugin_properties.participant_liveliness_assert_period.nanosec = 0; discovery_plugin_properties.participant_liveliness_lease_duration.sec = 30; discovery_plugin_properties.participant_liveliness_lease_duration.nanosec = 0; /* Register DPSE with updated properties */ if (!RT_Registry_register(registry, "dpse", DPSE_DiscoveryFactory_get_interface(), &discovery_plugin_properties._parent, NULL)) { printf("failed to register dpse\n"); goto done; }
For more information, see the Application Generation Using XML section in the User’s Manual.