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()
34 : entrySetById( entrySet.template get<Id>()),
35 entrySetByTimeout( entrySet.template get<Timeout> ()),
36 timer( "TimerEventProxy", membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
39 template<typename IdType>
40 prefix_ senf::scheduler::TimerEventProxy<IdType>::TimerEventProxy(std::string const & name, console::DirectoryNode & node)
41 : entrySetById( entrySet.template get<Id>()),
42 entrySetByTimeout( entrySet.template get<Timeout> ()),
43 timer( "TimerEventProxy", membind(&TimerEventProxy<IdType>::timerEvent, this), 0, false)
45 node.add(name, console::factory::Command(
46 &TimerEventProxy<IdType>::list, this) .doc("List active Timers"));
49 template<typename IdType>
50 prefix_ void senf::scheduler::TimerEventProxy<IdType>::timerEvent()
52 ClockService::clock_type actual = ClockService::now();
53 typename EntrySetByTimeout_t::iterator it = entrySetByTimeout.begin();
54 while (it != entrySetByTimeout.end() && it->timeout <= actual) {
56 // remove due entry from set
57 entrySetByTimeout.erase(it);
59 item.cb(actual, item.id);
60 it = entrySetByTimeout.begin();
62 if (entrySet.size() > 0)
63 timer.timeout(entrySetByTimeout.begin()->timeout);
66 template<typename IdType>
67 prefix_ void senf::scheduler::TimerEventProxy<IdType>::add(
68 ClockService::clock_type timeout, IdType const & id, Callback cb)
71 entrySetByTimeout.insert( Entry(timeout, id, cb));
72 // the scheduler time to the first earliest timeout (ordered index)
73 timer.timeout( entrySetByTimeout.begin()->timeout);
76 template<typename IdType>
77 prefix_ bool senf::scheduler::TimerEventProxy<IdType>::remove(IdType const & id)
79 return entrySetById.erase( id) > 0;
82 template<typename IdType>
83 prefix_ senf::ClockService::clock_type senf::scheduler::TimerEventProxy<IdType>::timeout(IdType const & id)
86 typename EntrySetById_t::const_iterator i ( entrySetById.find( id));
87 return i == entrySetById.end() ? 0 : i->timeout;
91 template<typename IdType>
92 prefix_ std::vector<std::pair<senf::ClockService::clock_type, IdType> > senf::scheduler::TimerEventProxy<IdType>::list()
95 std::vector<std::pair<ClockService::clock_type, IdType> > tmp;
97 typename EntrySetByTimeout_t::const_iterator it;
98 for (it = entrySetByTimeout.begin(); it != entrySetByTimeout.end(); ++it) {
99 tmp.push_back(std::make_pair<ClockService::clock_type, IdType>( it->timeout, it->id));
104 ///////////////////////////////ct.e////////////////////////////////////////
111 // c-file-style: "senf"
112 // indent-tabs-mode: nil
113 // ispell-local-dictionary: "american"
114 // compile-command: "scons -u test"
115 // comment-column: 40