16 _io_service(_service->GetAsioService()),
17 _strand(*_io_service),
18 _strand_required(_service->IsStrandRequired()),
23 throw CppCommon::ArgumentException(
"Asio service is invalid!");
28 _io_service(_service->GetAsioService()),
29 _strand(*_io_service),
30 _strand_required(_service->IsStrandRequired()),
35 throw CppCommon::ArgumentException(
"Asio service is invalid!");
40 _io_service(_service->GetAsioService()),
41 _strand(*_io_service),
42 _strand_required(_service->IsStrandRequired()),
47 throw CppCommon::ArgumentException(
"Asio service is invalid!");
52 _io_service(_service->GetAsioService()),
53 _strand(*_io_service),
54 _strand_required(_service->IsStrandRequired()),
60 throw CppCommon::ArgumentException(
"Asio service is invalid!");
63 throw CppCommon::ArgumentException(
"Action function is invalid!");
66Timer::Timer(
const std::shared_ptr<Service>& service,
const std::function<
void(
bool)>&
action,
const CppCommon::UtcTime&
time)
68 _io_service(_service->GetAsioService()),
69 _strand(*_io_service),
70 _strand_required(_service->IsStrandRequired()),
76 throw CppCommon::ArgumentException(
"Asio service is invalid!");
79 throw CppCommon::ArgumentException(
"Action function is invalid!");
84 _io_service(_service->GetAsioService()),
85 _strand(*_io_service),
86 _strand_required(_service->IsStrandRequired()),
92 throw CppCommon::ArgumentException(
"Asio service is invalid!");
95 throw CppCommon::ArgumentException(
"Action function is invalid!");
100 return CppCommon::UtcTime(_timer.expires_at());
105 return CppCommon::Timespan(_timer.expires_from_now());
111 _timer.expires_at(
time.chrono(),
ec);
126 _timer.expires_from_now(
timespan.chrono(),
ec);
174 if (
ec == asio::error::operation_aborted)
187 if (_strand_required)
201 if (
ec == asio::error::operation_aborted)
232void Timer::SendError(std::error_code
ec)
235 if (
ec == asio::error::operation_aborted)
241void Timer::SendTimer(
bool canceled)
Asio allocate handler wrapper.
virtual bool Cancel()
Cancel any wait operation on the timer.
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
virtual bool WaitSync()
Wait for the timer (synchronous)
CppCommon::UtcTime expire_time() const
Get the timer's expiry time as an absolute time.
Timer(const std::shared_ptr< Service > &service)
Initialize timer with a given Asio service.
virtual void onTimer(bool canceled)
Handle timer notification.
CppCommon::Timespan expire_timespan() const
Get the timer's expiry time relative to now.
virtual bool Setup(const CppCommon::UtcTime &time)
Setup the timer with absolute expiry time.
virtual bool WaitAsync()
Wait for the timer (asynchronous)
virtual void onError(int error, const std::string &category, const std::string &message)
Handle error notification.
C++ Server project definitions.