8 #ifndef XCLOX_CLIENT_HPP
9 #define XCLOX_CLIENT_HPP
65 : m_callable(callable)
80 void query(
const std::string& server,
const std::chrono::milliseconds& timeout = std::chrono::milliseconds(DefaultTimeout::ms))
82 std::lock_guard<std::mutex> lock(m_mutex);
84 m_queryList.push_back(
Query::start(m_pool, server, m_callable, timeout));
90 m_callable = std::move(callable);
96 std::lock_guard<std::mutex> lock(m_mutex);
97 for (
auto query : m_queryList) {
98 if (
auto shared =
query.lock()) {
106 void purgeQueryList()
108 m_queryList.remove_if(std::mem_fn(&std::weak_ptr<Query>::expired));
112 asio::thread_pool m_pool;
114 std::list<std::weak_ptr<Query>> m_queryList;
Client is an asynchronous multi-query NTP client.
Definition: client.hpp:47
void query(const std::string &server, const std::chrono::milliseconds &timeout=std::chrono::milliseconds(DefaultTimeout::ms))
Place a NTP query [thread-safe].
Definition: client.hpp:80
void setCallback(Callback callable)
Register a callable for reporting the result of the query back to the caller.
Definition: client.hpp:88
void cancel()
Cancel all current queries [thread-safe].
Definition: client.hpp:94
Query::Callback Callback
Type of query callback.
Definition: client.hpp:54
~Client()
Default destructor.
Definition: client.hpp:70
Client(Callback callable)
Default constructor.
Definition: client.hpp:64
Query::DefaultTimeout DefaultTimeout
Type of query timeout holder.
Definition: client.hpp:56
internal::DefaultTimeout< QuerySingle, 5000 > DefaultTimeout
Type of query timeout milliseconds holder.
Definition: query.hpp:65
std::function< void(const std::string &, const std::string &, Status, const Packet &, const std::chrono::steady_clock::duration &)> Callback
Type of query callback.
Definition: query.hpp:64
static std::weak_ptr< Query > start(asio::thread_pool &pool, const std::string &server, Callback callback, const std::chrono::milliseconds &timeout=std::chrono::milliseconds(DefaultTimeout::ms))
Starts querying all resolved addresses of server one at a time until success.
Definition: query.hpp:87
Status
Type of query status.
Definition: query.hpp:55