From a11f3fa7440d9667656e92702dff6e18d623120a Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 22 Dec 2025 17:01:16 +0100 Subject: Add http server with stats.json --- lib/ClockTAI.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib/ClockTAI.cpp') diff --git a/lib/ClockTAI.cpp b/lib/ClockTAI.cpp index 5b6534f..12d2106 100644 --- a/lib/ClockTAI.cpp +++ b/lib/ClockTAI.cpp @@ -30,7 +30,7 @@ * * This file contains self-test code that can be executed by running * g++ -g -Wall -DTAI_TEST -DHAVE_CURL -std=c++11 -lcurl -pthread \ - * ClockTAI.cpp Log.cpp RemoteControl.cpp -o taitest && ./taitest + * ClockTAI.cpp Log.cpp RemoteControl.cpp -lboost_system -o taitest && ./taitest */ #include @@ -379,16 +379,16 @@ void Bulletin::clear_expiry_if_overridden() } } +ClockTAI::ClockTAI(const std::vector& bulletin_urls) #if ENABLE_REMOTECONTROL -ClockTAI::ClockTAI(const std::vector& bulletin_urls) : - RemoteControllable("clocktai") + : RemoteControllable("clocktai") { RC_ADD_PARAMETER(tai_utc_offset, "TAI-UTC offset"); RC_ADD_PARAMETER(expiry, "Number of seconds until TAI Bulletin expires"); RC_ADD_PARAMETER(expires_at, "UNIX timestamp when TAI Bulletin expires"); RC_ADD_PARAMETER(url, "URLs used to fetch the bulletin, separated by pipes"); #else -ClockTAI::ClockTAI(const std::vector& bulletin_urls) { +{ #endif // ENABLE_REMOTECONTROL if (bulletin_urls.empty()) { @@ -405,6 +405,10 @@ ClockTAI::ClockTAI(const std::vector& bulletin_urls) { etiLog.level(debug) << "ClockTAI uses bulletin URL: '" << join_string_with_pipe(m_bulletin_urls) << "'"; } +ClockTAI::ClockTAI(const std::string& bulletin_urls_pipe_separated) + : ClockTAI(split_pipe_separated_string(bulletin_urls_pipe_separated)) { } + + BulletinState ClockTAI::get_valid_offset() { std::unique_lock lock(m_data_mutex); @@ -567,6 +571,18 @@ int ClockTAI::get_offset() throw std::logic_error("ClockTAI: No valid m_state at end of get_offset()"); } +std::optional ClockTAI::expires_at() const +{ + std::unique_lock lock(m_data_mutex); + const auto& state = m_bulletin.state(); + if (state.valid) { + return state.expires_at; + } + else { + return nullopt; + } +} + #if SUPPORT_SETTING_CLOCK_TAI int ClockTAI::update_local_tai_clock(int offset) { -- cgit v1.2.3