Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
ntp_time_service.hpp File Reference

Go to the source code of this file.

Classes

class  time_shield::detail::FakeNtpRunner
 Fake runner for tests without network access. More...
 
class  time_shield::NtpTimeServiceT< RunnerT >
 Singleton service for background NTP measurements. More...
 
class  time_shield::NtpTimeService
 

Namespaces

namespace  time_shield
 Main namespace for the Time Shield library.
 
namespace  time_shield::detail
 
namespace  time_shield::ntp
 

Typedefs

using time_shield::detail::RunnerAlias = detail::FakeNtpRunner
 
using time_shield::NtpTimeService = NtpTimeServiceT<detail::FakeNtpRunner>
 NTP time service alias that uses a fake runner for tests.
 

Functions

bool time_shield::ntp::init (std::chrono::milliseconds interval=std::chrono::seconds(30), bool measure_immediately=true)
 Initialize NTP time service and start background measurements.
 
bool time_shield::ntp::init (int interval_ms, bool measure_immediately=true)
 Initialize NTP time service using milliseconds.
 
void time_shield::ntp::shutdown ()
 Stop NTP time service.
 
int64_t time_shield::ntp::offset_us () noexcept
 Return last estimated offset in microseconds.
 
int64_t time_shield::ntp::utc_time_us () noexcept
 Return current UTC time in microseconds based on offset.
 
int64_t time_shield::ntp::utc_time_ms () noexcept
 Return current UTC time in milliseconds based on offset.
 
int64_t time_shield::ntp::utc_time_sec () noexcept
 Return current UTC time in seconds based on offset.
 
bool time_shield::ntp::last_measure_ok () noexcept
 Return whether last measurement updated the offset.
 
uint64_t time_shield::ntp::measure_count () noexcept
 Return total number of measurement attempts.
 
uint64_t time_shield::ntp::fail_count () noexcept
 Return number of failed measurement attempts.
 
int64_t time_shield::ntp::last_update_realtime_us () noexcept
 Return realtime timestamp of last measurement attempt.
 
int64_t time_shield::ntp::last_success_realtime_us () noexcept
 Return realtime timestamp of last successful measurement.
 
bool time_shield::ntp::stale (std::chrono::milliseconds max_age) noexcept
 Return true when last measurement is older than max_age.
 

Variables

NtpTimeServiceT< RunnerAliastime_shield::detail::g_ntp_time_service
 
template<class RunnerT>
NtpTimeServiceT< RunnerT > time_shield::NtpTimeServiceT< RunnerT >::m_instance {}