RTI Connext DDS Micro  Version 2.4.11
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
osapi_system.h
Go to the documentation of this file.
1 /*
2  * FILE: osapi_system.h - Definition of System API
3  *
4  * Copyright 2012-2015 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  * 15jul2015,tk MICRO-1426/PR#15358 Added support for OSAPI_System_get_ticktime
14  * 22mar2014,tk Updated API and documentation
15  * 01deb2014,tk MICRO-716: Abstract system API
16  * 12mar2012,tk Written
17  */
18 /*ce
19  * \file
20  * \brief System API definition
21  */
22 #ifndef osapi_system_h
23 #define osapi_system_h
24 
25 #ifndef osapi_dll_h
26 #include "osapi/osapi_dll.h"
27 #endif
28 #ifndef osapi_time_h
29 #include "osapi/osapi_time.h"
30 #endif
31 #ifndef osapi_timer_h
32 #include "osapi/osapi_timer.h"
33 #endif
34 #ifndef osapi_semaphore_h
35 #include "osapi/osapi_semaphore.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42 
43 #define OSAPI_SYSTEM_MAX_HOSTNAME (64)
44 
45 struct OSAPI_System;
46 
47 /*ci
48  * \brief The first object-id returned by OSAPI_System_get_next_object_id()
49  */
50 #define OSAPI_SYSTEM_OBJECTID_START 0x01000000
51 
52 /*ci
53  * \brief The maximum returned valid object-id from
54  * OSAPI_System_get_next_object_id() is OSAPI_SYSTEM_OBJECTID_MAX-1.
55  */
56 #define OSAPI_SYSTEM_OBJECTID_MAX 0x7fffffff
57 
58 /*e \defgroup OSAPI_SystemClass OSAPI System
59  * \ingroup OSAPIModule
60  * \brief Abstract System API.
61  *
62  * \details
63  *
64  * The System is defined as the physical or virtual
65  * execution environment and implements functions that are not necessarily
66  * provided by the operating system. For example, a custom embedded board may
67  * include a special real-time clock which is synchronized via GPS, but is
68  * not available via a regular OS system call.
69  */
70 
71 /*e \ingroup OSAPI_SystemClass
72  *
73  * start timer definition
74  */
75 FUNCTION_MUST_TYPEDEF(
76 RTI_BOOL
77 (*OSAPI_System_start_timer_T)(OSAPI_Timer_T self,
78  OSAPI_TimerTickHandlerFunction tick_handler)
79 )
80 
81 /*e \ingroup OSAPI_SystemClass
82  *
83  * stop timer definition
84  */
85 FUNCTION_SHOULD_TYPEDEF(
86 RTI_BOOL
87 (*OSAPI_System_stop_timer_T)(OSAPI_Timer_T self)
88 )
89 
90 /*e \ingroup OSAPI_SystemClass
91  *
92  * get timer resolution
93  */
94 FUNCTION_SHOULD_TYPEDEF(
95 RTI_INT32
97 )
98 
99 /*e \ingroup OSAPI_SystemClass
100  *
101  * get time
102  */
103 FUNCTION_SHOULD_TYPEDEF(
104 RTI_BOOL
106 )
107 
108 /*e \ingroup OSAPI_SystemClass
109  *
110  * initialize
111  */
112 FUNCTION_SHOULD_TYPEDEF(
113 RTI_BOOL
115 )
116 
117 /*e \ingroup OSAPI_SystemClass
118  *
119  * finalize
120  */
121 FUNCTION_SHOULD_TYPEDEF(
122 RTI_BOOL
124 )
125 
126 /*e \ingroup OSAPI_SystemClass
127  *
128  * get_hostname
129  */
130 FUNCTION_MUST_TYPEDEF(
131 RTI_BOOL
132 (*OSAPI_System_get_hostname_T)(char *const hostname)
133 )
134 
135 struct OSAPI_SystemUUID;
136 
137 FUNCTION_MUST_TYPEDEF(
138 RTI_BOOL
139 (*OSAPI_System_generate_uuid_T)(struct OSAPI_SystemUUID *uuid_out);
140 )
141 
142 FUNCTION_MUST_TYPEDEF(
143 RTI_BOOL
144 (*OSAPI_System_get_ticktime_T)(RTI_INT32 *sec,RTI_UINT32 *nanosec);
145 )
146 
147 /*e \ingroup OSAPI_SystemClass
148  *
149  * System Interface class
150  *
151  * The methods in this interface are called by the corresponding
152  * OSAPI_System function. For example, OSAPI_System_get_time() calls
153  * system->get_time().
154  *
155  */
157 {
158  /*e \ingroup OSAPI_SystemClass
159  *
160  * Refer to \ref OSAPI_System_start_timer for signature
161  * and semantics.
162  */
164 
165  /*e \ingroup OSAPI_SystemClass
166  *
167  * Refer to \ref OSAPI_System_stop_timer for signature
168  * and semantics.
169  */
171 
172  /*e \ingroup OSAPI_SystemClass
173  *
174  * Refer to \ref OSAPI_System_get_timer_resolution for signature
175  * and semantics.
176  */
178 
179  /*e \ingroup OSAPI_SystemClass
180  *
181  * Refer to \ref OSAPI_System_get_time for signature
182  * and semantics.
183  */
185 
186  /*e \ingroup OSAPI_SystemClass
187  *
188  * Refer to \ref OSAPI_System_initialize for signature
189  * and semantics.
190  */
192 
193  /*e \ingroup OSAPI_SystemClass
194  *
195  * Refer to \ref OSAPI_System_finalize for signature
196  * and semantics.
197  */
199 
200  /*e \ingroup OSAPI_SystemClass
201  *
202  * Refer to \ref OSAPI_System_generate_uuid for signature
203  * and semantics.
204  */
205  OSAPI_System_generate_uuid_T generate_uuid;
206 
207  /*e\ingroup OSAPI_SystemClass
208  *
209  * Refer to \ref OSAPI_System_get_hostname for signature
210  * and semantics.
211  */
213 
214  /*e\ingroup OSAPI_SystemClass
215  *
216  * Refer to \ref OSAPI_System_get_ticktime for signature
217  * and semantics.
218  */
219  OSAPI_System_get_ticktime_T get_ticktime;
220 };
221 
222 #define OSAPI_SystemI_INITIALIZER \
223 {\
224  NULL,\
225  NULL,\
226  NULL,\
227  NULL,\
228  NULL,\
229  NULL,\
230  NULL,\
231  NULL,\
232  NULL\
233 }
234 
235 extern OSAPIDllVariable struct OSAPI_System *OSAPI_System_gv_System;
236 
237 /*e \ingroup OSAPI_SystemClass
238  * \brief Set system interface
239  *
240  * \details
241  * This function sets the system interface, overriding the current system
242  * interface.
243  *
244  * \param [in] intf - The new system interface
245  *
246  * \return RTI_TRUE on success, RTI_FALSE on failure.
247  */
248 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
250 
251 /*e \ingroup OSAPI_SystemClass
252  * \brief Get the current system interface
253  *
254  * \details
255  * This function returns the current system interface
256  *
257  * \param [out] intf - The current system interface
258  *
259  * \return RTI_TRUE on success, RTI_FALSE on failure.
260  */
261 SHOULD_CHECK_RETURN OSAPIDllExport RTI_BOOL
263 
264 /*e \ingroup OSAPI_SystemClass
265  *
266  * System listener
267  */
268 FUNCTION_MUST_TYPEDEF(
269 RTI_BOOL
270 (*OSAPI_System_on_system_initialize_T)(void *listener_data,struct OSAPI_System *system)
271 )
272 
273 typedef void
274 (*OSAPI_System_on_system_finalize_T)(void *listener_data,struct OSAPI_System *system);
275 
276 /*e \ingroup OSAPI_SystemClass
277  *
278  * System listener
279  */
281 {
282  void *listener_data;
283  OSAPI_System_on_system_initialize_T on_system_initialize;
284  OSAPI_System_on_system_finalize_T on_system_finalize;
285 };
286 
287 #define OSAPI_SystemListener_INITIALIZER \
288 {\
289  NULL,\
290  NULL,\
291  NULL,\
292 }
293 
294 /*e \ingroup OSAPI_SystemClass
295  * \brief Install a system listeners
296  *
297  * \details
298  *
299  * The system listeners are called during the life-time of the system.
300  * Only listeners which are non-NULL are called, thus it is ok to install
301  * a partially set listener structure. System listeners can be installed
302  * until the system has been initialized by calling OSAPI_System_initialize.
303  * This function is not considered thread-safe. The listener value should
304  * always be initialized with OSAPI_SystemListener_DEFAULT before use.
305  *
306  * \param [in] listener System listeners to call
307  *
308  * \return RTI_TRUE on success, RTI_FALSE on failure
309  */
310 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
312 
313 /*e \ingroup OSAPI_SystemClass
314  * \brief Get current system listeners
315  *
316  * \details
317  * Return the current set of system listeners. This function is not thread-safe.
318  *
319  * \param[in] listener System listener structure to fill in.
320  *
321  * \return RTI_TRUE on success, RTI_FALSE on failure.
322  */
323 SHOULD_CHECK_RETURN OSAPIDllExport RTI_BOOL
325 
326 /*e \ingroup OSAPI_SystemClass
327  *
328  * System properties
329  */
331 {
332  /*e
333  * \brief Set the timer properties
334  */
336 
337  /*e
338  * \brief Set the hostname for the node.
339  *
340  * \details
341  * \rtime uses this name when it announces itself on the
342  * network. This name is used by other RTI products. The
343  * hostname must not exceed OSAPI_SYSTEM_MAX_HOSTNAME,
344  * including the \0 character.
345  */
346  char hostname[OSAPI_SYSTEM_MAX_HOSTNAME];
347 };
348 
349 #define OSAPI_SystemProperty_INITIALIZER \
350 {\
351  OSAPI_TimerProperty_INITIALIZER,\
352  {0}\
353 }
354 
355 /*e \ingroup OSAPI_SystemClass
356  * \brief UUID definition
357  *
358  * Abstract UUID object,a 128-bit value.
359  */
361 {
362  RTI_UINT32 value[4];
363 };
364 
365 struct OSAPI_System;
366 
367 /*e \ingroup OSAPI_SystemClass
368  * \brief Generate a unique universal identifier (UUID)
369  *
370  * \param [out] uuid_out The generated UUID value
371  *
372  * \return RTI_TRUE on success, RTI_FALSE on failure
373  */
374 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
376 
377 /*e \ingroup OSAPI_SystemClass
378  * \brief Get the current system time.
379  *
380  * \details
381  * In general, the system time is used by components to correlate both
382  * internal and external events, such as data reception and ordering. Thus,
383  * it is recommended that this function returns the real time. However, it is not
384  * strictly required.
385  *
386  * Notes:
387  * - It is assumed that the time returned by get_time is monotonically
388  * increasing. It is up to the implementation of this function to ensure
389  * this holds true.
390  * - It is ok to return the same time as the last call.
391  * - The clock used to report real-time can be different than the clock used to
392  * support start_timer and stop_timer.
393  *
394  * @param [out] now Time in NtpTime format.
395  *
396  * @return RTI_TRUE on success, RTI_FALSE on failure.
397  *
398  * @pre Initialized system.
399  *
400  * @exception None.
401  */
402 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
404 
405 /*e \ingroup OSAPI_SystemClass
406  * \brief Get the resolution of the clock driving the timer in nano seconds.
407  *
408  * \details
409  *
410  * This function must return the frequency of the system timer used to implement
411  * OSAPI_SystemI::start_timer and OSAPI_SystemI::stop_timer API.
412  *
413  * @return timer resolution in nanoseconds.
414  */
415 OSAPIDllExport RTI_INT32
417 
418 /*e \ingroup OSAPI_SystemClass
419  *
420  * \brief Start the timer.
421  *
422  * @param [in] self Timer object.
423  * @param [in] tick_handler Timer handle.
424  *
425  * @pre Initialized system.
426  */
427 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
428 OSAPI_System_start_timer(OSAPI_Timer_T self,
429  OSAPI_TimerTickHandlerFunction tick_handler);
430 
431 /*e \ingroup OSAPI_SystemClass
432  * \brief Stop the timer.
433  *
434  * @param [in] self Timer
435  *
436  * @return RTI_TRUE on success, RTI_FALSE on failure.
437  *
438  * @pre Initialized system.
439  */
440 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
441 OSAPI_System_stop_timer(OSAPI_Timer_T self);
442 
443 /*e \ingroup OSAPI_SystemClass
444  * \brief Initialize the system.
445  *
446  * \details
447  *
448  * This function initializes the system and calls the port specific initialize
449  * method first. The port specific initialization method must return RTI_TRUE
450  * on success and RTI_FALSE on failure. A system can only be initialized once.
451  *
452  * @return RTI_TRUE on success, RTI_FALSE on failure.
453  */
454 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
456 
457 #ifndef RTI_CERT
458 /*e \ingroup OSAPI_SystemClass
459  \brief Finalize the system.
460 
461  \details
462 
463  This function finalizes the system and calls the port specific finalize
464  method last. The port specific initialization method must return RTI_TRUE
465  on success and RTI_FALSE on failure.
466 
467  @return RTI_TRUE on success, RTI_FALSE on failure.
468 */
469 SHOULD_CHECK_RETURN OSAPIDllExport RTI_BOOL
471 #endif /* !RTI_CERT */
472 
473 /*e \ingroup OSAPI_SystemClass
474  * \brief Get the system properties
475  *
476  * @param [out] property
477  *
478  * @return RTI_TRUE on success, RTI_FALSE on failure.
479  */
480 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
482 
483 /*e \ingroup OSAPI_SystemClass
484  * \brief Set the system properties.
485  *
486  * \details
487  * The system properties can be set until the system is initialized by
488  * calling \ref OSAPI_System_initialize()
489  *
490  * @param [in] property
491  *
492  * @return RTI_TRUE on success, RTI_FALSE on failure.
493  */
494 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
496 
497 /*e \ingroup OSAPI_SystemClass
498  * \brief Get the native system interface
499  *
500  * \details
501  *
502  * This function must fill in the interface structure and assign the
503  * following methods:
504  *
505  * <ul>
506  * <li> \ref OSAPI_SystemI::get_timer_resolution
507  * <li> \ref OSAPI_SystemI::get_time
508  * <li> \ref OSAPI_SystemI::start_timer
509  * <li> \ref OSAPI_SystemI::stop_timer
510  * <li> \ref OSAPI_SystemI::generate_uuid
511  * <li> \ref OSAPI_SystemI::get_hostname
512  * <li> \ref OSAPI_SystemI::initialize
513  * <li> \ref OSAPI_SystemI::finalize
514  * <li> \ref OSAPI_SystemI::get_ticktime
515  * </ul>
516  *
517  * @param [out] intf The native system interface
518  */
519 OSAPIDllExport void
521 
522 /*e \ingroup OSAPI_SystemClass
523  *
524  * \brief Return next object ID
525  *
526  * \details
527  * This function return the next available object if. Object Id are never
528  * reused, thus it is possible to run out of object ids.
529  *
530  * \return new object on success, -1 on failure
531  */
532 OSAPIDllExport RTI_INT32
534 
535 /*e \ingroup OSAPI_SystemClass
536  * \brief Get the hostname
537  *
538  * \details
539  * Get the hostname
540  *
541  * @param [out] hostname The buffer to store the hostname. Must be at
542  * least OSAPI_SYSTEM_MAX_HOSTNAME bytes. If the
543  * actual hostname is longer than
544  * OSAPI_SYSTEM_MAX_HOSTNAME bytes (including \0) the
545  * hostname is truncated.
546  *
547  * @pre Initialized system.
548  *
549  * @exception None.
550  *
551  * @return RTI_TRUE on success, RTI_FALSE on failure.
552  *
553  * @mtsafety SAFE
554  */
555 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
556 OSAPI_System_get_hostname(char *const hostname);
557 
558 
559 /*e \ingroup OSAPI_SystemClass
560  *
561  * \brief Get current tick time
562  *
563  * \details
564  *
565  * The ticktime is a time measurement used by Micro to determine how much
566  * time has elapsed in a period. It does not have to be an absolute time,
567  * but it _must_ be monotonically increasing. For this reason it is important
568  * to choose the time source with care. For example, the system time may
569  * mbe adjusted backward or forward and this could affect the measure time
570  * lapse. The resolution of the tick time is expected to be no less than the
571  * system timer, although it is not a requirement.
572  *
573  * @param[out] sec The current ticktime in seconds
574  *
575  * @param[out] nanosec Additional nanoseconds in the current ticktime
576  *
577  * @pre Initialized system.
578  *
579  * @return RTI_TRUE on success, RTI_FALSE on failure.
580  */
581 MUST_CHECK_RETURN OSAPIDllExport RTI_BOOL
582 OSAPI_System_get_ticktime(RTI_INT32 *sec,RTI_UINT32 *nanosec);
583 
584 /*e \ingroup OSAPI_SystemClass
585  *
586  * \brief Get a semaphore to suspend a thread
587  *
588  * \return A semaphore on success, NULL on failure.
589  */
590 MUST_CHECK_RETURN OSAPIDllExport OSAPI_Semaphore_T*
592 
593 /*e \ingroup OSAPI_SystemClass
594  *
595  * \brief Return a semaphore acquired with \ref OSAPI_System_get_thread_semaphore
596  *
597  * \param[in] sem Semaphore to return
598  */
599 OSAPIDllExport void
601 
602 
603 #ifdef __cplusplus
604 } /* extern "C" */
605 #endif
606 
607 #endif /* osapi_system_h */

RTI Connext DDS Micro Version 2.4.11 Copyright © Mon Jul 23 2018 Real-Time Innovations, Inc