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

TimerSource.hh

Go to the documentation of this file.
00001 // $Id: TimerSource.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
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_TimerSource_
00027 #define HH_SENF_Scheduler_TimerSource_ 1
00028 
00029 // Custom includes
00030 #include <boost/utility.hpp>
00031 #include <signal.h>
00032 #include "ClockService.hh"
00033 #include "FdManager.hh"
00034 
00035 //#include "TimerSource.mpp"
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 namespace senf {
00039 namespace scheduler {
00040 namespace detail {
00041 
00042     class TimerSource
00043         : boost::noncopyable
00044     {
00045     public:
00046         virtual ~TimerSource();
00047 
00048         virtual void timeout(ClockService::clock_type timeout) = 0;
00049         virtual void notimeout() = 0;
00050 
00051         virtual void enable() = 0;
00052         virtual void disable() = 0;
00053 
00054     protected:
00055         TimerSource();
00056     };
00057 
00058     class POSIXTimerSource
00059         : public detail::FdManager::Event, public TimerSource
00060     {
00061     public:
00062         POSIXTimerSource();
00063         ~POSIXTimerSource();
00064 
00065         virtual void timeout(ClockService::clock_type timeout);
00066         virtual void notimeout();
00067 
00068         virtual void enable();
00069         virtual void disable();
00070 
00071     private:
00072         static void sigHandler(int signal, ::siginfo_t * siginfo, void *);
00073         virtual void signal(int events);
00074         void reschedule();
00075 
00076         bool timeoutEnabled_;
00077         ClockService::clock_type timeout_;
00078         int timerPipe_[2];
00079         sigset_t sigSet_;
00080         bool signalEnabled_;
00081         timer_t timerId_;
00082     };
00083 
00084     class PollTimerSource
00085         : public TimerSource
00086     {
00087     public:
00088         virtual void timeout(ClockService::clock_type timeout);
00089         virtual void notimeout();
00090 
00091         virtual void enable();
00092         virtual void disable();
00093     };
00094 
00095 #ifdef HAVE_TIMERFD_CREATE
00096     class TimerFDTimerSource
00097         : public detail::FdManager::Event, public TimerSource
00098     {
00099     public:
00100         TimerFDTimerSource();
00101         ~TimerFDTimerSource();
00102 
00103         virtual void timeout(ClockService::clock_type timeout);
00104         virtual void notimeout();
00105 
00106         virtual void enable();
00107         virtual void disable();
00108 
00109         static bool haveTimerFD();
00110 
00111     private:
00112         virtual void signal(int events);
00113         void reschedule();
00114 
00115         int timerfd_;
00116         bool timeoutEnabled_;
00117         ClockService::clock_type timeout_;
00118     };
00119 #endif
00120 
00121 }}}
00122 
00123 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00124 #include "TimerSource.cci"
00125 //#include "TimerSource.ct"
00126 //#include "TimerSource.cti"
00127 #endif
00128 
00129 
00130 // Local Variables:
00131 // mode: c++
00132 // fill-column: 100
00133 // comment-column: 40
00134 // c-file-style: "senf"
00135 // indent-tabs-mode: nil
00136 // ispell-local-dictionary: "american"
00137 // compile-command: "scons -u test"
00138 // End:

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