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 <sys/resource.h>       // getrlimit(2)
00019 
00020 #include "assa/EventHandler.h"
00021 #include "assa/Singleton.h"
00022 #include "assa/MaskSet.h"
00023 #include "assa/TimerQueue.h"
00024 #include "assa/TimerCountdown.h"
00025 
00026 namespace ASSA {
00027 
00053 class Reactor 
00054 {
00055 public:
00057     Reactor ();
00058 
00060     ~Reactor();
00061 
00072     TimerId registerTimerHandler (EventHandler*      eh_, 
00073                                   const TimeVal&     tv_,
00074                                   const std::string& name_ = "<unknown>");
00075 
00084     bool registerIOHandler (EventHandler* eh_, 
00085                             int fd_, 
00086                             EventType et_ = RWE_EVENTS);
00087 
00097     bool removeHandler (EventHandler* eh_, EventType et_ = ALL_EVENTS);
00098 
00103     bool removeTimerHandler (TimerId id_);
00104 
00110     bool removeIOHandler (int fd_);
00111 
00113     void waitForEvents (void);
00114 
00123     void waitForEvents (TimeVal* tv_);
00124 
00133     void stopReactor (void);
00134 
00143     void deactivate (void);
00144 
00145 private:
00146     Reactor (const Reactor&);            
00147     Reactor& operator= (const Reactor&); 
00148 
00149 private:
00151     bool handleError (void);
00152 
00157     bool dispatch (int minimum_);
00158 
00160     int isAnyReady (void);
00161 
00166     bool checkFDs (void);
00167 
00171     void dispatchHandler ( FdSet& mask_, EventHandler** fdSet_,
00172                    EH_IO_Callback callback_);
00173     
00180     void calculateTimeout (TimeVal*& howlong_, TimeVal* maxwait_);
00181 
00182     
00183 private:
00189     int m_noFiles;
00190 
00192     int m_maxfd;
00193 
00195     bool m_active;
00196 
00198     EventHandler** m_readSet;
00199 
00201     EventHandler** m_writeSet;
00202 
00204     EventHandler** m_exceptSet;
00205 
00207     MaskSet m_waitSet;
00208 
00210     MaskSet m_readySet;
00211 
00213     TimerQueue m_tqueue;
00214 };
00215 /*******************************************************************************
00216  Inline functions
00217 *******************************************************************************/
00218 
00219 inline void Reactor::deactivate (void) {  m_active = false; }
00220 
00221 } // end namespace ASSA
00222 
00223 
00224 #endif /* REACTOR_H */  

Generated on Mon Dec 19 16:37:14 2005 for libassa by  doxygen 1.4.5