Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

TimerEventProxy.hh

Go to the documentation of this file.
00001 // $Id: TimerEventProxy.hh 1786 2011-05-09 15:46:52Z mtk $
00002 //
00003 // Copyright (C) 2010
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Mathias Kretschmer <mtk@berlios.de>
00007 //     Jens Moedeker <jens.moedeker@fit.fraunhofer.de>
00008 //
00009 // This program is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation; either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the
00021 // Free Software Foundation, Inc.,
00022 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00027 #ifndef HH_SENF_Scheduler_TimerEventProxy_
00028 #define HH_SENF_Scheduler_TimerEventProxy_ 1
00029 
00030 // Custom includes
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         // data structure to hold active timers
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();  // callback for the Scheduler timer event
00114     };
00115 
00116 }}
00117 
00118 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00119 //#include "TimerEventProxy.cci"
00120 #include "TimerEventProxy.ct"
00121 //#include "TimerEventProxy.cti"
00122 #endif
00123 
00124 
00125 // Local Variables:
00126 // mode: c++
00127 // fill-column: 100
00128 // comment-column: 40
00129 // c-file-style: "senf"
00130 // indent-tabs-mode: nil
00131 // ispell-local-dictionary: "american"
00132 // compile-command: "scons -u test"
00133 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research