libassa 3.5.1
Loading...
Searching...
No Matches
EventHandler.h
Go to the documentation of this file.
1// -*- c++ -*-
2//------------------------------------------------------------------------------
3// EventHandler.h
4//------------------------------------------------------------------------------
5// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
6//
7// This library is free software; you can redistribute it and/or
8// modify it under the terms of the GNU Library General Public
9// License as published by the Free Software Foundation; either
10// version 2 of the License, or (at your option) any later version.
11//---------------------------------------------------------------------------
12#ifndef _EventHandler_h
13#define _EventHandler_h
14
15#include "assa/Assure.h"
16
17namespace ASSA {
18
27typedef unsigned long TimerId;
28
35{
36 READ_EVENT = 0x01,
39 WRITE_EVENT = 0x02,
42 EXCEPT_EVENT = 0x04,
45 SIGNAL_EVENT = 0x20,
46 RWE_EVENTS = 0x07,
47 ALL_EVENTS = 0x37
48};
49
50inline
52{
53 return (e_ & READ_EVENT) == READ_EVENT;
54}
55
56inline
58{
59 return (e_ & WRITE_EVENT) == WRITE_EVENT;
60}
61
62inline
64{
65 return (e_ & EXCEPT_EVENT) == EXCEPT_EVENT;
66}
67
68inline
70{
71 return (e_ & TIMEOUT_EVENT) == TIMEOUT_EVENT;
72}
73
74inline
76{
77 return (e_ & SIGNAL_EVENT) == SIGNAL_EVENT;
78}
79
80inline
82{
83 return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_);
84}
85
86inline
92
103{
104public:
106 EventHandler();
107
109 virtual ~EventHandler () { /* no-op */ }
110
115 virtual int handle_read (int fd);
116
120 virtual int handle_write (int fd);
121
125 virtual int handle_except (int fd);
126
130 virtual int handle_timeout (TimerId tid);
131
135 virtual int handle_signal (int signum_);
136
143 virtual int handle_close (int fd);
144
148 virtual void resetState (void);
149
153 void set_id (const std::string& id_) { m_id = id_; }
154
157 std::string get_id () const { return m_id; }
158
159protected:
160 std::string m_id;
161};
162
163inline
165EventHandler() : m_id ("EventHandler")
166{
167 trace_with_mask("EventHandler::EventHandler",REACTTRACE);
168}
169
170inline int
172handle_read (int /* fd */)
173{
174 trace_with_mask("EventHandler::handle_read",REACTTRACE);
175 return -1;
176}
177
178inline int
180handle_write (int /* fd */)
181{
182 trace_with_mask("EventHandler::handle_write",REACTTRACE);
183 return -1;
184}
185
186inline int
188handle_except (int /* fd */)
189{
190 trace_with_mask("EventHandler::handle_except",REACTTRACE);
191 return -1;
192}
193
194inline int
196handle_timeout (TimerId /* timer_id */)
197{
198 trace_with_mask("EventHandler::handle_timeout",REACTTRACE);
199 return -1;
200}
201
202inline int
204handle_signal (int /* signum_ */)
205{
206 trace_with_mask("EventHandler::handle_signal",REACTTRACE);
207 return -1;
208}
209
210inline int
212handle_close (int /* fd */)
213{
214 trace_with_mask("EventHandler::handle_close",REACTTRACE);
215 return -1;
216}
217
218inline void
220resetState (void)
221{
222 trace_with_mask("EventHandler::reset",REACTTRACE);
223}
224
237
238} // end namespace ASSA
239
240#endif // _EventHandler_h
A collection of assert function wrappers.
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
A wrapper class to provide AutoPtr with reference semantics.
Definition AutoPtr.h:32
EventHandler class.
virtual int handle_close(int fd)
EOF on peer socket handler callback.
virtual int handle_signal(int signum_)
Signal handler callback.
virtual int handle_write(int fd)
Write handler callback.
virtual int handle_except(int fd)
Exception handler callback.
void set_id(const std::string &id_)
Set EventHandler ID.
virtual void resetState(void)
A hook for derived class to reset internal state as needed.
std::string get_id() const
Retrieve EventHandler ID.
virtual int handle_timeout(TimerId tid)
Timeout handler callback.
virtual ~EventHandler()
Virtual destructor.
EventHandler()
Constructor.
virtual int handle_read(int fd)
Read event callback.
EventType
EventType defines events types that Reactor understands.
@ WRITE_EVENT
Notify when there will be room for at least 1 byte to be written to IO channel without blocking.
@ ALL_EVENTS
Mask that includes all events.
@ SIGNAL_EVENT
Notify when UNIX signal is delivered by OS.
@ READ_EVENT
Notify when there will be at least 1 byte available for reading from IO channel without blocking .
@ RWE_EVENTS
READ_EVENT | WRITE_EVENT | EXCEPT_EVENT
@ EXCEPT_EVENT
Notify when there is an exception condition detected in TCP layer.
@ TIMEOUT_EVENT
Notify about expired timer.
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
bool isReadEvent(EventType e_)
bool isExceptEvent(EventType e_)
@ REACTTRACE
Extended Reactor/PrioriyQueue messages
Definition LogMask.h:40
bool isSignalEvent(EventType e_)
bool isTimeoutEvent(EventType e_)
int(EventHandler::* EH_IO_Callback)(int)
A type for the pointer to I/O-related callback member function of class EventHandler.
bool isRWEEvents(EventType e_)
bool isAllEvents(EventType e_)
bool isWriteEvent(EventType e_)