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

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                            EventHandler.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 #ifndef _EventHandler_h
00013 #define _EventHandler_h
00014 
00015 #include "assa/Assure.h"
00016 
00017 namespace ASSA {
00018 
00027 typedef unsigned long TimerId;
00028 
00034 enum EventType
00035 {   
00036     READ_EVENT    = 0x01,   
00039     WRITE_EVENT   = 0x02,   
00042     EXCEPT_EVENT  = 0x04,   
00044     TIMEOUT_EVENT = 0x10,   
00045     SIGNAL_EVENT  = 0x20,   
00046     RWE_EVENTS    = 0x07,   
00047     ALL_EVENTS    = 0x37    
00048 };
00049 
00050 inline 
00051 bool isReadEvent (EventType e_) 
00052 {     
00053     return (e_ & READ_EVENT) == READ_EVENT;
00054 }
00055 
00056 inline 
00057 bool isWriteEvent (EventType e_) 
00058 {
00059     return (e_ & WRITE_EVENT) == WRITE_EVENT;
00060 }
00061 
00062 inline 
00063 bool isExceptEvent (EventType e_) 
00064 {
00065     return (e_ & EXCEPT_EVENT) == EXCEPT_EVENT;
00066 }
00067 
00068 inline
00069 bool isTimeoutEvent (EventType e_) 
00070 {
00071     return (e_ & TIMEOUT_EVENT) == TIMEOUT_EVENT;
00072 }
00073 
00074 inline
00075 bool isSignalEvent (EventType e_) 
00076 {
00077     return (e_ & SIGNAL_EVENT) == SIGNAL_EVENT;
00078 }
00079 
00080 inline 
00081 bool isRWEEvents (EventType e_) 
00082 {
00083     return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_);
00084 }
00085 
00086 inline 
00087 bool isAllEvents (EventType e_) 
00088 {
00089     return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_) &&
00090         isSignalEvent (e_) && isTimeoutEvent (e_) ;
00091 }
00092 
00102 class EventHandler
00103 {
00104 public:
00106     EventHandler();
00107 
00109     virtual ~EventHandler () { /* no-op */ }
00110 
00115     virtual int handle_read (int fd);
00116 
00120     virtual int handle_write (int fd);
00121 
00125     virtual int handle_except (int fd);
00126 
00130     virtual int handle_timeout (TimerId tid);
00131 
00135     virtual int handle_signal (int signum_); 
00136 
00143     virtual int handle_close (int fd);
00144 
00148     virtual void resetState (void);
00149 
00153     void set_id (const std::string& id_) { m_id = id_; }
00154 
00157     std::string get_id () const { return m_id; }
00158 
00159 protected:
00160     std::string m_id;           
00161 };
00162 
00163 inline
00164 EventHandler::
00165 EventHandler() : m_id ("EventHandler")
00166 {
00167     trace_with_mask("EventHandler::EventHandler",REACTTRACE);
00168 }
00169 
00170 inline int 
00171 EventHandler::
00172 handle_read (int /* fd */)
00173 {
00174     trace_with_mask("EventHandler::handle_read",REACTTRACE);
00175     return -1;
00176 }
00177 
00178 inline int 
00179 EventHandler::
00180 handle_write (int /* fd */)
00181 {
00182     trace_with_mask("EventHandler::handle_write",REACTTRACE);
00183     return -1;
00184 }
00185 
00186 inline int 
00187 EventHandler::
00188 handle_except (int /* fd */)
00189 {
00190     trace_with_mask("EventHandler::handle_except",REACTTRACE);
00191     return -1;
00192 }
00193 
00194 inline int 
00195 EventHandler::
00196 handle_timeout (TimerId /* timer_id */)
00197 {
00198     trace_with_mask("EventHandler::handle_timeout",REACTTRACE);
00199     return -1;
00200 }
00201 
00202 inline int 
00203 EventHandler::
00204 handle_signal (int /* signum_ */) 
00205 {
00206     trace_with_mask("EventHandler::handle_signal",REACTTRACE);
00207     return -1;
00208 }
00209 
00210 inline int 
00211 EventHandler::
00212 handle_close (int /* fd */)
00213 {
00214     trace_with_mask("EventHandler::handle_close",REACTTRACE);
00215     return -1;
00216 }
00217 
00218 inline void 
00219 EventHandler::
00220 resetState (void) 
00221 {
00222     trace_with_mask("EventHandler::reset",REACTTRACE);
00223 }
00224 
00236 typedef int (EventHandler::*EH_IO_Callback) (int);
00237 
00238 } // end namespace ASSA
00239 
00240 #endif // _EventHandler_h

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