4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Mathias Kretschmer <mtk@berlios.de>
7 // Jens Moedeker <jens.moedeker@fokus.fraunhofer.de>
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the
21 // Free Software Foundation, Inc.,
22 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 \brief TimerEventProxy public header */
27 #ifndef HH_SENF_Scheduler_TimerEventProxy_
28 #define HH_SENF_Scheduler_TimerEventProxy_ 1
31 #include <boost/multi_index_container.hpp>
32 #include <boost/multi_index/ordered_index.hpp>
33 #include <boost/multi_index/member.hpp>
35 #include <senf/Scheduler/ClockService.hh>
36 #include <senf/Scheduler/TimerEvent.hh>
37 #include <senf/Utils/Console/Console.hh>
39 ///////////////////////////////hh.p////////////////////////////////////////
43 /** \brief Deadline timer proxy
45 The TimerEventProxy is meant to host long term deadline timers to reduce the load of the
46 Scheduler with a huge count of TimerEvent items. It registers deadline timer callbacks which
47 will be called when the timer expires.
49 The functionality is based on one TimerEvent instance per TimerEventProxy instance and could
50 host a big count of timers.
52 template<typename IdType>
56 typedef boost::function<void(ClockService::clock_type, IdType const &)> Callback;
58 TimerEventProxy(std::string const & description = "");
59 ///< Instantiate a TimerEventProxy
60 /**< \param[in] description Descriptive name (purely informational) */
62 void add(ClockService::clock_type timeout, IdType const & id, Callback cb);
63 ///< Add new deadline timer
65 bool remove(IdType const & id); ///< Remove timer by given \a id.
67 std::vector<std::pair<ClockService::clock_type, IdType> > list() const;
68 ///< Returns a vector of all active timers with timeout and id.
70 ClockService::clock_type timeout(IdType const & id) const;
71 ///< Returns timeout for given id
72 /**< if no timer for this id is registered \a 0 is returned. */
76 ClockService::clock_type timeout;
80 Entry(ClockService::clock_type _timeout, IdType _id, Callback _cb)
81 : timeout(_timeout), id(_id), cb(_cb) { }
86 // data structure to hold active timers
87 typedef boost::multi_index_container<
89 boost::multi_index::indexed_by<
90 boost::multi_index::ordered_non_unique<
91 boost::multi_index::tag<Timeout>,
92 boost::multi_index::member<Entry, ClockService::clock_type, &Entry::timeout>
94 boost::multi_index::ordered_unique<
95 boost::multi_index::tag<Id>,
96 boost::multi_index::member<Entry, IdType, &Entry::id>
100 typedef typename EntrySet_t::template index<Timeout>::type EntrySetByTimeout_t;
101 typedef typename EntrySet_t::template index<Id>::type EntrySetById_t;
104 EntrySetById_t & entrySetById;
105 EntrySetByTimeout_t & entrySetByTimeout;
107 scheduler::TimerEvent timer;
109 void timerEvent(); // callback for the Scheduler timer event
114 ///////////////////////////////hh.e////////////////////////////////////////
115 //#include "TimerEventProxy.cci"
116 #include "TimerEventProxy.ct"
117 //#include "TimerEventProxy.cti"
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"