1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 5 #include "hmbdc/Exception.hpp" 6 #include "hmbdc/Compile.hpp" 13 #include <boost/intrusive/set.hpp> 16 namespace hmbdc {
namespace time {
18 using namespace hmbdc;
27 : boost::intrusive::set_base_hook<
28 boost::intrusive::link_mode<boost::intrusive::normal_link>
33 SysTime getFireAt()
const {
return fireAt_; }
36 using Callback = std::function<void (TimerManager&, SysTime const&)>;
37 Timer(Callback cb = detail::noop)
41 void setCallback(Callback cb) {
45 bool operator < (
Timer const& other)
const 46 {
return fireAt_ < other.fireAt_; }
47 bool operator <= (
SysTime const& t)
const 48 {
return !(t < fireAt_); }
71 timer.fireAt_ = fireAt;
72 timers_.insert(timer);
82 auto range = timers_.equal_range(timer);
83 for (
auto it = range.first; it != range.second; ++it) {
95 using Timers = boost::intrusive::multiset<Timer>;
108 { tm.schedule(now + interval, *
this); };
117 Duration day = Duration::seconds(86400);
118 SysTime newFireTime = getFireAt() + day;
119 while (newFireTime < now) newFireTime += day;
120 tm.schedule(newFireTime, *
this);
Definition: Timers.hpp:26
Definition: Timers.hpp:69
Definition: Timers.hpp:111
void cancel(Timer &timer)
cancel a timer previously scheduled with the TimerManager
Definition: Timers.hpp:81
Definition: Timers.hpp:124
Definition: Client.hpp:11
Definition: Timers.hpp:100