RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
rt_rt.h
1 /*
2  * FILE: rt_log.h - RT API
3  *
4  * Copyright 2011-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 15may2014,tk MICRO-791 Return RTI_INT32, not RTI_BOOL, in compare function
14  * 05may2014,tk MICRO-72 Updated based on CR-232
15  * 22apr2014,tk MICRO-82 Removed run method, kept base interface class
16  * 12dec2011,tk Written
17  */
18 /*ci
19  * \file
20  *
21  * \brief The Run-Time interface provides generic mechanism to handle
22  * extension to RTI Connext Micro.
23  *
24  * \defgroup RT_RunTimeClass RT
25  * \ingroup RTModule
26  *
27  * \details
28  *
29  * The Run-Time (RT) provides a basic mechanism to handle optional components.
30  * Components can be registered and looked up based on a name.
31  */
32 /*ci \addtogroup RT_RunTimeClass
33  * @{
34  */
35 #ifndef rt_rt_h
36 #define rt_rt_h
37 
38 #ifndef rt_dll_h
39 #include "rt/rt_dll.h"
40 #endif
41 
42 #ifndef osapi_types_h
43 #include "osapi/osapi_types.h"
44 #endif
45 
46 #ifndef osapi_timer_h
47 #include "osapi/osapi_timer.h"
48 #endif
49 
50 #ifndef reda_circularlist_h
51 #include "reda/reda_circularlist.h"
52 #endif
53 
54 #ifndef db_api_h
55 #include "db/db_api.h"
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 /*ci
64  * @}
65  */
66 #ifndef NULL
67 #define NULL ((void*)0)
68 #endif
69 
70 /*******************************************************************************
71  * RTConstants
72  ******************************************************************************/
73 #define RT_MKINTERFACEID(class_,instance_) \
74  ((((class_)<<16)&0xffff0000) | (instance_))
75 
76 #define RT_INTERFACE_CLASS(id_) ((id_) >> 16)
77 #define RT_INTERFACE_INSTANCE(id_) ((id_) & 0xffff)
78 
79 /* INTERFACE CLASSES */
80 #define RT_COMPONENT_CLASS_UNKNOWN (0x0000)
81 #define RT_COMPONENT_CLASS_DISCOVERY (0x0001)
82 #define RT_COMPONENT_CLASS_WHISTORY (0x0002)
83 #define RT_COMPONENT_CLASS_RHISTORY (0x0003)
84 #define RT_COMPONENT_CLASS_NETIO (0x0004)
85 
86 /* DDS Discovery class components */
87 #define RT_COMPONENT_INSTANCE_DISCOVERY_DPDE (1)
88 #define RT_COMPONENT_INSTANCE_DISCOVERY_DPSE (2)
89 #define RT_COMPONENT_INSTANCE_DISCOVERY_GROUP (3)
90 
91 /* DDS WriterHistory class components */
92 #define RT_COMPONENT_INSTANCE_WHISTORY_SM (1)
93 
94 /* DDS ReaderHistory class components */
95 #define RT_COMPONENT_INSTANCE_RHISTORY_SM (1)
96 
97 /* NETIO class components */
98 #define RT_COMPONENT_INSTANCE_UDP (1)
99 #define RT_COMPONENT_INSTANCE_RTPS (2)
100 #define RT_COMPONENT_INSTANCE_INTRA (3)
101 #define RT_COMPONENT_INSTANCE_DDSWI (4)
102 #define RT_COMPONENT_INSTANCE_DDSRI (5)
103 
104 /*ci \addtogroup RT_RunTimeClass
105  * @{
106  */
107 
108 /*ci
109  * \brief Type used to identify components
110  */
111 typedef RTI_UINT32 RT_ComponentInterfaceId_t;
112 
113 /*******************************************************************************
114  * RT_Component
115  ******************************************************************************/
116 struct RT_Component;
117 
118 /*ci
119  * \brief Abstract RT_Component type
120  */
121 typedef struct RT_Component RT_Component_T;
122 
123 /*ci
124  * \brief Notify listeners on changes in component state.
125  *
126  * \details
127  *
128  * The RT_ComponentListener structure is for future extensions.
129  */
130 struct RT_ComponentListener
131 {
132  /*ci
133  * \brief data passed in listeners
134  */
135  void *data;
136 };
137 
138 /*ci
139  * \brief Initializer for RT_ComponentListener
140  */
141 #define RT_ComponentListener_INITIALIZER \
142 { \
143  NULL \
144 }
145 
146 /*ci
147  * \brief Properties a component can be created with
148  */
149 struct RT_ComponentProperty
150 {
151  /*ci
152  * \brief A database to create tables in if needed
153  */
154  DB_Database_T db;
155 
156  /*ci
157  * \brief A timer to create timeouts from if needed
158  */
159  OSAPI_Timer_T timer;
160 };
161 
162 #define RT_ComponentProperty_INITIALIZER \
163 {\
164  NULL,\
165  NULL \
166 }
167 
168 /*ci
169  * \brief The component base interface
170  */
171 struct RT_ComponentI
172 {
173  /*ci
174  * \brief Some compilers do not allow empty structures. There are
175  * currently no base interface functions required
176  */
177  RTI_INT32 dummy;
178 };
179 
180 /*ci
181  * \brief The component base class
182  */
183 struct RT_Component
184 {
185  /*ci
186  *\brief All components are are linked together
187  */
188  REDA_CircularListNode_T _node;
189 
190  /*ci
191  *\brief Pointer to the component interface
192  */
193  struct RT_ComponentI *_intf;
194 
195  /*ci
196  *\brief Implementation specific flags
197  */
198  RTI_INT32 _flags;
199 
200  /*ci
201  *\brief The component ind
202  */
203  RTI_UINT32 id;
204 
205  /*ci
206  *\brief The listener specified when the component was created
207  */
208  struct RT_ComponentListener _listener;
209 
210  /*ci
211  *\brief The properties specified when the component was created
212  */
213  struct RT_ComponentProperty _property;
214 };
215 
216 /*ci
217  *
218  * \brief Initialize a RT_Component base-class
219  *
220  * \details
221  *
222  * All components must initialized the RT_Component base-class by
223  * calling this function
224  *
225  * \param[in] c The component to initialize
226  * \param[in] intf Pointer to implementation of the RT_ComponentI interface
227  * \param[in] id Unique ID for the component
228  * \param[in] property Properties for the component
229  * \param[in] listener Listeners to call when a component changes
230  *
231  * \sa \ref RT_Component_finalize
232  */
233 RTDllExport void
234 RT_Component_initialize(RT_Component_T *c,
235  struct RT_ComponentI *intf,
236  RTI_UINT32 id,
237  const struct RT_ComponentProperty *const property,
238  const struct RT_ComponentListener *const listener);
239 
240 /*ci
241  *
242  * \brief Finalize a RT_Component base-class
243  *
244  * \details
245  *
246  * All components must be finalized by calling this function
247  *
248  * \param[in] c The component to finalize
249  *
250  * \sa \ref RT_Component_initialize
251  */
252 RTDllExport void
253 RT_Component_finalize(RT_Component_T *c);
254 
255 #define RT_COMPONENTI_BASE {0}
256 
257 /*******************************************************************************
258  * RT_ComponentFactoryI
259  ******************************************************************************/
260 struct RT_ComponentFactory;
261 
262 /*ci
263  * \brief Properties a RT_ComponentFactory can be created with
264  */
265 struct RT_ComponentFactoryProperty
266 {
267  DB_Database_T db;
268 };
269 
270 /*ci
271  * \brief Initializer for \ref RT_ComponentFactoryProperty
272  */
273 #define RT_ComponentFactoryProperty_INITIALIZER \
274 { \
275  NULL\
276 }
277 
278 /*ci
279  * \brief Listeners that can be installed on a RT_ComponentFactoryProperty
280  * when it is created
281  */
282 struct RT_ComponentFactoryListener
283 {
284  void *dummy;
285 };
286 
287 /*ci
288  * \brief Initializer for \ref RT_ComponentFactoryListener
289  */
290 #define RT_ComponentFactoryListener_INITIALIZER \
291 {\
292  NULL\
293 }
294 
295 FUNCTION_MUST_TYPEDEF(
296 struct RT_ComponentFactory*
297 (*RT_ComponentFactory_initializeFactoryFunc)(
298  struct RT_ComponentFactoryProperty *property,
299  struct RT_ComponentFactoryListener *listener)
300 )
301 
302 typedef void
303 (*RT_ComponentFactory_finalizeFactoryFunc)(struct RT_ComponentFactory *factory,
304  struct RT_ComponentFactoryProperty **property,
305  struct RT_ComponentFactoryListener **listener);
306 
307 FUNCTION_MUST_TYPEDEF(
308 RT_Component_T*
309 (*RT_ComponentFactory_createFunc)(struct RT_ComponentFactory *factory,
310  struct RT_ComponentProperty *property,
311  struct RT_ComponentListener *listener)
312 )
313 
314 typedef void
315 (*RT_ComponentFactory_deleteFunc)(struct RT_ComponentFactory *factory,
316  RT_Component_T* component);
317 
318 FUNCTION_MUST_TYPEDEF(
319 struct RT_ComponentI*
320 (*RT_ComponentFactory_get_ifFunc)(struct RT_ComponentFactory *factory)
321 )
322 
323 #define RT_COMPONENT_FACTORY_ID_DEFAULT (0)
324 
325 /*ci
326  * \brief The RT_ComponentFactory interface
327  */
328 struct RT_ComponentFactoryI
329 {
330  /*ci
331  * \brief interface id
332  */
333  RTI_INT32 id;
334 
335  /*ci
336  * \brief function to call when the factory is first registered
337  */
338  RT_ComponentFactory_initializeFactoryFunc initialize;
339 
340  /*ci
341  * \brief function to call when the factory is unregistered
342  */
343  RT_ComponentFactory_finalizeFactoryFunc finalize;
344 
345  /*ci
346  * \brief function to call to create an new instance of a component
347  */
348  RT_ComponentFactory_createFunc create_component;
349 
350  /*ci
351  * \brief function to call to delete an instance of a component
352  */
353  RT_ComponentFactory_deleteFunc delete_component;
354 
355  /*ci
356  * \brief function to get the components interface implementation
357  */
358  RT_ComponentFactory_get_ifFunc get_if;
359 };
360 
361 #define RT_ComponentFactory_create_component(f_) ((f_)->intf)->create_component
362 
363 #define RT_ComponentFactory_delete_component(f_) ((f_)->intf)->delete_component
364 
365 #define RT_ComponentFactory_get_if(f_) ((f_)->intf)->get_if
366 
367 /*ci
368  * \def RT_MAX_FACTORY_NAME
369  * \brief Maximum length of a factory name, it does _not_ include \0
370  */
371 #define RT_MAX_FACTORY_NAME 7
372 
373 /*
374  * Structure to represent a compnent name as either a 64 bit integer
375  * or name
376  */
377 union RT_ComponentFactoryId
378 {
379  struct
380  {
381  char _name[RT_MAX_FACTORY_NAME+1];
382  } _name;
383  struct
384  {
385  RTI_UINT32 _high;
386  RTI_UINT32 _low;
387  } _value;
388 };
389 
390 /*
391  * Abstract type for the factory id
392  */
393 typedef union RT_ComponentFactoryId RT_ComponentFactoryId_T;
394 
395 /*ci
396  * \def RT_ComponentFactoryId_clear
397  *
398  * \brief Clear a factory id
399  */
400 #define RT_ComponentFactoryId_clear(id_) \
401  { (id_)->_value._high = 0; (id_)->_value._low = 0; }
402 
403 /*ci
404  * \brief A ComponentFactory base-class. All component factories must derive
405  * from this class
406  */
407 struct RT_ComponentFactory
408 {
409  struct RT_ComponentFactoryI *intf;
410  struct RT_ComponentFactory *_factory;
411  union RT_ComponentFactoryId _id;
412 };
413 
414 /*ci
415  * \brief Initializer for the \ref RT_ComponentFactory
416  */
417 #define RT_ComponentFactory_INITIALIZER \
418 { \
419  NULL,\
420  NULL,\
421  {{0,0}}\
422 }
423 
424 typedef struct RT_ComponentFactory RT_ComponentFactory_T;
425 
426 /*ci
427  * \brief Properties a \ref RT_Registry can be created with
428  */
429 struct RT_RegistryProperty
430 {
431  /*ci
432  * \brief The maximum number of component factories which can be registered
433  */
434  RTI_SIZE_T max_factories;
435 
436  /*ci
437  * \brief A database the component factory can use, if needed
438  */
439  DB_Database_T db;
440 };
441 
442 /*ci
443  * \brief Initializer for \ref RT_RegistryProperty
444  */
445 #define RT_RegistryProperty_INITIALIZER \
446 { \
447  1,\
448  NULL\
449 }
450 
451 /*ci
452  * \brief Default values for \ref RT_RegistryProperty
453  */
454 extern RTDllVariable struct RT_RegistryProperty
455  RTCOMPONENTFACTORY_REGISTRY_PROPERTY_DEFAULT;
456 
457 struct RT_Registry;
458 
459 /*ci
460  * \brief Abstract RT_Registry type
461  */
462 typedef struct RT_Registry RT_Registry_T;
463 
464 /*ci
465  * \brief Get the RT_Registry
466  *
467  * \details
468  *
469  * The RT_Registry exists as a single instance within a process.
470  *
471  * \return pointer to registry on success, NULL on failure
472  *
473  * \sa ref RT_Registry_finalize
474  */
475 SHOULD_CHECK_RETURN RTDllExport RT_Registry_T*
476 RT_Registry_get_instance(void);
477 
478 #ifndef RTI_CERT
479 /*ci
480  * \brief Finalize the RT_Registry
481  *
482  * \details
483  *
484  * The RT_Registry exists as a single instance within a process. This
485  * call finalizes the registry instance. If an already finalized registry
486  * is finalized again nothing is done.
487  *
488  * \return RTI_TRUE on success, RTI_FALSE on failure
489  *
490  * \sa ref RT_Registry_get_instance
491  */
492 SHOULD_CHECK_RETURN RTDllExport RTI_BOOL
493 RT_Registry_finalize(RT_Registry_T*);
494 #endif
495 
496 /*ci
497  * \brief Register a component factory
498  *
499  * \details
500  *
501  * In order to make a component available it is necessary to register
502  * a factory for the components. The factory is responsible for
503  * creating and deleting components. The name must be unqiue, if a factory
504  * already exists with the the name the call will fail.
505  *
506  * \param[in] registry Registry to register the component factory with
507  * \param[in] name The name of the component factory
508  * \param[in] intf Pointer to the implementation of the factory interface
509  * \param[in] property The properties to create the factory with
510  * \param[in] listener The listener to install with the factory
511 
512  * \return RTI_TRUE on success, RTI_FALSE on failure
513  *
514  * \sa ref RT_Registry_unregister
515  */
516 MUST_CHECK_RETURN RTDllExport RTI_INT32
517 RT_Registry_register(RT_Registry_T *registry,
518  const char *name,
519  struct RT_ComponentFactoryI *intf,
520  struct RT_ComponentFactoryProperty *property,
521  struct RT_ComponentFactoryListener *listener);
522 
523 /*ci
524  * \brief Unregister a component factory
525  *
526  * \details
527  *
528  * Remove a component factory from the registry. After it is unregistered
529  * it will no longer be possible to create or delete components from this
530  * factory.
531  *
532  * \param[in] registry Registry to register the component factory with
533  * \param[in] name The name of the component factory
534  * \param[out] property The properties the factory was created with
535  * \param[out] listener The listener to installed with the factory
536 
537  * \return RTI_TRUE on success, RTI_FALSE on failure
538  *
539  * \sa ref RT_Registry_register
540  */
541 SHOULD_CHECK_RETURN RTDllExport RTI_BOOL
542 RT_Registry_unregister(RT_Registry_T *registry,
543  const char *name,
544  struct RT_ComponentFactoryProperty **property,
545  struct RT_ComponentFactoryListener **listener);
546 
547 /*ci
548  * \brief Find a component factory based on the name
549  *
550  * \details
551  *
552  * This function is used to find a component based on its name.
553  *
554  * \param[in] registry Registry to search for the component factory in
555  * \param[in] name The name of the component factory to find
556 
557  * \return pointer to \ref RT_ComponentFactory on success, NULL on failure
558  *
559  * \sa ref RT_Registry_lookup_cid
560  */
561 MUST_CHECK_RETURN RTDllExport struct RT_ComponentFactory*
562 RT_Registry_lookup(RT_Registry_T *registry,const char *name);
563 
564 /*ci
565  * \brief Find a component factory based on the name and class id
566  *
567  * \details
568  *
569  * This function is used to find a component based on its name <em> and
570  * </em> the class id. If the name exists but is of the wrong class id
571  * NULL is returned.
572  *
573  * \param[in] registry Registry to search for the component factory in
574  * \param[in] name The name of the component factory to find
575  * \param[in] cid Component ID to choose from
576 
577  * \return pointer to \ref RT_ComponentFactory on success, NULL on failure
578  *
579  * \sa ref RT_Registry_lookup
580  */
581 MUST_CHECK_RETURN RTDllExport struct RT_ComponentFactory*
582 RT_Registry_lookup_cid(RT_Registry_T *registry,const char *name,RTI_INT32 cid);
583 
584 /*ci
585  * \brief Get the current properties for the registry
586  *
587  * \details
588  *
589  * This function returns the current properties for the registry
590  *
591  * \param[in] registry Registry to return properties for
592  * \param[out] property Current properties on successful return
593 
594  * \return RTI_TRUE on success, RTI_FALSE on failure
595  *
596  * \sa ref RT_Registry_set_property
597  */
598 MUST_CHECK_RETURN RTDllExport RTI_BOOL
599 RT_Registry_get_property(RT_Registry_T *registry,
600  struct RT_RegistryProperty *property);
601 
602 /*ci
603  * \brief Set the properties for the registry
604  *
605  * \details
606  *
607  * This function sets the properties for the registry. Note that the properties
608  * can only be changed until the first registration takes place.
609  *
610  * \param[in] registry Registry to set properties on
611  * \param[in] property New registry properties
612 
613  * \return RTI_TRUE on success, RTI_FALSE on failure
614  *
615  * \sa ref RT_Registry_get_property
616  */
617 MUST_CHECK_RETURN RTDllExport RTI_BOOL
618 RT_Registry_set_property(RT_Registry_T *registry,
619  struct RT_RegistryProperty *property);
620 
621 /*ci
622  * \brief Get the interface of a component factory
623  *
624  * \details
625  *
626  * Get the interface of a component factory
627  *
628  * \param[in] factory Factory to return id for
629  *
630  * \return Factory id
631  */
632 RTDllExport RTI_INT32
633 RT_ComponentFactory_get_id(struct RT_ComponentFactory *factory);
634 
635 /*ci
636  * \brief Initialize a RT_ComponentFactoryId_T based on the name
637  *
638  * \details
639  *
640  * Initialize a RT_ComponentFactoryId_T variable based on the name
641  *
642  * \param[in] id Id to initialize
643  * \param[in] name Name to initialize with
644  *
645  * \return Factory id
646  */
647 MUST_CHECK_RETURN RTDllExport RTI_BOOL
648 RT_ComponentFactoryId_set_name(RT_ComponentFactoryId_T *id,
649  const char *const name);
650 
651 /*ci
652  * \brief Return the component factory id as a name
653  *
654  * \details
655  *
656  * Return the component factory id as a name
657  *
658  * \param[in] id Id to return name from
659  *
660  * \return id as name
661  */
662 MUST_CHECK_RETURN RTDllExport const char*
663 RT_ComponentFactoryId_get_name(RT_ComponentFactoryId_T *id);
664 
665 /*ci
666  * \brief Compare a component factory id to a name
667  *
668  * \details
669  *
670  * Compare a component factory id to a name
671  *
672  * \param[in] id Id to compare
673  * \param[in] name Name to compare against
674  *
675  * \return RTI_TRUE if the id is equal to the name
676  */
677 MUST_CHECK_RETURN RTDllExport RTI_BOOL
678 RT_ComponentFactoryId_equals(RT_ComponentFactoryId_T *id,
679  const char *const name);
680 
681 /*ci
682  * \brief Compare a two component factory ids
683  *
684  * \details
685  *
686  * Compare a two component factory ids
687  *
688  * \param[in] id1 Left side of comparison
689  * \param[in] id2 Right side of comparison
690  *
691  * \return 0 if left = right, < 0 if left < right, > 0 if left > right
692  */
693 MUST_CHECK_RETURN RTDllExport RTI_INT32
694 RT_ComponentFactoryId_compare(const RT_ComponentFactoryId_T *id1,
695  const RT_ComponentFactoryId_T *id2);
696 
697 #ifdef __cplusplus
698 } /* extern "C" */
699 #endif
700 
701 #endif
702 
703 /*ci @} */

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