|
Time Shield Library 2.0.0
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 38 of file ntp_time_service.hpp.
|
default |
Construct fake runner.
|
inlineexplicit |
Construct fake runner with an unused pool.
Definition at line 43 of file ntp_time_service.hpp.
|
delete |
|
inline |
Stop background thread on destruction.
Definition at line 49 of file ntp_time_service.hpp.
|
inlineprivate |
Update fake offset and stats.
Definition at line 157 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return number of failed measurement attempts.
Definition at line 123 of file ntp_time_service.hpp.
|
inline |
Wake the worker thread and request a measurement.
Definition at line 95 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return whether last measurement updated the offset.
Definition at line 119 of file ntp_time_service.hpp.
|
inline |
Return copy of most recent samples.
Definition at line 130 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last successful measurement.
Definition at line 127 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last measurement attempt.
Definition at line 125 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return total number of measurement attempts.
Definition at line 121 of file ntp_time_service.hpp.
|
inline |
Perform one measurement immediately.
Definition at line 105 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return last estimated offset in microseconds.
Definition at line 110 of file ntp_time_service.hpp.
|
delete |
|
inlineprivate |
Background loop for fake measurements.
Definition at line 134 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return true when background thread is running.
Definition at line 92 of file ntp_time_service.hpp.
|
inline |
Start fake measurements using milliseconds.
Definition at line 77 of file ntp_time_service.hpp.
|
inline |
Start fake measurements on a background thread.
Definition at line 54 of file ntp_time_service.hpp.
|
inline |
Stop background measurements.
Definition at line 82 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds based on offset.
Definition at line 114 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in seconds based on offset.
Definition at line 116 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds based on offset.
Definition at line 112 of file ntp_time_service.hpp.
|
private |
Definition at line 172 of file ntp_time_service.hpp.
|
private |
Definition at line 173 of file ntp_time_service.hpp.
|
private |
Definition at line 181 of file ntp_time_service.hpp.
|
private |
Definition at line 168 of file ntp_time_service.hpp.
|
private |
Definition at line 177 of file ntp_time_service.hpp.
|
private |
Definition at line 175 of file ntp_time_service.hpp.
|
private |
Definition at line 176 of file ntp_time_service.hpp.
|
private |
Definition at line 179 of file ntp_time_service.hpp.
|
private |
Definition at line 183 of file ntp_time_service.hpp.
|
private |
Definition at line 182 of file ntp_time_service.hpp.
|
private |
Definition at line 180 of file ntp_time_service.hpp.
|
private |
Definition at line 169 of file ntp_time_service.hpp.
|
private |
Definition at line 184 of file ntp_time_service.hpp.
|
private |
Definition at line 171 of file ntp_time_service.hpp.