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

TimerEvent.hh

Go to the documentation of this file.
00001 // $Id: TimerEvent.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_TimerEvent_
00027 #define HH_SENF_Scheduler_TimerEvent_ 1
00028 
00029 // Custom includes
00030 #include <signal.h>
00031 #include <senf/boost_intrusive/iset_hook.hpp>
00032 #include "ClockService.hh"
00033 #include "FIFORunner.hh"
00034 #include <senf/Utils/Logger/SenfLog.hh>
00035 
00036 //#include "TimerEvent.mpp"
00037 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00038 
00039 namespace senf {
00040 namespace scheduler {
00041 
00042     namespace detail {
00043         struct TimerSetTag;
00044         typedef boost::intrusive::iset_base_hook<TimerSetTag> TimerSetBase;
00045         struct TimerSetCompare;
00046         class TimerDispatcher;
00047     }
00048 
00067     class TimerEvent
00068         : public detail::FIFORunner::TaskInfo,
00069           public detail::TimerSetBase
00070     {
00071     public:
00072         //-////////////////////////////////////////////////////////////////////////
00073         // Types
00074 
00075         typedef boost::function<void ()> Callback;
00076 
00077         //-////////////////////////////////////////////////////////////////////////
00079         //\{
00080 
00081         TimerEvent(std::string const & name, Callback const & cb, ClockService::clock_type timeout,
00082                    bool initiallyEnabled = true);
00084 
00095         TimerEvent(std::string const & name, Callback const & cb);
00097 
00103         ~TimerEvent();
00104 
00105         //\}
00106         //-////////////////////////////////////////////////////////////////////////
00107 
00108         void disable();                 
00109         void enable();                  
00110 
00111         void action(Callback const & cb); 
00112         void timeout(ClockService::clock_type timeout, bool initiallyEnabled=true);
00114 
00117         ClockService::clock_type timeout() const;
00119 
00120     private:
00121         virtual void v_run();
00122         virtual char const * v_type() const;
00123         virtual std::string v_info() const;
00124 
00125         Callback cb_;
00126         ClockService::clock_type timeout_;
00127 
00128         friend class detail::TimerDispatcher;
00129         friend class detail::TimerSetCompare;
00130     };
00131 
00132 }}
00133 
00134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00135 #include "TimerEvent.cci"
00136 //#include "TimerEvent.ct"
00137 //#include "TimerEvent.cti"
00138 #endif
00139 
00140 
00141 // Local Variables:
00142 // mode: c++
00143 // fill-column: 100
00144 // comment-column: 40
00145 // c-file-style: "senf"
00146 // indent-tabs-mode: nil
00147 // ispell-local-dictionary: "american"
00148 // compile-command: "scons -u test"
00149 // End:

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