55#ifndef JUNO_TIME_API_H
56#define JUNO_TIME_API_H
197#define JunoTime_TimeApiInit(Now, SleepTo, Sleep) \
201 JunoTime_SubtractTime, \
204 JunoTime_TimestampToNanos, \
205 JunoTime_TimestampToMicros, \
206 JunoTime_TimestampToMillis, \
207 JunoTime_NanosToTimestamp, \
208 JunoTime_MicrosToTimestamp, \
209 JunoTime_MillisToTimestamp, \
210 JunoTime_TimestampToDouble, \
211 JunoTime_DoubleToTimestamp, \
236 ptTime->ptApi = ptApi;
237 ptTime->_pfcnFailureHandler = pfcnFailureHandler;
238 ptTime->_pvFailureUserData = pvUserData;
#define JUNO_ASSERT_EXISTS(ptr)
Returns JUNO_STATUS_NULLPTR_ERROR if the expression is falsy.
Definition macros.h:50
#define JUNO_MODULE_EMPTY
Helper for module definitions with no additional members.
Definition module.h:86
#define JUNO_MODULE_RESULT(NAME_T, OK_T)
Define a result type combining a status and a success payload.
Definition module.h:193
#define JUNO_MODULE_ROOT(API_T,...)
Implement a module root struct containing ptApi and failure fields.
Definition module.h:126
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:56
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Failure handler callback signature.
Definition status.h:104
int32_t JUNO_STATUS_T
Canonical status type for LibJuno functions.
Definition status.h:49
void JUNO_USER_DATA_T
Opaque user data type for failure callbacks.
Definition status.h:96
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:227
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:112
JUNO_TIMESTAMP_RESULT_T JunoTime_MicrosToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MICROS_T iMicros)
Definition juno_time.c:196
JUNO_TIMESTAMP_RESULT_T JunoTime_MillisToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_MILLIS_T iMillis)
Definition juno_time.c:213
JUNO_TIME_NANOS_RESULT_T JunoTime_TimestampToNanos(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Definition juno_time.c:76
static bool JunoTime_TimestampGreaterThan(JUNO_TIMESTAMP_T tLeft, JUNO_TIMESTAMP_T tRight)
Compare timestamps (tLeft > tRight).
Definition time_api.h:215
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:48
static bool JunoTime_TimestampLessThan(JUNO_TIMESTAMP_T tLeft, JUNO_TIMESTAMP_T tRight)
Compare timestamps (tLeft < tRight).
Definition time_api.h:221
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:233
JUNO_TIMESTAMP_RESULT_T JunoTime_DoubleToTimestamp(const JUNO_TIME_ROOT_T *ptTime, double dTimestamp)
Definition juno_time.c:245
JUNO_RESULT_F64_T JunoTime_TimestampToDouble(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTimestamp)
Definition juno_time.c:231
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:26
JUNO_TIME_MILLIS_RESULT_T JunoTime_TimestampToMillis(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tTime)
Definition juno_time.c:145
JUNO_TIMESTAMP_RESULT_T JunoTime_NanosToTimestamp(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIME_NANOS_T iNanos)
Definition juno_time.c:179
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:105
JUNO_TIME_SECONDS_T iSeconds
Whole seconds component of time.
Definition time_api.h:107
JUNO_TIME_SUBSECONDS_T iSubSeconds
Definition time_api.h:110
Vtable for time operations and conversions.
Definition time_api.h:128
JUNO_TIMESTAMP_RESULT_T(* DoubleToTimestamp)(const JUNO_TIME_ROOT_T *ptTime, double dTimestamp)
Convert a double to a timestamp.
Definition time_api.h:154
JUNO_TIMESTAMP_RESULT_T(* Now)(const JUNO_TIME_ROOT_T *ptTime)
Get the current time as specified by the implementation.
Definition time_api.h:130
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:136
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:148
JUNO_STATUS_T(* Sleep)(const JUNO_TIME_ROOT_T *ptTime, JUNO_TIMESTAMP_T tDuration)
Sleep this thread for a duration.
Definition time_api.h:138
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:140
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:144
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:132
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:146
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:150
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:142
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:134
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:152
Common module result type aliases used throughout LibJuno.