00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027 #ifndef HH_SENF_Scheduler_TimerEventProxy_
00028 #define HH_SENF_Scheduler_TimerEventProxy_ 1
00029
00030
00031 #include <boost/multi_index_container.hpp>
00032 #include <boost/multi_index/ordered_index.hpp>
00033 #include <boost/multi_index/member.hpp>
00034
00035 #include <senf/Scheduler/ClockService.hh>
00036 #include <senf/Scheduler/TimerEvent.hh>
00037
00038
00039 namespace senf {
00040 namespace scheduler {
00041
00051 template<typename IdType>
00052 class TimerEventProxy
00053 {
00054 public:
00055 typedef boost::function<void(ClockService::clock_type, IdType const &)> Callback;
00056
00057 TimerEventProxy(std::string const & description = "");
00059
00061 void add(ClockService::clock_type timeout, IdType const & id, Callback cb);
00063
00064 bool remove(IdType const & id);
00065
00066 std::vector<std::pair<ClockService::clock_type, IdType> > list() const;
00068
00069 ClockService::clock_type timeout(IdType const & id) const;
00071
00073 unsigned numEvents() const;
00074
00075 void clear();
00076
00077 private:
00078 #ifndef DOXYGEN
00079 struct Entry {
00080 ClockService::clock_type timeout;
00081 IdType id;
00082 Callback cb;
00083
00084 Entry(ClockService::clock_type _timeout, IdType _id, Callback _cb)
00085 : timeout(_timeout), id(_id), cb(_cb) { }
00086 };
00087 struct Timeout {};
00088 struct Id {};
00089 #endif
00090
00091 typedef boost::multi_index_container<
00092 Entry,
00093 boost::multi_index::indexed_by<
00094 boost::multi_index::ordered_non_unique<
00095 boost::multi_index::tag<Timeout>,
00096 boost::multi_index::member<Entry, ClockService::clock_type, &Entry::timeout>
00097 >,
00098 boost::multi_index::ordered_unique<
00099 boost::multi_index::tag<Id>,
00100 boost::multi_index::member<Entry, IdType, &Entry::id>
00101 >
00102 >
00103 > EntrySet_t;
00104 typedef typename EntrySet_t::template index<Timeout>::type EntrySetByTimeout_t;
00105 typedef typename EntrySet_t::template index<Id>::type EntrySetById_t;
00106
00107 EntrySet_t entrySet;
00108 EntrySetById_t & entrySetById;
00109 EntrySetByTimeout_t & entrySetByTimeout;
00110
00111 scheduler::TimerEvent timer;
00112
00113 void timerEvent();
00114 };
00115
00116 }}
00117
00118
00119
00120 #include "TimerEventProxy.ct"
00121
00122 #endif
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133