delayed-call-table.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_DELAYED_CALL_TABLE_HPP
23 #define NDN_DELAYED_CALL_TABLE_HPP
24 
25 #include <deque>
26 #include <ndn-cpp/face.hpp>
27 
28 namespace ndn {
29 
31 public:
38  void
39  callLater(Milliseconds delayMilliseconds, const Face::Callback& callback);
40 
46  void
47  callTimedOut();
48 
49 private:
50  class Entry {
51  public:
58  Entry(Milliseconds delayMilliseconds, const Face::Callback& callback);
59 
65  getCallTime() const { return callTime_; }
66 
71  void
72  callCallback() const { callback_(); }
73 
77  class Compare {
78  public:
79  bool
80  operator()
81  (const ptr_lib::shared_ptr<const Entry>& x,
82  const ptr_lib::shared_ptr<const Entry>& y) const
83  {
84  return x->callTime_ < y->callTime_;
85  }
86  };
87 
88  private:
89  const Face::Callback callback_;
90  MillisecondsSince1970 callTime_;
91  };
92 
93  // Use a deque so we can efficiently remove from the front.
94  std::deque<ptr_lib::shared_ptr<Entry> > table_;
95  Entry::Compare entryCompare_;
96 };
97 
98 }
99 
100 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:111
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Definition: delayed-call-table.hpp:30
func_lib::function< void()> Callback
Face::Callback is used internally in callLater.
Definition: face.hpp:674
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
void callTimedOut()
Call and remove timed-out callback entries.
Definition: delayed-call-table.cpp:41
void callLater(Milliseconds delayMilliseconds, const Face::Callback &callback)
Call callback() after the given delay.
Definition: delayed-call-table.cpp:32
Compare shared_ptrs to Entry based only on callTime_.
Definition: delayed-call-table.hpp:77