|
Time Shield Library
C++ library for working with time
|
Fake runner for tests without network access. More...
#include <ntp_time_service.hpp>
Public Member Functions | |
| FakeNtpRunner ()=default | |
| Construct fake runner. | |
| FakeNtpRunner (NtpClientPool) | |
| Construct fake runner with an unused pool. | |
| FakeNtpRunner (const FakeNtpRunner &)=delete | |
| FakeNtpRunner & | operator= (const FakeNtpRunner &)=delete |
| ~FakeNtpRunner () | |
| Stop background thread on destruction. | |
| bool | start (std::chrono::milliseconds interval=std::chrono::seconds(30), bool measure_immediately=true) |
| Start fake measurements on a background thread. | |
| bool | start (int interval_ms, bool measure_immediately=true) |
| Start fake measurements using milliseconds. | |
| void | stop () |
| Stop background measurements. | |
| bool | running () const noexcept |
| Return true when background thread is running. | |
| bool | force_measure () |
| Wake the worker thread and request a measurement. | |
| bool | measure_now () |
| Perform one measurement immediately. | |
| int64_t | offset_us () const noexcept |
| Return last estimated offset in microseconds. | |
| int64_t | utc_time_us () const noexcept |
| Return current UTC time in microseconds based on offset. | |
| int64_t | utc_time_ms () const noexcept |
| Return current UTC time in milliseconds based on offset. | |
| int64_t | utc_time_sec () const noexcept |
| Return current UTC time in seconds based on offset. | |
| bool | last_measure_ok () const noexcept |
| Return whether last measurement updated the offset. | |
| uint64_t | measure_count () const noexcept |
| Return total number of measurement attempts. | |
| uint64_t | fail_count () const noexcept |
| Return number of failed measurement attempts. | |
| int64_t | last_update_realtime_us () const noexcept |
| Return realtime timestamp of last measurement attempt. | |
| int64_t | last_success_realtime_us () const noexcept |
| Return realtime timestamp of last successful measurement. | |
| std::vector< NtpSample > | last_samples () const |
| Return copy of most recent samples. | |
Private Member Functions | |
| void | run_loop () |
| Background loop for fake measurements. | |
| bool | do_measure () |
| Update fake offset and stats. | |
Private Attributes | |
| std::chrono::milliseconds | m_interval {std::chrono::seconds(30)} |
| bool | m_measure_immediately {true} |
| std::thread | m_thread |
| std::condition_variable | m_cv |
| std::mutex | m_cv_mtx |
| std::atomic< bool > | m_is_running {false} |
| std::atomic< bool > | m_is_stop_requested {false} |
| std::atomic< bool > | m_is_force_requested {false} |
| std::atomic< bool > | m_last_measure_ok {false} |
| std::atomic< uint64_t > | m_measure_count {0} |
| std::atomic< uint64_t > | m_fail_count {0} |
| std::atomic< int64_t > | m_last_update_realtime_us {0} |
| std::atomic< int64_t > | m_last_success_realtime_us {0} |
| std::atomic< int64_t > | m_offset_us {0} |
Fake runner for tests without network access.
Definition at line 32 of file ntp_time_service.hpp.
|
default |
Construct fake runner.
|
inlineexplicit |
Construct fake runner with an unused pool.
Definition at line 37 of file ntp_time_service.hpp.
|
delete |
|
inline |
Stop background thread on destruction.
Definition at line 43 of file ntp_time_service.hpp.
|
inlineprivate |
Update fake offset and stats.
Definition at line 151 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return number of failed measurement attempts.
Definition at line 117 of file ntp_time_service.hpp.
|
inline |
Wake the worker thread and request a measurement.
Definition at line 89 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return whether last measurement updated the offset.
Definition at line 113 of file ntp_time_service.hpp.
|
inline |
Return copy of most recent samples.
Definition at line 124 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last successful measurement.
Definition at line 121 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last measurement attempt.
Definition at line 119 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return total number of measurement attempts.
Definition at line 115 of file ntp_time_service.hpp.
|
inline |
Perform one measurement immediately.
Definition at line 99 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return last estimated offset in microseconds.
Definition at line 104 of file ntp_time_service.hpp.
|
delete |
|
inlineprivate |
Background loop for fake measurements.
Definition at line 128 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return true when background thread is running.
Definition at line 86 of file ntp_time_service.hpp.
|
inline |
Start fake measurements using milliseconds.
Definition at line 71 of file ntp_time_service.hpp.
|
inline |
Start fake measurements on a background thread.
Definition at line 48 of file ntp_time_service.hpp.
|
inline |
Stop background measurements.
Definition at line 76 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds based on offset.
Definition at line 108 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in seconds based on offset.
Definition at line 110 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds based on offset.
Definition at line 106 of file ntp_time_service.hpp.
|
private |
Definition at line 166 of file ntp_time_service.hpp.
|
private |
Definition at line 167 of file ntp_time_service.hpp.
|
private |
Definition at line 175 of file ntp_time_service.hpp.
|
private |
Definition at line 162 of file ntp_time_service.hpp.
|
private |
Definition at line 171 of file ntp_time_service.hpp.
|
private |
Definition at line 169 of file ntp_time_service.hpp.
|
private |
Definition at line 170 of file ntp_time_service.hpp.
|
private |
Definition at line 173 of file ntp_time_service.hpp.
|
private |
Definition at line 177 of file ntp_time_service.hpp.
|
private |
Definition at line 176 of file ntp_time_service.hpp.
|
private |
Definition at line 174 of file ntp_time_service.hpp.
|
private |
Definition at line 163 of file ntp_time_service.hpp.
|
private |
Definition at line 178 of file ntp_time_service.hpp.
|
private |
Definition at line 165 of file ntp_time_service.hpp.