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.cc

Go to the documentation of this file.
00001 // $Id: TimerEvent.cc 1772 2011-03-10 12:45:21Z tho $
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 #include "TimerEvent.hh"
00027 #include "TimerEvent.ih"
00028 
00029 // Custom includes
00030 #include <sstream>
00031 
00032 //#include "TimerEvent.mpp"
00033 #define prefix_
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 prefix_ senf::scheduler::detail::TimerDispatcher::TimerDispatcher()
00037     : source_ (new PollTimerSource())
00038 {}
00039 
00040 prefix_ senf::scheduler::detail::TimerDispatcher::~TimerDispatcher()
00041 {
00042     TimerSet::iterator i (timers_.begin());
00043     TimerSet::iterator const i_end (timers_.end());
00044     for (; i != i_end; ++i)
00045         FIFORunner::instance().dequeue(&(*i));
00046 }
00047 
00048 void senf::scheduler::detail::TimerDispatcher::add(TimerEvent & event)
00049 {
00050     TimerSet::iterator i (timers_.insert(event));
00051     FIFORunner::instance().enqueue(&(*i));
00052 }
00053 
00054 prefix_ void senf::scheduler::detail::TimerDispatcher::remove(TimerEvent & event)
00055 {
00056     TimerSet::iterator i (TimerSet::current(event));
00057     if (i == timers_.end())
00058         return;
00059     FIFORunner::instance().dequeue(&(*i));
00060     timers_.erase(i);
00061 }
00062 
00063 prefix_ void senf::scheduler::detail::TimerDispatcher::prepareRun()
00064 {
00065     TimerSet::iterator i (timers_.begin());
00066     TimerSet::iterator const i_end (timers_.end());
00067     ClockService::clock_type now (FdManager::instance().eventTime());
00068     for (; i != i_end && i->timeout_ <= now ; ++i)
00069         i->setRunnable();
00070 }
00071 
00072 prefix_ void senf::scheduler::detail::TimerDispatcher::reschedule()
00073 {
00074     if (timers_.empty())
00075         source_->notimeout();
00076     else
00077         source_->timeout(timers_.begin()->timeout_);
00078 }
00079 
00080 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00081 // senf::scheduler::detail::TimerDispatcher::TimerEvent
00082 
00083 prefix_ void senf::scheduler::TimerEvent::v_run()
00084 {
00085     disable();
00086     cb_();
00087 }
00088 
00089 prefix_ char const * senf::scheduler::TimerEvent::v_type()
00090     const
00091 {
00092     return "tm";
00093 }
00094 
00095 prefix_ std::string senf::scheduler::TimerEvent::v_info()
00096     const
00097 {
00098     std::stringstream ss;
00099     ss.imbue( std::locale(ss.getloc(),
00100                           new boost::posix_time::time_facet("%Y-%m-%d %H:%M:%S.%f-0000")) );
00101     ss << "expire " << ClockService::abstime(timeout_);
00102     return ss.str();
00103 }
00104 
00105 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00106 #undef prefix_
00107 //#include "TimerEvent.mpp"
00108 
00109 
00110 // Local Variables:
00111 // mode: c++
00112 // fill-column: 100
00113 // comment-column: 40
00114 // c-file-style: "senf"
00115 // indent-tabs-mode: nil
00116 // ispell-local-dictionary: "american"
00117 // compile-command: "scons -u test"
00118 // End:

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