|
Time Shield Library
C++ library for working with time
|
Singleton service for background NTP measurements. More...
#include <ntp_time_service.hpp>
Public Member Functions | |
| NtpTimeServiceT (const NtpTimeServiceT &)=delete | |
| NtpTimeServiceT & | operator= (const NtpTimeServiceT &)=delete |
| bool | init () |
| Start background measurements using stored interval. | |
| bool | init (std::chrono::milliseconds interval, bool measure_immediately=true) |
| Start background measurements with interval and immediate flag. | |
| void | shutdown () |
| Stop background measurements and release resources. | |
| bool | running () const noexcept |
| Return true when background runner is active. | |
| void | ensure_started () noexcept |
| Ensure background runner is started with current config. | |
| int64_t | offset_us () noexcept |
| Return last estimated offset in microseconds. | |
| int64_t | utc_time_us () noexcept |
| Return current UTC time in microseconds based on offset. | |
| int64_t | utc_time_ms () noexcept |
| Return current UTC time in milliseconds based on offset. | |
| int64_t | utc_time_sec () 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. | |
| bool | stale (std::chrono::milliseconds max_age) const noexcept |
| Return true when last measurement is older than max_age. | |
| bool | set_servers (std::vector< NtpServerConfig > servers) |
| Replace server list used for new runner instances. | |
| bool | set_default_servers () |
| Use conservative default servers for new runner instances. | |
| bool | clear_servers () |
| Clear custom server list and return to default behavior. | |
| bool | set_pool_config (NtpPoolConfig cfg) |
| Override pool configuration for new runner instances. | |
| NtpPoolConfig | pool_config () const |
| Return current pool configuration. | |
| std::vector< NtpSample > | last_samples () const |
| Return copy of last measurement samples. | |
| NtpTimeServiceT ()=default | |
| Construct service. | |
| ~NtpTimeServiceT () | |
| Stop background runner on destruction. | |
| bool | apply_config_now () |
| Apply current config by rebuilding the runner. | |
Static Public Member Functions | |
| static NtpTimeServiceT & | instance () noexcept |
| Return the singleton instance. | |
Private Member Functions | |
| bool | is_running_locked () const noexcept |
| Check runner status under lock. | |
| std::unique_ptr< RunnerT > | build_runner_locked () |
| Build a runner with current server list and pool config. | |
Private Attributes | |
| std::mutex | m_mtx |
| std::chrono::milliseconds | m_interval {std::chrono::seconds(30)} |
| bool | m_measure_immediately {true} |
| bool | m_has_custom_servers {false} |
| std::vector< NtpServerConfig > | m_servers |
| bool | m_has_custom_pool_cfg {false} |
| NtpPoolConfig | m_pool_cfg {} |
| std::unique_ptr< RunnerT > | m_runner |
Static Private Attributes | |
| static NtpTimeServiceT | m_instance |
Singleton service for background NTP measurements.
Uses an internal runner to keep offset updated. It exposes UTC time computed as realtime clock plus the latest offset. Configure pool servers and sampling before starting the service.
Definition at line 200 of file ntp_time_service.hpp.
|
delete |
|
default |
Construct service.
|
inline |
Stop background runner on destruction.
Definition at line 447 of file ntp_time_service.hpp.
|
inline |
Apply current config by rebuilding the runner.
Definition at line 453 of file ntp_time_service.hpp.
|
inlineprivate |
Build a runner with current server list and pool config.
Definition at line 501 of file ntp_time_service.hpp.
|
inline |
Clear custom server list and return to default behavior.
Definition at line 403 of file ntp_time_service.hpp.
|
inlinenoexcept |
Ensure background runner is started with current config.
Definition at line 287 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return number of failed measurement attempts.
Definition at line 342 of file ntp_time_service.hpp.
|
inline |
Start background measurements using stored interval.
Definition at line 217 of file ntp_time_service.hpp.
|
inline |
Start background measurements with interval and immediate flag.
| interval | Measurement interval. |
| measure_immediately | Measure before first sleep if true. |
Definition at line 225 of file ntp_time_service.hpp.
|
inlinestaticnoexcept |
Return the singleton instance.
Definition at line 204 of file ntp_time_service.hpp.
|
inlineprivatenoexcept |
Check runner status under lock.
Definition at line 496 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return whether last measurement updated the offset.
Definition at line 326 of file ntp_time_service.hpp.
|
inline |
Return copy of last measurement samples.
Definition at line 438 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last successful measurement.
Definition at line 358 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return realtime timestamp of last measurement attempt.
Definition at line 350 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return total number of measurement attempts.
Definition at line 334 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return last estimated offset in microseconds.
Definition at line 296 of file ntp_time_service.hpp.
|
delete |
|
inline |
Return current pool configuration.
Definition at line 428 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return true when background runner is active.
Definition at line 281 of file ntp_time_service.hpp.
|
inline |
Use conservative default servers for new runner instances.
Definition at line 391 of file ntp_time_service.hpp.
|
inline |
Override pool configuration for new runner instances.
| cfg | Pool configuration to apply. |
Definition at line 416 of file ntp_time_service.hpp.
|
inline |
Replace server list used for new runner instances.
| servers | Server configurations to use. |
Definition at line 379 of file ntp_time_service.hpp.
|
inline |
Stop background measurements and release resources.
Definition at line 263 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return true when last measurement is older than max_age.
| max_age | Maximum allowed age. |
Definition at line 367 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in milliseconds based on offset.
Definition at line 314 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in seconds based on offset.
Definition at line 320 of file ntp_time_service.hpp.
|
inlinenoexcept |
Return current UTC time in microseconds based on offset.
Definition at line 305 of file ntp_time_service.hpp.
|
private |
Definition at line 530 of file ntp_time_service.hpp.
|
private |
Definition at line 527 of file ntp_time_service.hpp.
|
staticprivate |
Definition at line 536 of file ntp_time_service.hpp.
|
private |
Definition at line 524 of file ntp_time_service.hpp.
|
private |
Definition at line 525 of file ntp_time_service.hpp.
|
mutableprivate |
Definition at line 523 of file ntp_time_service.hpp.
|
private |
Definition at line 531 of file ntp_time_service.hpp.
|
private |
Definition at line 533 of file ntp_time_service.hpp.
|
private |
Definition at line 528 of file ntp_time_service.hpp.