39#if !defined(NDEBUG) || defined(DEBUG_TIMER_OBJECTS)
62 return &aLeft < &aRight;
73 class subscriber_wrapper :
public lifetime<reference_counted<i_timer_subscriber>>
76 subscriber_wrapper(
i_timer_object& aTimerObject, std::function<
void()> aCallback) :
77 iTimerObject{ &aTimerObject }, iCallback { aCallback }
82#if !defined(NDEBUG) || defined(DEBUG_TIMER_OBJECTS)
83 if (iTimerObject !=
nullptr)
85 if (iTimerObject->debug())
87 std::cerr <<
"i_timer_object::subscriber_wrapper::~subscriber_wrapper()" << std::endl;
93 void timer_expired(i_timer_object&)
override
95#if !defined(NDEBUG) || defined(DEBUG_TIMER_OBJECTS)
98 if (iTimerObject->debug())
100 std::cerr <<
"i_timer_object::subscriber_wrapper::timer_expired(...)" << std::endl;
106 bool attached()
const override
108 return iTimerObject !=
nullptr;
110 void detach()
override
114 if (iTimerObject->debug())
116 std::cerr <<
"i_timer_object::subscriber_wrapper::detach()" << std::endl;
118 iTimerObject =
nullptr;
122 i_timer_object* iTimerObject;
123 std::function<void()> iCallback;
128 virtual void expires_at(
const std::chrono::steady_clock::time_point& aDeadline) = 0;
138 template <
typename Duration>
141 expires_at(std::chrono::steady_clock::now() + std::chrono::duration_cast<std::chrono::nanoseconds>(aDuration));
145 auto subscriber = make_ref<subscriber_wrapper>(*
this, [aSubscriber]() { aSubscriber(); });
151 auto subscriber = make_ref<subscriber_wrapper>(*
this, [
this, aSubscriber]() { aSubscriber(*
this); });
i_timer_subscriber & async_wait(const std::function< void()> &aSubscriber)
i_timer_object abstract_type
virtual void unsubscribe(i_timer_subscriber &aSubscriber)=0
virtual void set_debug(bool aDebug)=0
i_timer_subscriber & async_wait(const std::function< void(i_timer_object &)> &aSubscriber)
virtual void expires_at(const std::chrono::steady_clock::time_point &aDeadline)=0
virtual bool debug() const =0
virtual ~i_timer_object()=default
void expires_from_now(const Duration &aDuration)
virtual void async_wait(i_timer_subscriber &aSubscriber)=0
virtual ~i_timer_subscriber()=default
virtual void timer_expired(i_timer_object &aTimerObject)=0
i_timer_subscriber abstract_type
virtual bool attached() const =0
friend bool operator<(const i_timer_subscriber &aLeft, const i_timer_subscriber &aRight)