diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-05 23:44:31 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-05 23:44:31 +0100 |
commit | 743e66a3469af27819bcd0e3e1694d2a4c523c6b (patch) | |
tree | f6ae7e4122eb5ff249d699bc2c786e2d5a7e35b7 | |
parent | 0957760c42cc04d9c295b649b039015186b25609 (diff) | |
download | dabmux-743e66a3469af27819bcd0e3e1694d2a4c523c6b.tar.gz dabmux-743e66a3469af27819bcd0e3e1694d2a4c523c6b.tar.bz2 dabmux-743e66a3469af27819bcd0e3e1694d2a4c523c6b.zip |
Use std::chrono in ClockTAI
-rw-r--r-- | src/ClockTAI.cpp | 23 | ||||
-rw-r--r-- | src/ClockTAI.h | 7 |
2 files changed, 8 insertions, 22 deletions
diff --git a/src/ClockTAI.cpp b/src/ClockTAI.cpp index c7b045b..5334bbd 100644 --- a/src/ClockTAI.cpp +++ b/src/ClockTAI.cpp @@ -52,22 +52,14 @@ ClockTAI::ClockTAI() { m_offset = 0; - m_bulletin_download_time.tv_nsec = 0; - m_bulletin_download_time.tv_sec = 0; } int ClockTAI::get_offset() { -#if ENABLE_OUTPUT_EDI - struct timespec time_now; + auto time_now = std::chrono::system_clock::now(); - int err = clock_gettime(CLOCK_REALTIME, &time_now); - if (err) { - throw std::runtime_error("ClockTAI::get_offset() clock_gettime failed"); - } - - if (time_now.tv_sec - m_bulletin_download_time.tv_sec > - 3600 * 24 * 31) { + if (time_now - m_bulletin_download_time > + std::chrono::seconds(3600 * 24 * 31)) { // Refresh if it's older than one month. Leap seconds are // announced several months in advance @@ -84,7 +76,6 @@ int ClockTAI::get_offset() etiLog.level(info) << "Updated TAI-UTC offset to " << m_offset << "s."; } -#endif // ENABLE_OUTPUT_EDI return m_offset; } @@ -183,11 +174,7 @@ int ClockTAI::download_tai_utc_bulletin(const char* url) } else { // Save the download time of the bulletin - int err = clock_gettime(CLOCK_REALTIME, &m_bulletin_download_time); - if (err) { - perror("REALTIME clock_gettime failed"); - r = 1; - } + m_bulletin_download_time = std::chrono::system_clock::now(); } /* always cleanup */ @@ -230,5 +217,3 @@ void debug_tai_clk() } #endif - - diff --git a/src/ClockTAI.h b/src/ClockTAI.h index 027e6db..499fa56 100644 --- a/src/ClockTAI.h +++ b/src/ClockTAI.h @@ -37,9 +37,10 @@ #include <stdint.h> #include <stdlib.h> #include <sstream> -#include <time.h> +#include <chrono> -// EDI needs to know UTC-TAI, but doesn't need the CLOCK_TAI to be set +// EDI needs to know UTC-TAI, but doesn't need the CLOCK_TAI to be set. +// We can keep this code, maybe for future use #define SUPPORT_SETTING_CLOCK_TAI 0 /* Loads, parses and represents TAI-UTC offset information from the USNO bulletin */ @@ -65,7 +66,7 @@ class ClockTAI { int m_offset; std::stringstream m_bulletin; - struct timespec m_bulletin_download_time; + std::chrono::system_clock::time_point m_bulletin_download_time; // Load bulletin into m_bulletin, return 0 on success int download_tai_utc_bulletin(const char* url); |