55#ifndef JUNO_TIME_API_H
56#define JUNO_TIME_API_H
199#define JunoTime_TimeApiInit(Now, SleepTo, Sleep) \
203 JunoTime_SubtractTime, \
206 JunoTime_TimestampToNanos, \
207 JunoTime_TimestampToMicros, \
208 JunoTime_TimestampToMillis, \
209 JunoTime_NanosToTimestamp, \
210 JunoTime_MicrosToTimestamp, \
211 JunoTime_MillisToTimestamp, \
212 JunoTime_TimestampToDouble, \
213 JunoTime_DoubleToTimestamp, \
238 ptTime->ptApi = ptApi;
239 ptTime->_pfcnFailureHandler = pfcnFailureHandler;
240 ptTime->_pvFailureUserData = pvUserData;
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:51
#define JUNO_MODULE_EMPTY
Helper for module definitions with no additional members.
Definition module.h:87
#define JUNO_MODULE_RESULT(NAME_T, OK_T)
Define a result type combining a status and a success payload.
Definition module.h:198
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:129
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:59
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:110
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:51
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:101
uint64_t JUNO_TIME_NANOS_T
Nanoseconds count type.
Definition time_api.h:79
static bool JunoTime_TimestampEquals(JUNO_TIMESTAMP_T tLeft, JUNO_TIMESTAMP_T tRight)
Compare timestamps for equality.
Definition time_api.h:229
uint64_t JUNO_TIME_MICROS_T
Microseconds count type.
Definition time_api.h:77
JUNO_TIME_MICROS_RESULT_T JunoTime_TimestampToMicros(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Definition juno_time.c:116
JUNO_TIMESTAMP_RESULT_T JunoTime_MicrosToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MICROS_T iMicros)
Definition juno_time.c:203
JUNO_TIMESTAMP_RESULT_T JunoTime_MillisToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MILLIS_T iMillis)
Definition juno_time.c:221
JUNO_TIME_NANOS_RESULT_T JunoTime_TimestampToNanos(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Definition juno_time.c:79
static bool JunoTime_TimestampGreaterThan(JUNO_TIMESTAMP_T tLeft, JUNO_TIMESTAMP_T tRight)
Compare timestamps (tLeft > tRight).
Definition time_api.h:217
uint64_t JUNO_TIME_MILLIS_T
Milliseconds count type.
Definition time_api.h:75
uint32_t JUNO_TIME_SECONDS_T
Whole seconds component type.
Definition time_api.h:73
JUNO_STATUS_T JunoTime_SubtractTime(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T *ptRetTime, JUNO_TIMESTAMP_T tTimeToSubtract)
Subtract a duration from a timestamp in-place. If the subtraction would underflow (negative time),...
Definition juno_time.c:50
static bool JunoTime_TimestampLessThan(JUNO_TIMESTAMP_T tLeft, JUNO_TIMESTAMP_T tRight)
Compare timestamps (tLeft < tRight).
Definition time_api.h:223
static JUNO_STATUS_T JunoTime_TimeInit(JUNO_TIME_ROOT_T *ptTime, const JUNO_TIME_API_T *ptApi, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvUserData)
Initialize the time module root with API and failure handler.
Definition time_api.h:235
JUNO_TIMESTAMP_RESULT_T JunoTime_DoubleToTimestamp(const JUNO_TIME_ROOT_T *ptTime, double dTimestamp)
Definition juno_time.c:255
JUNO_RESULT_F64_T JunoTime_TimestampToDouble(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTimestamp)
Definition juno_time.c:240
JUNO_STATUS_T JunoTime_AddTime(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T *ptRetTime, JUNO_TIMESTAMP_T tTimeToAdd)
Add a duration to a timestamp in-place.
Definition juno_time.c:27
JUNO_TIME_MILLIS_RESULT_T JunoTime_TimestampToMillis(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Definition juno_time.c:150
JUNO_TIMESTAMP_RESULT_T JunoTime_NanosToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_NANOS_T iNanos)
Definition juno_time.c:185
uint32_t JUNO_TIME_SUBSECONDS_T
Subsecond fixed-point fraction type.
Definition time_api.h:81
struct JUNO_TIME_ROOT_TAG JUNO_TIME_ROOT_T
Definition time_api.h:69
Common assertion and helper macros for LibJuno modules.
Module system and dependency injection primitives for LibJuno.
Status codes and failure-handling helpers for LibJuno.
Timestamp consisting of whole seconds and fixed-point subseconds.
Definition time_api.h:106
JUNO_TIME_SECONDS_T iSeconds
Whole seconds component of time.
Definition time_api.h:108
JUNO_TIME_SUBSECONDS_T iSubSeconds
Definition time_api.h:111
Vtable for time operations and conversions.
Definition time_api.h:130
JUNO_TIMESTAMP_RESULT_T(* DoubleToTimestamp)(const JUNO_TIME_ROOT_T *ptTime, double dTimestamp)
Convert a double to a timestamp.
Definition time_api.h:156
JUNO_TIMESTAMP_RESULT_T(* Now)(const JUNO_TIME_ROOT_T *ptTime)
Get the current time as specified by the implementation.
Definition time_api.h:132
JUNO_STATUS_T(* SleepTo)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTimeToWakeup)
Sleep this thread until a specific time.
Definition time_api.h:138
JUNO_TIMESTAMP_RESULT_T(* MicrosToTimestamp)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MICROS_T iMicros)
Convert microseconds to a timestamp.
Definition time_api.h:150
JUNO_STATUS_T(* Sleep)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tDuration)
Sleep this thread for a duration.
Definition time_api.h:140
JUNO_TIME_NANOS_RESULT_T(* TimestampToNanos)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Convert a timestamp to nanoseconds (round to nearest, half-up)
Definition time_api.h:142
JUNO_TIME_MILLIS_RESULT_T(* TimestampToMillis)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Convert a timestamp to milliseconds (round to nearest, half-up)
Definition time_api.h:146
JUNO_STATUS_T(* AddTime)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T *ptRetTime, JUNO_TIMESTAMP_T tTimeToAdd)
Perform addition with time (in-place add to ptRetTime)
Definition time_api.h:134
JUNO_TIMESTAMP_RESULT_T(* NanosToTimestamp)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_NANOS_T iNanos)
Convert nanoseconds to a timestamp.
Definition time_api.h:148
JUNO_TIMESTAMP_RESULT_T(* MillisToTimestamp)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MILLIS_T iMillis)
Convert milliseconds to a timestamp.
Definition time_api.h:152
JUNO_TIME_MICROS_RESULT_T(* TimestampToMicros)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Convert a timestamp to microseconds (round to nearest, half-up)
Definition time_api.h:144
JUNO_STATUS_T(* SubtractTime)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T *ptRetTime, JUNO_TIMESTAMP_T tTimeToSubtract)
Perform subtraction with time (in-place subtract from ptRetTime)
Definition time_api.h:136
JUNO_RESULT_F64_T(* TimestampToDouble)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTimestamp)
Convert a timestamp to a double.
Definition time_api.h:154
Common module result type aliases used throughout LibJuno.