/f8/builds/libassa-3.5.0-1.fc8/BUILD/libassa-3.5.0/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 
00162     bool handleError (void);
00163 
00168     bool dispatch (int minimum_);
00169 
00171     int isAnyReady (void);
00172 
00177     bool checkFDs (void);
00178 
00182     void dispatchHandler ( FdSet&          mask_, 
00183                            Fd2Eh_Map_Type& fdSet_,
00184                            EH_IO_Callback  callback_);
00185     
00192     void calculateTimeout (TimeVal*& howlong_, TimeVal* maxwait_);
00193 
00194 private:
00200     int m_fd_setsize;
00201 
00206     handler_t m_maxfd_plus1;
00207 
00209     bool m_active;
00210 
00212     Fd2Eh_Map_Type m_readSet;
00213 
00215     Fd2Eh_Map_Type m_writeSet;
00216 
00218     Fd2Eh_Map_Type m_exceptSet;
00219 
00221     MaskSet m_waitSet;
00222 
00224     MaskSet m_readySet;
00225 
00227     TimerQueue m_tqueue;
00228 };
00229 
00230 //-----------------------------------------------------------------------------
00231 // Inline functions
00232 //-----------------------------------------------------------------------------
00233 
00234 inline void Reactor::deactivate (void) {  m_active = false; }
00235 
00236 } // end namespace ASSA
00237 
00238 
00239 
00240 #endif /* REACTOR_H */  

Generated on Tue Mar 11 19:24:25 2008 for libassa by  doxygen 1.5.4