/usr/include/assa-3.5/assa/EventHandler.h is in libassa-3.5-5-dev 3.5.1-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | // -*- c++ -*-
//------------------------------------------------------------------------------
// EventHandler.h
//------------------------------------------------------------------------------
// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//---------------------------------------------------------------------------
#ifndef _EventHandler_h
#define _EventHandler_h
#include "assa/Assure.h"
namespace ASSA {
/** @file EventHandler.h
An abstract interface for handling I/O events, timers, and such.
*/
/** @var unsigned long TimerId.
Timer Id is used in handle_timeout() calls.
*/
typedef unsigned long TimerId;
/** @enum EventType
EventType defines events types that Reactor understands.
*/
enum EventType
{
READ_EVENT = 0x01, /**< Notify when there will be at least 1 byte
available for reading from IO channel without
blocking . */
WRITE_EVENT = 0x02, /**< Notify when there will be room for at least
1 byte to be written to IO channel without
blocking. */
EXCEPT_EVENT = 0x04, /**< Notify when there is an exception condition
detected in TCP layer. */
TIMEOUT_EVENT = 0x10, /**< Notify about expired timer. */
SIGNAL_EVENT = 0x20, /**< Notify when UNIX signal is delivered by OS */
RWE_EVENTS = 0x07, /**< READ_EVENT | WRITE_EVENT | EXCEPT_EVENT */
ALL_EVENTS = 0x37 /**< Mask that includes all events. */
};
inline
bool isReadEvent (EventType e_)
{
return (e_ & READ_EVENT) == READ_EVENT;
}
inline
bool isWriteEvent (EventType e_)
{
return (e_ & WRITE_EVENT) == WRITE_EVENT;
}
inline
bool isExceptEvent (EventType e_)
{
return (e_ & EXCEPT_EVENT) == EXCEPT_EVENT;
}
inline
bool isTimeoutEvent (EventType e_)
{
return (e_ & TIMEOUT_EVENT) == TIMEOUT_EVENT;
}
inline
bool isSignalEvent (EventType e_)
{
return (e_ & SIGNAL_EVENT) == SIGNAL_EVENT;
}
inline
bool isRWEEvents (EventType e_)
{
return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_);
}
inline
bool isAllEvents (EventType e_)
{
return isReadEvent (e_) && isWriteEvent (e_) && isExceptEvent (e_) &&
isSignalEvent (e_) && isTimeoutEvent (e_) ;
}
/** EventHandler class.
EventHandler is a pure virtual class. It is an interface class to the
Event Handlers. These events are processed by Reactor. The supported events
are signals, timers, and I/O pipes such as file descriptors, sockets and such.
@see EventType
*/
class EventHandler
{
public:
/// Constructor
EventHandler();
/// Virtual destructor
virtual ~EventHandler () { /* no-op */ }
/** Read event callback. If reader detects EOF, it must
return error to the Reactor. (See Reactor for details).
@return 0 on success, -1 on error
*/
virtual int handle_read (int fd);
/** Write handler callback.
@return 0 on success, -1 on error
*/
virtual int handle_write (int fd);
/** Exception handler callback.
@return 0 on success, -1 on error
*/
virtual int handle_except (int fd);
/** Timeout handler callback.
@return 1 to reschedule the timer, 0 otherwise
*/
virtual int handle_timeout (TimerId tid);
/** Signal handler callback.
@return 0 on success, -1 on error
*/
virtual int handle_signal (int signum_);
/** EOF on peer socket handler callback. There is no
corresponding EventType. One is not needed because detecting
EOF is a part of handle_read () data processing.
@return 0 on success, -1 on error
*/
virtual int handle_close (int fd);
/** A hook for derived class to reset internal state
as needed.
*/
virtual void resetState (void);
/** Set EventHandler ID. ID allows Reactor and application-level
code describe intelligently the kind of the EventHandler.
*/
void set_id (const std::string& id_) { m_id = id_; }
/** Retrieve EventHandler ID.
*/
std::string get_id () const { return m_id; }
protected:
std::string m_id; /// EventHandler ID.
};
inline
EventHandler::
EventHandler() : m_id ("EventHandler")
{
trace_with_mask("EventHandler::EventHandler",REACTTRACE);
}
inline int
EventHandler::
handle_read (int /* fd */)
{
trace_with_mask("EventHandler::handle_read",REACTTRACE);
return -1;
}
inline int
EventHandler::
handle_write (int /* fd */)
{
trace_with_mask("EventHandler::handle_write",REACTTRACE);
return -1;
}
inline int
EventHandler::
handle_except (int /* fd */)
{
trace_with_mask("EventHandler::handle_except",REACTTRACE);
return -1;
}
inline int
EventHandler::
handle_timeout (TimerId /* timer_id */)
{
trace_with_mask("EventHandler::handle_timeout",REACTTRACE);
return -1;
}
inline int
EventHandler::
handle_signal (int /* signum_ */)
{
trace_with_mask("EventHandler::handle_signal",REACTTRACE);
return -1;
}
inline int
EventHandler::
handle_close (int /* fd */)
{
trace_with_mask("EventHandler::handle_close",REACTTRACE);
return -1;
}
inline void
EventHandler::
resetState (void)
{
trace_with_mask("EventHandler::reset",REACTTRACE);
}
/** @var int (EventHandler::*EH_IO_Callback) (int)
A type for the pointer to I/O-related callback member function
of class EventHandler.
These are:
- handle_read ()
- handle_write ()
- handle_except ()
@see EventHandler
*/
typedef int (EventHandler::*EH_IO_Callback) (int);
} // end namespace ASSA
#endif // _EventHandler_h
|