/* * (c) Copyright, Real-Time Innovations, 2023-2024. * All rights reserved. * * No duplications, whole or partial, manual or electronic, may be made * without express written permission. Any such copies, or * revisions thereof, must display this notice unaltered. * This code contains trade secrets of Real-Time Innovations, Inc. */ #ifndef osapi_rtpsTime_h #define osapi_rtpsTime_h #include "osapi/osapi_ntptime.h" #ifdef __cplusplus extern "C" { #endif /** @internal * \file * \brief RTPS time and duration. */ typedef struct RTIRtpsDuration { /** @internal Seconds.**/ RTI_INT32 sec; /** @internal fraction of a second in 1/2^32 form.*/ RTI_UINT32 frac; } RTIRtpsDuration; /** @internal * \ingroup RTIRtpsClass * * The infinite number of seconds that can be represented using RTPS duration. * This value is defined by the standard. */ #define RTI_RTPS_DURATION_SEC_INFINITE 0x7fffffff /** @internal * \ingroup RTIRtpsClass * * The infinite value of the fraction field in RTPS duration. This * value is defined by the standard. */ #define RTI_RTPS_DURATION_FRAC_INFINITE ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * Represents infinite timevalue that can be represented using the * RTPS duration format. This value is defined by the standard. */ #define RTI_RTPS_DURATION_INFINITE \ { \ RTI_RTPS_DURATION_SEC_INFINITE, RTI_RTPS_DURATION_FRAC_INFINITE \ } /** @internal * \ingroup RTIRtpsClass * * The maximum number of seconds that can be represented using RTPS duration. */ #define RTI_RTPS_DURATION_SEC_MAX ((RTI_INT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The largest possible value of the fraction field in RTPS duration. */ #define RTI_RTPS_DURATION_FRAC_MAX ((RTI_UINT32) 0xfffffffe) /** @internal * \ingroup RTIRtpsClass * * Represents maximum timevalue that can be represented using the * RTPS duration format. */ #define RTI_RTPS_DURATION_MAX \ { \ RTI_RTPS_DURATION_SEC_MAX, RTI_RTPS_DURATION_FRAC_MAX \ } /** @internal * \ingroup RTIRtpsClass * * The number of seconds corresponding to RTI_RTPS_DURATION_AUTO. */ #define RTI_RTPS_DURATION_SEC_AUTO ((RTI_INT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The fraction of seconds corresponding to RTI_RTPS_DURATION_AUTO. */ #define RTI_RTPS_DURATION_FRAC_AUTO 0U /** @internal * \ingroup RTIRtpsClass * * The AUTO value semantic depends on the usage. */ #define RTI_RTPS_DURATION_AUTO \ { \ RTI_RTPS_DURATION_SEC_AUTO, RTI_RTPS_DURATION_FRAC_AUTO \ } /** @internal * \ingroup RTIRtpsClass * * The number of seconds corresponding to RTI_RTPS_DURATION_INVALID. This * value is defined by the standard. */ #define RTI_RTPS_DURATION_SEC_INVALID ((RTI_INT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The fraction of seconds corresponding to RTI_RTPS_DURATION_INVALID. This * value is defined by the standard. */ #define RTI_RTPS_DURATION_FRAC_INVALID ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The INVALID value semantic depends on the usage. This value is defined by the * standard. */ #define RTI_RTPS_DURATION_INVALID \ { \ RTI_RTPS_DURATION_SEC_INVALID, RTI_RTPS_DURATION_FRAC_INVALID \ } /** @internal \ingroup RTIRtpsClass * * @brief Compare two RTIRtpsDuration. * * @param dur1 RTIRtpsDuration. * @param dur2 RTIRtpsDuration. * * @return If dur1 > dur2 then return 1. If dur1 < dur2 then return -1. * If dur1 == dur2 then return 0. */ extern RTIOsapiDllExport int RTIRtpsDuration_compare( const struct RTIRtpsDuration dur1, const struct RTIRtpsDuration dur2); /** @internal \ingroup RTIRtpsClass * * @brief Copy a RTIRtpsDuration from dIn to dOut. * * @param dOut RTIRtpsDuration, NOT NULL. * @param dIn RTIRtpsDuration, NOT NULL. */ extern RTIOsapiDllExport void RTIRtpsDuration_copy( struct RTIRtpsDuration *dOut, const struct RTIRtpsDuration *dIn); /** @internal * \ingroup RTIRtpsClass * * NULL RTIRtpsDuration pointer is considered infinity. This is consistent * with the concept of infinite time on UNIX. * * In addition, if the seconds field equals, or is above * RTI_RTPS_DURATION_SEC_INFINITE, the duration value is also considered * infinite. * * @param duration Pointer to RTIRtpsDuration. * * @return RTI_TRUE if duration is infinite, RTI_FALSE otherwise. */ extern RTIOsapiDllExport RTIBool RTIRtpsDuration_isInfinite(const struct RTIRtpsDuration *duration); /** @internal * \ingroup RTIRtpsClass * * @param duration Pointer to RTIRtpsDuration. * * @return RTI_TRUE if duration is AUTO, RTI_FALSE otherwise. * */ extern RTIOsapiDllExport RTIBool RTIRtpsDuration_isAuto(const struct RTIRtpsDuration *duration); /** @internal * \ingroup RTIRtpsClass * * Checks if the duration structure represents an invalid duration. * * @param duration Pointer to RTIRtpsDuration. * * @return RTI_TRUE if duration is invalid, RTI_FALSE otherwise. */ extern RTIOsapiDllExport RTIBool RTIRtpsDuration_isInvalid(const struct RTIRtpsDuration *duration); /** @internal * \ingroup RTIRtpsClass * @brief Convert RTINtpTime to RTIRtpsDuration. * * @param rtpsDuration (RTIRtpsDuration *) Pointer to RTIRtpsDuration struct * that is going to be converted. * @param time (RTINtpTime *) Pointer to RTINtpTime struct that needs to be * converted. */ extern RTIOsapiDllExport void RTIRtpsDuration_fromNtptime( struct RTIRtpsDuration *rtpsDuration, const struct RTINtpTime *time); /** @internal * \ingroup RTIRtpsClass * @brief Convert RTIRtpsDuration to RTINtpTime. * * @param time (RTINtpTime *) Pointer to RTINtpTime struct that is going to be * converted. * @param rtpsDuration (RTIRtpsDuration *) Pointer to RTIRtpsDuration struct * that needs to be converted. */ extern RTIOsapiDllExport void RTIRtpsDuration_toNtptime( const struct RTIRtpsDuration *rtpsDuration, struct RTINtpTime *time); typedef struct RTIRtpsTime { /** @internal Seconds.**/ RTI_UINT32 sec; /** @internal fraction of a second in 1/2^32 form.*/ RTI_UINT32 frac; } RTIRtpsTime; /** @internal * \ingroup RTIRtpsClass * * The infinite number of seconds that can be represented using RTPS time. This * value is defined by the standard. */ #define RTI_RTPS_TIME_SEC_INFINITE ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The infinite value of the fraction field in RTPS time. This * value is defined by the standard. */ #define RTI_RTPS_TIME_FRAC_INFINITE ((RTI_UINT32) 0xfffffffe) /** @internal * \ingroup RTIRtpsClass * * Represents infinite timevalue that can be represented using the * RTPS time format. This value is defined by the standard. */ #define RTI_RTPS_TIME_INFINITE \ { \ RTI_RTPS_TIME_SEC_INFINITE, RTI_RTPS_TIME_FRAC_INFINITE \ } /** @internal * \ingroup RTIRtpsClass * * The maximum number of seconds that can be represented using RTPS time. */ #define RTI_RTPS_TIME_SEC_MAX ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The largest possible valid value of the fraction field in RTPS time. */ #define RTI_RTPS_TIME_FRAC_MAX ((RTI_UINT32) 0xfffffffe) /** @internal * \ingroup RTIRtpsClass * * Represents maximum timevalue that can be represented using the * RTPS time format. */ #define RTI_RTPS_TIME_MAX \ { \ RTI_RTPS_TIME_SEC_MAX, RTI_RTPS_TIME_FRAC_MAX \ } /** @internal * \ingroup RTIRtpsClass * * The number of seconds corresponding to RTI_RTPS_TIME_INVALID. */ #define RTI_RTPS_TIME_SEC_INVALID ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The fraction of seconds corresponding to RTI_RTPS_TIME_INVALID. */ #define RTI_RTPS_TIME_FRAC_INVALID ((RTI_UINT32) 0xffffffff) /** @internal * \ingroup RTIRtpsClass * * The INVALID value semantic depends on the usage. Share the same values with * RTI_RTPS_TIME_AUTO. */ #define RTI_RTPS_TIME_INVALID \ { \ RTI_RTPS_TIME_SEC_INVALID, RTI_RTPS_TIME_FRAC_INVALID \ } /** @internal * \ingroup RTIRtpsClass * * The number of seconds corresponding to RTI_RTPS_TIME_AUTO. */ #define RTI_RTPS_TIME_SEC_AUTO RTI_RTPS_TIME_SEC_INVALID /** @internal * \ingroup RTIRtpsClass * * The fraction of seconds corresponding to RTI_RTPS_TIME_AUTO. */ #define RTI_RTPS_TIME_FRAC_AUTO RTI_RTPS_TIME_FRAC_INVALID /** @internal * \ingroup RTIRtpsClass * * The AUTO value semantic depends on the usage. Share the same values with * RTI_RTPS_TIME_INVALID, when transforming this into an RTINtpTime we transform * this into a INVALID. */ #define RTI_RTPS_TIME_AUTO RTI_RTPS_TIME_INVALID /** @internal \ingroup RTIRtpsClass * * @brief Compare two RTIRtpsTime. * * @param time1 RTIRtpsTime. * @param time2 RTIRtpsTime. * * @return If time1 > time2 then return 1. If time1 < time2 then return -1. * If time1 == time2 then return 0. */ extern RTIOsapiDllExport int RTIRtpsTime_compare( const struct RTIRtpsTime time1, const struct RTIRtpsTime time2); /** @internal \ingroup RTIRtpsClass * * @brief Copy a RTIRtpsTime from tIn to tOut. * * @param tOut RTIRtpsTime, NOT NULL. * @param tIn RTIRtpsTime, NOT NULL. */ extern RTIOsapiDllExport void RTIRtpsTime_copy( struct RTIRtpsTime *tOut, const struct RTIRtpsTime *tIn); /** @internal * \ingroup RTIRtpsClass * * NULL RTIRtpsTime pointer is considered infinity. This is consistent * with the concept of infinite time on UNIX. * * In addition, if the seconds field equals, or is above * RTI_RTPS_TIME_SEC_MAX, the time value is also considered infinite. * * @param time Pointer to RTIRtpsTime. * * @return RTI_TRUE if time is infinite, RTI_FALSE otherwise. */ extern RTIOsapiDllExport RTIBool RTIRtpsTime_isInfinite(const struct RTIRtpsTime *time); /** @internal * \ingroup RTIRtpsClass * * Checks if the time structure represents an invalid time. * * @param time Pointer to RTIRtpsTime. * * @return RTI_TRUE if time is invalid, RTI_FALSE otherwise. */ extern RTIOsapiDllExport RTIBool RTIRtpsTime_isInvalid(const struct RTIRtpsTime *time); /** @internal * \ingroup RTIRtpsClass * * @brief Convert RTINtpTime to RTIRtpsTime. * * @param rtpsTime (RTIRtpsTime *) Pointer to RTIRtpsTime struct that is going * to be converted. * @param time (RTINtpTime *) Pointer to RTINtpTime struct that needs to be * converted. */ extern RTIOsapiDllExport void RTIRtpsTime_fromNtptime( struct RTIRtpsTime *rtpsTime, const struct RTINtpTime *time); /** @internal * \ingroup RTIRtpsClass * * @brief Convert RTIRtpsTime to RTINtpTime. Since AUTO and INVALID share the * same value we are losing AUTO when transforming it back to an RTINtpTime. * * @param rtpsTime (RTINtpTime *) Pointer to RTINtpTime struct that is going to * be converted. * @param time (RTIRtpsTime *) Pointer to RTIRtpsTime struct that the result is * stored in. */ extern RTIOsapiDllExport void RTIRtpsTime_toNtptime( const struct RTIRtpsTime *rtpsTime, struct RTINtpTime *time); #ifdef __cplusplus } /* extern "C" */ #endif #include "osapi/osapi_ntptime_impl.h" #include "osapi/osapi_rtpsTime_impl.h" #endif /* osapi_rtpsTime_h */