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 non-inline template implementation */
30 ///////////////////////////////ct.p////////////////////////////////////////
32 template<typename IdType>
33 prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy(std::string const & description)
34 : entrySetById( entrySet.template get<Id>()),
35 entrySetByTimeout( entrySet.template get<Timeout> ()),
36 timer( "TimerEventProxy " + description,
37 membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
40 template<typename IdType>
41 prefix_ void senf::scheduler::TimerEventProxy<IdType>::timerEvent()
43 ClockService::clock_type now = ClockService::now();
44 typename EntrySetByTimeout_t::iterator it = entrySetByTimeout.begin();
45 while (it != entrySetByTimeout.end() && it->timeout <= now) {
47 // remove due entry from set
48 entrySetByTimeout.erase(it);
50 item.cb(now, item.id);
51 it = entrySetByTimeout.begin();
53 if (entrySet.size() > 0)
54 timer.timeout(entrySetByTimeout.begin()->timeout);
57 template<typename IdType>
58 prefix_ void senf::scheduler::TimerEventProxy<IdType>::add(
59 ClockService::clock_type timeout, IdType const & id, Callback cb)
62 entrySetByTimeout.insert( Entry(timeout, id, cb));
63 // the scheduler time to the first earliest timeout (ordered index)
64 timer.timeout( entrySetByTimeout.begin()->timeout);
67 template<typename IdType>
68 prefix_ bool senf::scheduler::TimerEventProxy<IdType>::remove(IdType const & id)
70 bool removed (entrySetById.erase( id) > 0);
71 if (entrySet.size() > 0)
72 timer.timeout(entrySetByTimeout.begin()->timeout);
78 template<typename IdType>
79 prefix_ senf::ClockService::clock_type senf::scheduler::TimerEventProxy<IdType>::timeout(IdType const & id)
82 typename EntrySetById_t::const_iterator i ( entrySetById.find( id));
83 return i == entrySetById.end() ? 0 : i->timeout;
87 template<typename IdType>
88 prefix_ std::vector<std::pair<senf::ClockService::clock_type, IdType> > senf::scheduler::TimerEventProxy<IdType>::list()
91 std::vector<std::pair<ClockService::clock_type, IdType> > tmp;
93 typename EntrySetByTimeout_t::const_iterator it;
94 for (it = entrySetByTimeout.begin(); it != entrySetByTimeout.end(); ++it) {
95 tmp.push_back(std::make_pair<ClockService::clock_type, IdType>( it->timeout, it->id));
100 ///////////////////////////////ct.e////////////////////////////////////////
107 // c-file-style: "senf"
108 // indent-tabs-mode: nil
109 // ispell-local-dictionary: "american"
110 // compile-command: "scons -u test"
111 // comment-column: 40