[Pkg-voip-commits] [bctoolbox] 48/57: Rework the get_current_time API - have a function which enforce we get the UTC current time - return UTC current time for the get_cur_time_ms - do not expose _bctbx_get_cur_time in the API.
daniel at gnoutcheff.name
daniel at gnoutcheff.name
Thu Mar 30 04:31:35 UTC 2017
This is an automated email from the git hooks/post-receive script.
gnoutchd-guest pushed a commit to branch debian/sid
in repository bctoolbox.
commit 7494e721d5ae24692fc5ceb70946d5d4051de13b
Author: Johan Pascal <johan.pascal at belledonne-communications.com>
Date: Mon Feb 6 09:33:55 2017 +0700
Rework the get_current_time API
- have a function which enforce we get the UTC current time
- return UTC current time for the get_cur_time_ms
- do not expose _bctbx_get_cur_time in the API.
---
include/bctoolbox/port.h | 15 ++++++++++++++-
src/utils/port.c | 6 +++++-
tester/port.c | 11 ++++++++++-
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/include/bctoolbox/port.h b/include/bctoolbox/port.h
index 38824ec..fc7ffc5 100644
--- a/include/bctoolbox/port.h
+++ b/include/bctoolbox/port.h
@@ -363,8 +363,21 @@ BCTBX_PUBLIC char *bctbx_concat (const char *str, ...) ;
BCTBX_PUBLIC int bctbx_file_exist(const char *pathname);
+/**
+ * @brief return a timeSpec structure(sec and nsec) containing current time(WARNING: there is no guarantees it is UTC ).
+ * The time returned may refers to UTC or last boot.
+ * Use this function only to compute a time span between two calls
+ * @param[in/out] ret The current time (seconds and nano seconds).
+ */
BCTBX_PUBLIC void bctbx_get_cur_time(bctoolboxTimeSpec *ret);
-void _bctbx_get_cur_time(bctoolboxTimeSpec *ret, bool_t realtime);
+
+/**
+ * @brief return a timeSpec structure(sec and nsec) containing current UTC time.
+ *
+ * @param[in/out] ret The current UTC time, (seconds and nano seconds)
+ */
+BCTBX_PUBLIC void bctbx_get_utc_cur_time(bctoolboxTimeSpec *ret);
+
BCTBX_PUBLIC uint64_t bctbx_get_cur_time_ms(void);
BCTBX_PUBLIC void bctbx_sleep_ms(int ms);
BCTBX_PUBLIC void bctbx_sleep_until(const bctoolboxTimeSpec *ts);
diff --git a/src/utils/port.c b/src/utils/port.c
index 4ff3850..0053558 100644
--- a/src/utils/port.c
+++ b/src/utils/port.c
@@ -727,6 +727,10 @@ void _bctbx_get_cur_time(bctoolboxTimeSpec *ret, bool_t realtime){
#endif
}
+void bctbx_get_utc_cur_time(bctoolboxTimeSpec *ret){
+ _bctbx_get_cur_time(ret, TRUE);
+}
+
void bctbx_get_cur_time(bctoolboxTimeSpec *ret){
_bctbx_get_cur_time(ret, FALSE);
}
@@ -734,7 +738,7 @@ void bctbx_get_cur_time(bctoolboxTimeSpec *ret){
uint64_t bctbx_get_cur_time_ms(void) {
bctoolboxTimeSpec ts;
- bctbx_get_cur_time(&ts);
+ _bctbx_get_cur_time(&ts, TRUE);
return (ts.tv_sec * 1000LL) + ((ts.tv_nsec + 500000LL) / 1000000LL);
}
diff --git a/tester/port.c b/tester/port.c
index e3ece9e..f0cfffd 100644
--- a/tester/port.c
+++ b/tester/port.c
@@ -84,9 +84,11 @@ static void bytesToFromHexaStrings(void) {
static void timeFunctions(void) {
bctoolboxTimeSpec testTs;
- bctoolboxTimeSpec y2k;
+ bctoolboxTimeSpec y2k,monday6Feb2017;
y2k.tv_sec = 946684800;
y2k.tv_nsec = 123456789;
+ monday6Feb2017.tv_sec = 1486347823;
+ monday6Feb2017.tv_nsec = 0;
memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
BC_ASSERT_EQUAL(bctbx_timespec_compare(&y2k, &testTs), 0, int, "%d");
@@ -105,6 +107,13 @@ static void timeFunctions(void) {
bctbx_timespec_add(&testTs, -946684801);
BC_ASSERT_EQUAL(testTs.tv_sec, 0, int64_t, "%ld");
BC_ASSERT_EQUAL(testTs.tv_nsec, 0, int64_t, "%ld");
+
+ /* test the get utc time function
+ * there is no easy way to ensure we get the correct time, just check it is at least not the time from last boot,
+ * check it is greater than the current time as this test was written(6feb2017) */
+ bctbx_get_utc_cur_time(&testTs);
+ BC_ASSERT_TRUE(bctbx_timespec_compare(&testTs, &monday6Feb2017)>0);
+
}
static test_t utils_tests[] = {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/bctoolbox.git
More information about the Pkg-voip-commits
mailing list