RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
ApplicationSupport.h
1 #ifndef ApplicationSupport_h
2 #define ApplicationSupport_h
3 
4 #include "rti_me_c.h"
5 #include "netio/netio_udp.h"
6 #include "disc_dpde/disc_dpde_discovery_plugin.h"
8 
9 /*i
10  * \addtogroup HWAppExModule_AppSupport
11  * @{
12  */
13 
14 /*i
15  * \brief Value returned by the application to the invoking
16  * shell in case of a successful execution.
17  */
18 #define APP_RETVAL_OK 0
19 /*i
20  * \brief Value returned by the application to the invoking
21  * shell in case of an unsuccessful execution.
22  */
23 #define APP_RETVAL_ERROR -1
24 
25 /*i
26  * \brief Value to indicate that an unlimited number
27  * of samples is expected to be written/received.
28  */
29 #define APP_COUNT_UNLIMITED -1
30 
31 struct Application;
32 typedef struct Application Application_t;
33 
34 /* e
35  * \brief User-defined function to read data when some is available.
36  */
37 typedef int (*Application_take_data_fn)(Application_t *application);
38 
39 /*i
40  * \brief Structure containing several configuration parameters exposed by
41  * the application.
42  *
43  * Each member of this data-type represents a custom configuration parameter
44  * that can be used to control the behavior of an application.
45  * Initialization of instances of this type should be carried out using
46  * \ref ApplicationConfig_INITIALIZER, for statically allocated values, or
47  * \ref ApplicationConfig_initialize, for dynamically allocated ones.
48  */
49 typedef struct ApplicationConfig {
50  /*i
51  * \brief DDS Domain ID to join.
52  *
53  * (default value: 0)
54  */
55  DDS_Long domain_id;
56  /*i
57  * \brief Whether the application should be publishing
58  * or subscribing to data.
59  *
60  * (default value: false)
61  */
62  DDS_Boolean publish;
63  /*i
64  * \brief Whether a subscribing application should
65  * wait for data by using a listener installed on
66  * the DataReader or by using a WaitSet instance
67  * with the DataReader's StatusCondition attached
68  * to it.
69  *
70  * (default value: false)
71  */
72  DDS_Boolean use_waitset;
73  /*i
74  * \brief Whether a subscribing application should
75  * filter data samples using callback
76  * on_before_sample_commit of a DataReader's listener.
77  *
78  * If this functionality is enabled, then \ref filter_deserialized
79  * must be disabled.
80  *
81  * (default value: false)
82  */
83  DDS_Boolean filter_commit;
84  /*i
85  * \brief Whether a subscribing application should
86  * filter data samples using callback
87  * on_before_sample_deserialize of a DataReader's listener.
88  *
89  * If this functionality is enabled, then \ref filter_commit
90  * must be disabled.
91  *
92  * (default value: false)
93  */
94  DDS_Boolean filter_deserialized;
95  /*i
96  * \brief Whether the application should use dynamic or
97  * static DDS discovery to detect other applications
98  * in the same DDS domain.
99  *
100  * (default value: true)
101  */
102  DDS_Boolean use_dynamic_discovery;
103  /*i
104  * \brief Whether the application should rely on automatic
105  * configuration of network interfaces based on information
106  * provided by the OS or it should instead statically configure
107  * the interface's parameters
108  *
109  * (default value: false)
110  */
111  DDS_Boolean use_static_interface;
112  /*i
113  * \brief A pointer to the TypePlugin to be used by the application.
114  *
115  * The TypePlugin is used to register the data type on the
116  * application's DomainParticipant.
117  *
118  * (default value: NULL)
119  */
120  struct NDDS_Type_Plugin *type_plugin;
121  /*i
122  * \brief Numerical ID of the DataWriter used by the application
123  * (if publishing).
124  *
125  * This value is used along with static
126  * DDS discovery, to identify the writer's end-point when
127  * statically asserting the existence of its remote publication.
128  *
129  * (default value: \ref DEFAULT_ENTITY_ID_WRITER)
130  */
131  DDS_BUILTIN_TOPIC_KEY_TYPE_NATIVE entity_id_writer;
132  /*i
133  * \brief Numerical ID of the DataReader used by the application
134  * (if subscribing).
135  *
136  * This value is used along with static
137  * DDS discovery, to identify the reader's end-point when
138  * statically asserting the existence of its remote subscription.
139  *
140  * (default value: \ref DEFAULT_ENTITY_ID_READER)
141  */
142  DDS_BUILTIN_TOPIC_KEY_TYPE_NATIVE entity_id_reader;
143  /*i
144  * \brief Name of the participant used by the application when publishing data.
145  *
146  * This value is used along with static DDS discovery, to identify
147  * the remote DomainParticipant and assert his existence.
148  *
149  * (default value: \ref DEFAULT_PART_NAME_WRITER)
150  */
151  DDS_Char part_name_writer[DDS_ENTITYNAME_QOS_NAME_MAX];
152  /*i
153  * \brief Name of the participant used by the application when subscribing data.
154  *
155  * This value is used along with static DDS discovery, to identify
156  * the remote DomainParticipant and assert his existence.
157  *
158  * (default value: \ref DEFAULT_PART_NAME_READER)
159  */
160  DDS_Char part_name_reader[DDS_ENTITYNAME_QOS_NAME_MAX];
161  /*i
162  * \brief Name of the topic that will be used by the application to exchange
163  * data.
164  *
165  * (default value: \ref DEFAULT_TOPIC_NAME)
166  */
167  DDS_Char topic_name[RTPS_PATHNAME_LEN_MAX+1];
168  /*i
169  * \brief Name of the type that will be used by the application.
170  *
171  * This is a custom name that is specified when a data-type's TypePlugin
172  * is registered on a DomainParticipant. It can be any non-empty value,
173  * but every DomainParticipant that wants to exchange samples through a
174  * topic of this type must have registered it with the same name in order
175  * for discovery and endpoint matching to be carried out successfully.
176  *
177  * (default value: \ref DEFAULT_TOPIC_NAME).
178  */
179  DDS_Char type_name[RTPS_PATHNAME_LEN_MAX+1];
180  /*i
181  * \brief Name of the loopback network interface that will be enabled for
182  * communication.
183  *
184  * (default value: \ref DEFAULT_INTERFACE_LOOP)
185  */
186  DDS_Char interface_loop[DDS_ENTITYNAME_QOS_NAME_MAX];
187  /*i
188  * \brief Name of the external network interface that will be enabled for
189  * communication.
190  *
191  * (default value: \ref DEFAULT_INTERFACE_UDP)
192  */
193  DDS_Char interface_udp[DDS_ENTITYNAME_QOS_NAME_MAX];
194  /*i
195  * \brief Address or hostname of a network peer that will be added to the
196  * list of peers initially contacted for DDS endpoint discovery.
197  *
198  * (default value: \ref DEFAULT_PEER)
199  */
201  /*i
202  * \brief Number of seconds between successive application operations.
203  *
204  * Used to determine:
205  * - Time between successive data sample writes.
206  * - Time-out of reading operations (when using \ref DDS_WaitSet_wait
207  * or when actively waiting for samples to be received by an
208  * asynchronous listener).
209  *
210  * (default value: \ref DEFAULT_SLEEP_SEC)
211  */
212  DDS_Long sleep_time;
213  /*i
214  * \brief Number of samples that an application must wait to
215  * write/receive before terminating
216  *
217  * (default value: \ref APP_COUNT_UNLIMITED)
218  */
219  DDS_Long count_expected;
220  /*i
221  * \brief QoS configuration for DDS_DomainParticipantFactory.
222  *
223  * (default value: \ref DDS_DomainParticipantFactoryQos_INITIALIZER)
224  */
225  struct DDS_DomainParticipantFactoryQos qos_factory;
226  /*i
227  * \brief QoS configuration for DDS_DomainParticipant.
228  *
229  * (default value: \ref DDS_DomainParticipantQos_INITIALIZER)
230  */
231  struct DDS_DomainParticipantQos qos_participant;
232  /*i
233  * \brief QoS configuration for DDS_DataReader.
234  *
235  * (default value: \ref DDS_DataReaderQos_INITIALIZER)
236  */
237  struct DDS_DataReaderQos qos_reader;
238  /*i
239  * \brief QoS configuration for DDS_DataWriter.
240  *
241  * (default value: \ref DDS_DataWriterQos_INITIALIZER)
242  */
243  struct DDS_DataWriterQos qos_writer;
244  /*i
245  * \brief DDS_DataReaderListener that will be installed on the
246  * DataReader used by the application.
247  *
248  * (default value: \ref DDS_DataReaderListener_INITIALIZER)
249  */
250  struct DDS_DataReaderListener listener_reader;
251  /*i
252  * \brief DDS_DataWriterListener that will be installed on the
253  * DataWriter used by the application.
254  *
255  * (default value: \ref DDS_DataWriterListener_INITIALIZER)
256  */
257  struct DDS_DataWriterListener listener_writer;
258  /*i
259  * \brief DDS_StatusMask used to install the configured DDS_DataReaderListener.
260  *
261  * (default value: \ref DDS_STATUS_MASK_NONE)
262  */
263  DDS_StatusMask listener_reader_mask;
264  /*i
265  * \brief DDS_StatusMask used to install the configured DDS_DataWriterListener.
266  *
267  * (default value: \ref DDS_STATUS_MASK_NONE)
268  */
269  DDS_StatusMask listener_writer_mask;
270  /*i
271  * \brief DDS_StatusMask used to enable statuses on the
272  * DataReader's StatusCondition when using a DDS_WaitSet
273  * to receive data or consume other DDS events.
274  *
275  * (default value: \ref DDS_STATUS_MASK_NONE)
276  */
277  DDS_StatusMask waitset_mask;
278  /*i
279  * \brief Call-back function provided by the user that will be invoked
280  * whenever new data samples are received.
281  *
282  * (default value: NULL)
283  */
284  Application_take_data_fn take_data;
285  /*i
286  * \brief Type-specific function used to determine whether a data-type
287  * has a key or is unkeyed. Required when asserting a remote
288  * subscription/publication to enable static endpoint discovery.
289  *
290  * (default value: NULL)
291  */
293 } ApplicationConfig_t;
294 
295 /*i
296  * \brief Default DDS domain ID
297  */
298 #define DEFAULT_DOMAIN_ID 0
299 
300 /*i
301  * \brief Default numerical ID of a DataWriter
302  */
303 #define DEFAULT_ENTITY_ID_WRITER 100
304 
305 /*i
306  * \brief Default numerical ID of a DataReader
307  */
308 #define DEFAULT_ENTITY_ID_READER 200
309 
310 /*i
311  * \brief Default name of a publishing DomainParticipant
312  */
313 #define DEFAULT_PART_NAME_WRITER "HelloWorldPublisher"
314 
315 /*i
316  * \brief Default name of a subscribing DomainParticipant
317  */
318 #define DEFAULT_PART_NAME_READER "HelloWorldSubscriber"
319 
320 /*i
321  * \brief Default name of the topic used by the application
322  */
323 #define DEFAULT_TOPIC_NAME "HelloWorldTopic"
324 
325 /*i
326  * \brief Default name of the data type used by the application
327  */
328 #define DEFAULT_TYPE_NAME "HelloWorldType"
329 
330 /*i
331  * \brief Default address of the network peer that will be initially
332  * contacted for DDS endpoint discovery.
333  */
334 #define DEFAULT_PEER "127.0.0.1"
335 
336 #if defined(RTI_DARWIN)
337 /*i
338  * \brief Default UDP network interface.
339  */
340 #define DEFAULT_UDP_INTERFACE "en1"
341 #elif defined (RTI_LINUX)
342 #define DEFAULT_UDP_INTERFACE "eth0"
343 #elif defined (RTI_VXWORKS)
344 #define DEFAULT_UDP_INTERFACE "geisc0"
345 #elif defined(RTI_WIN32)
346 #define DEFAULT_UDP_INTERFACE "Local Area Connection"
347 #else
348 #define DEFAULT_UDP_INTERFACE "ce0"
349 #endif
350 
351 #if defined(RTI_DARWIN)
352 /*i
353  * \brief Default loopback network interface.
354  */
355 #define DEFAULT_LOOP_INTERFACE "lo0"
356 #elif defined (RTI_LINUX)
357 #define DEFAULT_LOOP_INTERFACE "lo"
358 #elif defined (RTI_VXWORKS)
359 #define DEFAULT_LOOP_INTERFACE "lo0"
360 #elif defined(RTI_WIN32)
361 #define DEFAULT_LOOP_INTERFACE "Loopback Pseudo-Interface 1"
362 #else
363 #define DEFAULT_LOOP_INTERFACE "lo0"
364 #endif
365 
366 /*i
367  * \brief Default sleep_time in seconds.
368  */
369 #define DEFAULT_SLEEP_SEC 1
370 
371 /*i
372  * \brief Initialization value for statically allocated instances
373  * of \ref ApplicationConfig_t.
374  */
375 #define ApplicationConfig_INITIALIZER \
376 {\
377  DEFAULT_DOMAIN_ID,\
378  DDS_BOOLEAN_FALSE,\
379  DDS_BOOLEAN_FALSE,\
380  DDS_BOOLEAN_FALSE,\
381  DDS_BOOLEAN_FALSE,\
382  DDS_BOOLEAN_TRUE,\
383  DDS_BOOLEAN_FALSE,\
384  NULL,\
385  DEFAULT_ENTITY_ID_WRITER,\
386  DEFAULT_ENTITY_ID_READER,\
387  DEFAULT_PART_NAME_WRITER,\
388  DEFAULT_PART_NAME_READER,\
389  DEFAULT_TOPIC_NAME,\
390  DEFAULT_TYPE_NAME,\
391  DEFAULT_LOOP_INTERFACE,\
392  DEFAULT_UDP_INTERFACE,\
393  DEFAULT_PEER,\
394  DEFAULT_SLEEP_SEC,\
395  APP_COUNT_UNLIMITED,\
396  DDS_DomainParticipantFactoryQos_INITIALIZER,\
397  DDS_DomainParticipantQos_INITIALIZER,\
398  DDS_DataReaderQos_INITIALIZER,\
399  DDS_DataWriterQos_INITIALIZER,\
400  DDS_DataReaderListener_INITIALIZER,\
401  DDS_DataWriterListener_INITIALIZER,\
402  DDS_STATUS_MASK_NONE,\
403  DDS_STATUS_MASK_NONE,\
404  DDS_STATUS_MASK_NONE,\
405  NULL,\
406  NULL\
407 }
408 
409 /*i
410  * \brief Initializes an instance of \ref ApplicationConfig_t to its
411  * default values.
412  */
413 extern void
414 ApplicationConfig_initialize(ApplicationConfig_t *config);
415 
416 /*i
417  * \brief Finalizes an instance of \ref ApplicationConfig_t, releasing
418  * any memory allocated by its members.
419  */
420 extern void
421 ApplicationConfig_finalize(ApplicationConfig_t *config);
422 
423 /*i
424  * \brief Populates an instance of \ref ApplicationConfig_t using
425  * values passed by users through the command line.
426  */
427 extern DDS_Boolean
428 ApplicationConfig_parse_arguments(
429  ApplicationConfig_t *config, int argc, char** argv);
430 
431 /*i
432  * \brief Prints the contents of an instance of \ref ApplicationConfig_t
433  * to the standard output for debug purposes.
434  */
435 extern void
436 ApplicationConfig_print(ApplicationConfig_t *config);
437 
438 /*i
439  * \brief State of a generic DDS application.
440  *
441  * This data-type contains references to any resource/entity created by
442  * the application and required to carry out its functionalities.
443  * It is used to access these resources in the application code and to
444  * properly manage their life-cycle (i.e. finalizing them at shutdown).
445  */
446 typedef struct Application {
447  /*i
448  * \brief User-specified configuration
449  */
450  ApplicationConfig_t config;
451  /*i
452  * \brief Property used to initialize UDP transport
453  */
454  struct UDP_InterfaceFactoryProperty property_udp;
455  /*i
456  * \brief Property used to initialize DPDE module for dynamic DDS discovery.
457  */
458  struct DPDE_DiscoveryPluginProperty property_dpde;
459  /*i
460  * \brief Property used to initialize DPSE module for static DDS discovery.
461  */
462  struct DPSE_DiscoveryPluginProperty property_dpse;
463  /*i
464  * \brief Value used to assert the existence of a remote publication, when
465  * using static DDS discovery.
466  */
467  struct DDS_PublicationBuiltinTopicData rem_publication_data;
468  /*i
469  * \brief Value used to assert the existence of a remote subscription, when
470  * using static DDS discovery.
471  */
472  struct DDS_SubscriptionBuiltinTopicData rem_subscription_data;
473  /*
474  * \brief DDS_DomainParticipant used to access a DDS domain.
475  */
476  DDS_DomainParticipant *participant;
477  /*i
478  * \brief DDS_Publisher used to create DDS_DataWriter endpoints.
479  */
480  DDS_Publisher *publisher;
481  /*i
482  * \brief DDS_Subscriber used to create DDS_DataReader endpoints.
483  */
484  DDS_Subscriber *subscriber;
485  /*i
486  * \brief DDS_Topic used to communicate between remote applications.
487  */
488  DDS_Topic *topic;
489  /*i
490  * \brief DDS_DataReader used to received data from the DDS domain.
491  */
492  DDS_DataReader *reader;
493  /*i
494  * \brief DDS_DataWriter used to publish data to the DDS domain.
495  */
496  DDS_DataWriter *writer;
497  /*i
498  * \brief DDS_WaitSet used to wait for data to be received
499  * from the DDS domain.
500  */
501  DDS_WaitSet *waitset;
502  /*i
503  * \brief DDS_StatusCondition of the DDS_DataReader.
504  */
505  DDS_StatusCondition *condition_dr;
506  /*i
507  * \brief Sequence of DDS_Condition used to store the result of
508  * DDS_WaitSet_wait, when waiting for data to be received.
509  */
510  struct DDS_ConditionSeq active_conditions;
511  /*i
512  * \brief Current number of data-samples that have been processed
513  * (written/received) by the application so far.
514  */
515  DDS_Long count_processed;
516 } Application_t;
517 
518 
519 /*i
520  * \brief Creates a new instance of \ref Application_t and initializes
521  * it using the specified configuration.
522  */
523 extern Application_t*
524 Application_create(ApplicationConfig_t *config);
525 
526 /*i
527  * \brief Deletes an instance of \ref Application_t created using
528  * \ref Application_create.
529  */
530 extern void
531 Application_delete(Application_t *application);
532 
533 /*i
534  * \brief Enables the DDS entities of an application
535  */
536 extern DDS_Boolean
537 Application_enable(Application_t *application);
538 
539 /*i
540  * \brief Blocks the invoking thread until new data samples have been received.
541  */
542 extern void
543 Application_wait_for_data(Application_t *application);
544 
545 /*i
546  * \brief Prints help text for the application to standard output
547  */
548 extern void
549 Application_help(char *appname);
550 
551 /*i
552  * \brief Implementation of \ref DDS_DataReaderListener::on_data_available
553  */
554 extern void
555 Application_ListenerHelper_on_data_available(
556  void *listener_data,
557  DDS_DataReader * reader);
558 
559 /*i
560  * \brief Implementation of \ref DDS_DataReaderListener::on_subscription_matched
561  */
562 extern void
563 Application_ListenerHelper_on_subscription_matched(
564  void *listener_data,
565  DDS_DataReader * reader,
566  const struct
568 
569 /*i
570  * \brief Implementation of \ref DDS_DataWriterListener::on_publication_matched
571  */
572 extern void
573 Application_ListenerHelper_on_publication_matched(
574  void *listener_data,
575  DDS_DataWriter * writer,
576  const struct DDS_PublicationMatchedStatus *status);
577 
578 /*i
579  * @}
580  */
581 
582 #endif

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc