/home/vlg/develop/libASSA/libassa/assa/Reactor.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                             Reactor.h
00004 //------------------------------------------------------------------------------
00005 //  Copyright (C) 1997-2002,2005  Vladislav Grinchenko 
00006 //
00007 //  This library is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU Library General Public
00009 //  License as published by the Free Software Foundation; either
00010 //  version 2 of the License, or (at your option) any later version.
00011 //------------------------------------------------------------------------------
00012 //  Created: 05/25/1999
00013 //------------------------------------------------------------------------------
00014 #ifndef REACTOR_H
00015 #define REACTOR_H
00016 
00017 #include <sys/time.h>           // select(2)
00018 #include <map>
00019 
00020 #if !defined(WIN32)
00021 #    include <sys/resource.h>       // getrlimit(2)
00022 #endif
00023 
00024 #include "assa/EventHandler.h"
00025 #include "assa/Singleton.h"
00026 #include "assa/MaskSet.h"
00027 #include "assa/TimerQueue.h"
00028 #include "assa/TimerCountdown.h"
00029 
00030 namespace ASSA {
00031 
00057 class Reactor 
00058 {
00059 public:
00061     Reactor ();
00062 
00064     ~Reactor();
00065 
00076     TimerId registerTimerHandler (EventHandler*      eh_, 
00077                                   const TimeVal&     tv_,
00078                                   const std::string& name_ = "<unknown>");
00079 
00088     bool registerIOHandler (EventHandler* eh_, 
00089                             handler_t     fd_, 
00090                             EventType     et_ = RWE_EVENTS);
00091 
00101     bool removeHandler (EventHandler* eh_, EventType et_ = ALL_EVENTS);
00102 
00107     bool removeTimerHandler (TimerId id_);
00108 
00114     bool removeIOHandler (handler_t fd_);
00115 
00117     void waitForEvents (void);
00118 
00127     void waitForEvents (TimeVal* tv_);
00128 
00137     void stopReactor (void);
00138 
00147     void deactivate (void);
00148 
00149 private:
00150     Reactor (const Reactor&);            
00151     Reactor& operator= (const Reactor&); 
00152 
00153 private:
00154     typedef std::map<u_int, EventHandler*> Fd2Eh_Map_Type;
00155     typedef Fd2Eh_Map_Type::iterator Fd2Eh_Map_Iter;
00156 
00157 private:
00159     void adjust_maxfdp1 (handler_t fd_,
00160                          handler_t rmax_, 
00161                          handler_t wmax_, 
00162                          handler_t emax_);
00163 
00165     bool handleError (void);
00166 
00171     bool dispatch (int minimum_);
00172 
00174     int isAnyReady (void);
00175 
00180     bool checkFDs (void);
00181 
00185     void dispatchHandler ( FdSet&          mask_, 
00186                            Fd2Eh_Map_Type& fdSet_,
00187                            EH_IO_Callback  callback_);
00188     
00195     void calculateTimeout (TimeVal*& howlong_, TimeVal* maxwait_);
00196 
00197 private:
00203     int m_fd_setsize;
00204 
00209     handler_t m_maxfd_plus1;
00210 
00212     bool m_active;
00213 
00215     Fd2Eh_Map_Type m_readSet;
00216 
00218     Fd2Eh_Map_Type m_writeSet;
00219 
00221     Fd2Eh_Map_Type m_exceptSet;
00222 
00224     MaskSet m_waitSet;
00225 
00227     MaskSet m_readySet;
00228 
00230     TimerQueue m_tqueue;
00231 };
00232 
00233 //-----------------------------------------------------------------------------
00234 // Inline functions
00235 //-----------------------------------------------------------------------------
00236 
00237 inline void Reactor::deactivate (void) {  m_active = false; }
00238 
00239 } // end namespace ASSA
00240 
00241 
00242 
00243 #endif /* REACTOR_H */  

Generated on Sun Aug 13 15:08:00 2006 for libassa by  doxygen 1.4.6