From f60287bf49f5aa6dd1e8d4f0255d4f59be6bc0cf Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 14 Mar 2011 11:31:38 +0100 Subject: [PATCH] [lib] Change TIMESTAMP type TIMESTAMP is not a simple alias for struct timespec. It is now a clone of struct timespec that uses fields of a fixed size (uint32_t). --- libowlps/libowlps.c | 19 ++++++++++++++++++- libowlps/owlps.h | 9 +++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index bc7edeb..a8cb571 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -107,11 +107,15 @@ void owl_timestamp_now(TIMESTAMP *now) int owl_timestamp_now_ns(TIMESTAMP *now) { int ret ; - if ((ret = clock_gettime(CLOCK_REALTIME, now))) + struct timespec now_ts ; + if ((ret = clock_gettime(CLOCK_REALTIME, &now_ts))) { perror("Cannot get the current time") ; return ret ; } + + *now = owl_timespec_to_timestamp(now_ts) ; + return 0 ; } @@ -127,6 +131,19 @@ void owl_timestamp_round_to_ms(TIMESTAMP *now) +/* + * Returns a TIMESTAMP from a struct timespec. + */ +TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) +{ + TIMESTAMP res ; + res.tv_sec = d.tv_sec ; + res.tv_nsec = d.tv_nsec ; + return res ; +} + + + /* * Returns a TIMESTAMP from a struct timeval. */ diff --git a/libowlps/owlps.h b/libowlps/owlps.h index 51fe315..c0944df 100644 --- a/libowlps/owlps.h +++ b/libowlps/owlps.h @@ -60,8 +60,12 @@ typedef enum {FALSE, TRUE} BOOL ; typedef enum {NORTH = 1, EAST, SOUTH, WEST} DIRECTION ; -/* Timestamp type */ -typedef struct timespec TIMESTAMP ; +/* Timestamp type (struct timespec clone with fix-sized fields) */ +typedef struct _TIMESTAMP +{ + uint32_t tv_sec ; + uint32_t tv_nsec ; +} TIMESTAMP ; /* Message sent by the listener to the aggregator */ @@ -226,6 +230,7 @@ uint_fast8_t owl_frequency_to_channel(uint_fast16_t channel) ; void owl_timestamp_now(TIMESTAMP *now) ; int owl_timestamp_now_ns(TIMESTAMP *now) ; void owl_timestamp_round_to_ms(TIMESTAMP *now) ; +TIMESTAMP owl_timespec_to_timestamp(const struct timespec d) ; TIMESTAMP owl_timeval_to_timestamp(const struct timeval d) ; uint64_t owl_timestamp_to_ms(TIMESTAMP date) ; uint_fast32_t owl_time_elapsed(TIMESTAMP sup, TIMESTAMP inf) ;