29class Timer :
public std::enable_shared_from_this<Timer>
42 Timer(
const std::shared_ptr<Service>&
service,
const CppCommon::UtcTime& time);
48 Timer(
const std::shared_ptr<Service>&
service,
const CppCommon::Timespan& timespan);
54 Timer(
const std::shared_ptr<Service>&
service,
const std::function<
void(
bool)>& action);
61 Timer(
const std::shared_ptr<Service>&
service,
const std::function<
void(
bool)>& action,
const CppCommon::UtcTime& time);
68 Timer(
const std::shared_ptr<Service>&
service,
const std::function<
void(
bool)>& action,
const CppCommon::Timespan& timespan);
77 std::shared_ptr<Service>&
service() noexcept {
return _service; }
79 std::shared_ptr<asio::io_context>&
io_context() noexcept {
return _io_context; }
81 asio::io_context::strand&
strand() noexcept {
return _strand; }
93 virtual bool Setup(
const CppCommon::UtcTime& time);
99 virtual bool Setup(
const CppCommon::Timespan& timespan);
105 virtual bool Setup(
const std::function<
void(
bool)>& action);
112 virtual bool Setup(
const std::function<
void(
bool)>& action,
const CppCommon::UtcTime& time);
119 virtual bool Setup(
const std::function<
void(
bool)>& action,
const CppCommon::Timespan& timespan);
148 virtual void onError(
int error,
const std::string& category,
const std::string& message) {}
152 std::shared_ptr<Service> _service;
154 std::shared_ptr<asio::io_context> _io_context;
156 asio::io_context::strand _strand;
157 bool _strand_required;
159 asio::system_timer _timer;
161 std::function<void(
bool)> _action;
164 void SendError(std::error_code ec);
166 void SendTimer(
bool canceled);