X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FScheduler%2FTimerEventProxy.hh;h=9d40e3dd7e42ededc808c9bc255a73a91120cc26;hb=2b2af7d62142f61f5804df2184b58e5f7ce3bd06;hp=ae77e58eb4ad12e8efb100104a5ce2805e11fa46;hpb=acce6d54436fa760c0f4770ea3a6c76ae40e0bb8;p=senf.git diff --git a/senf/Scheduler/TimerEventProxy.hh b/senf/Scheduler/TimerEventProxy.hh index ae77e58..9d40e3d 100644 --- a/senf/Scheduler/TimerEventProxy.hh +++ b/senf/Scheduler/TimerEventProxy.hh @@ -4,6 +4,7 @@ // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Mathias Kretschmer +// Jens Moedeker // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,7 +22,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief TimerEventProxy public header */ + \brief TimerEventProxy public header */ #ifndef HH_SENF_Scheduler_TimerEventProxy_ #define HH_SENF_Scheduler_TimerEventProxy_ 1 @@ -34,51 +35,55 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include -#include +#include namespace senf { namespace scheduler { - /** \brief Deadline timer proxy The TimerEventProxy is meant to host long term deadline timers to reduce the load of the - Scheduler with a hugh count of TimerEvent items. It registers deadline timer callbacks which + Scheduler with a huge count of TimerEvent items. It registers deadline timer callbacks which will be called when the timer expires. The functionality is based on one TimerEvent instance per TimerEventProxy instance and could host a big count of timers. */ - template - class TimerEventProxy { - private: + template + class TimerEventProxy + { + public: + /////////////////////////////////////////////////////////////////////////// + // Types + typedef boost::function Callback; - template + TimerEventProxy(); + ///< Instantiate a TimerEventProxy + + TimerEventProxy(std::string const & name, senf::console::DirectoryNode & node); + ///< Instantiate a TimerEventProxy and add the list command to the give DirectoryNode + + void add(senf::ClockService::clock_type timeout, IdType const &id, Callback cb); + ///< Add new deadline timer + bool remove(IdType const & id); + ///< Remove timer by given \a id. + std::vector > list(); + ///< Returns a vector of all active timers with timeout and id. + + private: +#ifndef DOXYGEN struct Entry { - public: senf::ClockService::clock_type timeout; - T id; - boost::function fkt; - - bool operator<(const Entry & e) const { - return id < e.id; - } - // bool operator==(const Entry &e)const{return id == e.id;} - Entry(senf::ClockService::clock_type _timeout, T_ _id, boost::function _fkt) : - timeout(_timeout), id(_id), fkt(_fkt) { - } - }; + IdType id; + Callback cb; + Entry(senf::ClockService::clock_type _timeout, IdType _id, Callback _cb) + : timeout(_timeout), id(_id), cb(_cb) { } + }; senf::scheduler::TimerEvent timer; @@ -87,46 +92,30 @@ namespace scheduler { // struct Timeout {}; struct Id {}; - typedef boost::multi_index_container , - boost::multi_index::indexed_by< - boost::multi_index::ordered_non_unique< - boost::multi_index::tag, - boost::multi_index::member , - senf::ClockService::clock_type, - &Entry::timeout> >, - boost::multi_index::ordered_unique, boost::multi_index::identity > > > > - EntrySet; - - typedef typename EntrySet::template index::type - EntrySetByTimeout_t; - typedef typename EntrySet::template index::type EntrySetById_t; - - EntrySet entrySet; +#endif + typedef boost::multi_index_container< + Entry, + boost::multi_index::indexed_by< + boost::multi_index::ordered_non_unique< + boost::multi_index::tag, + boost::multi_index::member + >, + boost::multi_index::ordered_unique< + boost::multi_index::tag, + boost::multi_index::member + > + > + > EntrySet_t; + + typedef typename EntrySet_t::template index::type EntrySetByTimeout_t; + typedef typename EntrySet_t::template index::type EntrySetById_t; + + EntrySet_t entrySet; EntrySetById_t & entrySetById; EntrySetByTimeout_t & entrySetByTimeout; - private: // callback for the Scheduler timer event void timerEvent(); - - public: - /////////////////////////////////////////////////////////////////////////// - // Types - typedef boost::function Callback; - - TimerEventProxy(); - ///< Instantiate a TimerEventProxy - - TimerEventProxy(std::string const & name, senf::console::DirectoryNode & node); - ///< Instantiate a TimerEventProxy and add the list command to the give DirectoryNode - - void add(senf::ClockService::clock_type timeout, T const &id, Callback cb); - ///< Add new deadline timer - bool del(T const & id); - ///< Remove timer by given \a id. - std::vector > list(); - ///< Returns a vector of all active timers with timeout and id. }; } }