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

FdEvent.hh

Go to the documentation of this file.
00001 // $Id: FdEvent.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_FdEvent_
00027 #define HH_SENF_Scheduler_FdEvent_ 1
00028 
00029 // Custom includes
00030 #include <senf/boost_intrusive/iset_hook.hpp>
00031 #include <senf/Utils/Exception.hh>
00032 #include "FdManager.hh"
00033 #include "FIFORunner.hh"
00034 
00035 //#include "FdEvent.mpp"
00036 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00037 
00038 namespace senf {
00039 namespace scheduler {
00040 
00041     namespace detail {
00042         struct FdSetTag;
00043         typedef boost::intrusive::iset_base_hook<FdSetTag> FdSetBase;
00044         struct FdSetCompare;
00045         struct FindFd;
00046         class FdDispatcher;
00047         class FileDispatcher;
00048     }
00049 
00082     class FdEvent
00083         : public detail::FIFORunner::TaskInfo,
00084           public detail::FdSetBase,
00085           public detail::FdManager::Event
00086     {
00087     public:
00088         //-////////////////////////////////////////////////////////////////////////
00089         // Types
00090 
00091         typedef boost::function<void (int)> Callback;
00092 
00093         enum Events {
00094             EV_NONE = 0                             
00095           , EV_READ = detail::FdManager::EV_READ    
00096           , EV_PRIO = detail::FdManager::EV_PRIO    
00097           , EV_WRITE = detail::FdManager::EV_WRITE  
00098           , EV_HUP = detail::FdManager::EV_HUP      
00099           , EV_ERR = detail::FdManager::EV_ERR      
00100           , EV_ALL = (detail::FdManager::EV_READ
00101                       | detail::FdManager::EV_WRITE
00102                       | detail::FdManager::EV_PRIO) 
00103         };
00104 
00105         //-////////////////////////////////////////////////////////////////////////
00107         //\{
00108 
00109         template <class Handle>
00110         FdEvent(std::string const & name, Callback const & cb, Handle const & handle, int events,
00111                 bool initiallyEnabled = true);
00113 
00124         FdEvent(std::string const & name, Callback const & cb);
00126 
00134         ~FdEvent();
00135 
00136         //\}
00137         //-////////////////////////////////////////////////////////////////////////
00138 
00139         void disable();                 
00140         void enable();                  
00141 
00142         FdEvent & action(Callback const & cb); 
00143 
00144         FdEvent & events(int events);   
00145         FdEvent & addEvents(int events); 
00146         FdEvent & removeEvents(int events); 
00147         int events();                   
00148 
00149         template <class Handle>
00150         FdEvent & handle(Handle const & handle); 
00151 
00152         struct DuplicateEventRegistrationException : public Exception
00153         { DuplicateEventRegistrationException() : Exception("duplicate fd event registration") {} };
00154 
00155     protected:
00156 
00157     private:
00158         virtual void signal(int events);
00159         virtual void v_run();
00160         virtual char const * v_type() const;
00161         virtual std::string v_info() const;
00162 
00163         Callback cb_;
00164         int fd_;
00165         bool pollable_;
00166         int events_;
00167         int signaledEvents_;
00168 
00169         friend class detail::FdSetCompare;
00170         friend class detail::FindFd;
00171         friend class detail::FdDispatcher;
00172         friend class detail::FileDispatcher;
00173     };
00174 
00181     template <class Handle>
00182     int get_descriptor(Handle const & handle);
00183 }}
00184 
00185 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00186 #include "FdEvent.cci"
00187 #include "FdEvent.ct"
00188 #include "FdEvent.cti"
00189 #endif
00190 
00191 
00192 // Local Variables:
00193 // mode: c++
00194 // fill-column: 100
00195 // comment-column: 40
00196 // c-file-style: "senf"
00197 // indent-tabs-mode: nil
00198 // ispell-local-dictionary: "american"
00199 // compile-command: "scons -u test"
00200 // End:

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