4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Mathias Kretschmer <mtk@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief TimerEventProxy public header */
29 prefix_ senf::scheduler::TimerEventProxy<T>::TimerEventProxy() :
30 timer("timer", senf::membind(&TimerEventProxy<T>::timerEvent, this), 0,
31 false), entrySetById(entrySet.template get<Id> ()),
32 entrySetByTimeout(entrySet.template get<Timeout> ())
38 prefix_ senf::scheduler::TimerEventProxy<T>::TimerEventProxy( std::string const & name,
39 senf::console::DirectoryNode & node) :
40 timer("timer", senf::membind(&TimerEventProxy<T>::timerEvent, this), 0,
41 false), entrySetById(entrySet.template get<Id> ()),
42 entrySetByTimeout(entrySet.template get<Timeout> ())
44 node.add(name, senf::console::factory::Command(
45 &TimerEventProxy<T>::listTimers, this) .doc("List active Timers"));
49 prefix_ void senf::scheduler::TimerEventProxy<T>::timerEvent() {
51 senf::ClockService::clock_type actual = senf::ClockService::now();
52 typename EntrySetByTimeout_t::iterator it;
54 // execute the timer callbacks first
56 it = entrySetByTimeout.begin();
57 while (it != entrySetByTimeout.end() && it->timeout <= actual) {
59 // remove due entry from set
60 entrySetByTimeout.erase(it);
62 item.fkt(actual, item.id);
64 it = entrySetByTimeout.begin();
67 if (entrySet.size() > 0) {
68 timer.timeout(entrySetByTimeout.begin()->timeout);
73 prefix_ void senf::scheduler::TimerEventProxy<T>::add(
74 senf::ClockService::clock_type timeout, T const & id, Callback fkt)
77 entrySetByTimeout.insert(Entry<T> (timeout, id, fkt));
79 // the scheduler time to the first earliest timeout (ordered index)
80 timer.timeout(entrySetByTimeout.begin()->timeout);
82 // // if map was empty before, hence we need to activate the time event object
83 // if( entrySetByTimeout.size() >= 1){
89 prefix_ bool senf::scheduler::TimerEventProxy<T>::del(T const & id)
91 typename EntrySetById_t::iterator it(entrySetById.find(Entry<T> (0, id, NULL)));
93 if (it != entrySetById.end()) {
94 entrySetById.erase(it);
101 prefix_ std::vector<std::pair<senf::ClockService::clock_type, T> > senf::scheduler::TimerEventProxy<T>::list()
103 std::vector<std::pair<senf::ClockService::clock_type, T> > tmp;
105 typename EntrySetByTimeout_t::iterator it;
106 for (it = entrySetByTimeout.begin(); it != entrySetByTimeout.end(); ++it) {
107 tmp.push_back(std::make_pair<senf::ClockService::clock_type, T>( it->timeout, it->id));