3.10. Time

Time representation.

Defines

TIME_BUFSIZE

String buffer minimum size.

INVALID_TIME

Static initializer for the struct time.

Functions

void time_build(struct time * t, double secs)

Build a new time structure from a number of seconds.

bool time_gettimestamp(struct time * t)

Get a current timestamp.

void time_add(struct time * res, const struct time * t1, const struct time * t2)

Add two time object.

int time_diff(struct time * res, const struct time * t1, const struct time * t2)

Compute the difference between two time object. It returns the result of time_cmp(t1, t2).

uint64 time_divide(const struct time * t1, const struct time * t2)

Divide two time value.

void time_mult(struct time * res, const struct time * t1, const int mult)

Multiply a time value.

int time_cmp(const struct time * t1, const struct time * t2)

Compare two time object. It returns -1, 1 or 0 respectivelly if t1 is smaller than t2, t1 is larger than t2 or t1 is equal to t2.

double time_sec(const struct time * t)

Convert time to a number of seconds.

bool time_tostring(const struct time * t, char * buffer, size_t len)

Convert time to a string.

See
TIME_BUFSIZE

bool time_format(const struct time * t, const char * format, char * buffer, size_t len)

Convert time to a formated string.

See
strftime()

bool time_isvalid(const struct time * t)

Check if the time is valid.

Variables

struct time invalid_time

class time

Time structure.

Public Members

time_t secs

Seconds

uint32 nsecs

Nano-seconds

3.11. Timer

Timer functions.

Typedefs

typedef void(* timer_callback)(int count, void *data)

Opaque timer structure. Timer callback called whenever a timer triggers.

Enums

time_realm_mode enum

Timer mode.

Values:

  • TIME_REALM_REALTIME -
  • TIME_REALM_STATIC -
Functions

bool time_realm_initialize(struct time_realm * realm, enum time_realm_mode mode)

Create a new time realm.

bool time_realm_destroy(struct time_realm * realm)

Destroy a time realm.

void time_realm_update_and_check(struct time_realm * realm, const struct time * value)

Update the time of a time realm that is in TIMER_REALM_STATIC mode. It does also check for timer to trigger.

struct time * time_realm_current_time(struct time_realm * realm)

Get the current local time of the time realm.

struct timer * time_realm_timer(struct time_realm * realm, timer_callback callback, void * user)

Create a new timer.

bool time_realm_check(struct time_realm * realm)

Check and execute timer callbacks.

bool timer_init_thread()

Initialize the current thread for timer support.

Return
false if an error occurred.

void timer_destroy(struct timer * timer)

Destroy a timer.

bool timer_once(struct timer * timer, struct time * delay)

Start a timer to be trigger only once.

Return
false if an error occurred.

bool timer_repeat(struct timer * timer, struct time * delay)

Start a timer to be repeated until it is stopped or destroyed.

Return
false if an error occurred.

bool timer_stop(struct timer * timer)

Stop a timer.

Return
false if an error occurred.

class time_realm

Opaque timer environment structure.

Public Members