Loading...
Searching...
No Matches
EventHandler.h
Go to the documentation of this file.
// -*- 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 {
typedef unsigned long TimerId;
enum EventType
{
READ_EVENT = 0x01,
WRITE_EVENT = 0x02,
EXCEPT_EVENT = 0x04,
TIMEOUT_EVENT = 0x10,
SIGNAL_EVENT = 0x20,
RWE_EVENTS = 0x07,
ALL_EVENTS = 0x37
};
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_) ;
}
class EventHandler
{
public:
EventHandler();
virtual ~EventHandler () { /* no-op */ }
virtual int handle_read (int fd);
virtual int handle_write (int fd);
virtual int handle_except (int fd);
virtual int handle_timeout (TimerId tid);
virtual int handle_signal (int signum_);
virtual int handle_close (int fd);
virtual void resetState (void);
void set_id (const std::string& id_) { m_id = id_; }
std::string get_id () const { return m_id; }
protected:
std::string m_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);
}
typedef int (EventHandler::*EH_IO_Callback) (int);
} // end namespace ASSA
#endif // _EventHandler_h
Assure.h
A collection of assert function wrappers.
trace_with_mask
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition Logger.h:437
ASSA::EventHandler
EventHandler class.
Definition EventHandler.h:103
ASSA::EventHandler::handle_close
virtual int handle_close(int fd)
EOF on peer socket handler callback.
Definition EventHandler.h:212
ASSA::EventHandler::m_id
std::string m_id
Definition EventHandler.h:160
ASSA::EventHandler::handle_signal
virtual int handle_signal(int signum_)
Signal handler callback.
Definition EventHandler.h:204
ASSA::EventHandler::handle_write
virtual int handle_write(int fd)
Write handler callback.
Definition EventHandler.h:180
ASSA::EventHandler::handle_except
virtual int handle_except(int fd)
Exception handler callback.
Definition EventHandler.h:188
ASSA::EventHandler::set_id
void set_id(const std::string &id_)
Set EventHandler ID.
Definition EventHandler.h:153
ASSA::EventHandler::resetState
virtual void resetState(void)
A hook for derived class to reset internal state as needed.
Definition EventHandler.h:220
ASSA::EventHandler::get_id
std::string get_id() const
Retrieve EventHandler ID.
Definition EventHandler.h:157
ASSA::EventHandler::handle_timeout
virtual int handle_timeout(TimerId tid)
Timeout handler callback.
Definition EventHandler.h:196
ASSA::EventHandler::~EventHandler
virtual ~EventHandler()
Virtual destructor.
Definition EventHandler.h:109
ASSA::EventHandler::EventHandler
EventHandler()
Constructor.
Definition EventHandler.h:165
ASSA::EventHandler::handle_read
virtual int handle_read(int fd)
Read event callback.
Definition EventHandler.h:172
ASSA
Definition Acceptor.h:40
ASSA::EventType
EventType
EventType defines events types that Reactor understands.
Definition EventHandler.h:35
ASSA::WRITE_EVENT
@ WRITE_EVENT
Notify when there will be room for at least 1 byte to be written to IO channel without blocking.
Definition EventHandler.h:39
ASSA::ALL_EVENTS
@ ALL_EVENTS
Mask that includes all events.
Definition EventHandler.h:47
ASSA::SIGNAL_EVENT
@ SIGNAL_EVENT
Notify when UNIX signal is delivered by OS.
Definition EventHandler.h:45
ASSA::READ_EVENT
@ READ_EVENT
Notify when there will be at least 1 byte available for reading from IO channel without blocking .
Definition EventHandler.h:36
ASSA::RWE_EVENTS
@ RWE_EVENTS
READ_EVENT | WRITE_EVENT | EXCEPT_EVENT.
Definition EventHandler.h:46
ASSA::EXCEPT_EVENT
@ EXCEPT_EVENT
Notify when there is an exception condition detected in TCP layer.
Definition EventHandler.h:42
ASSA::TIMEOUT_EVENT
@ TIMEOUT_EVENT
Notify about expired timer.
Definition EventHandler.h:44
ASSA::EH_IO_Callback
int(EventHandler::* EH_IO_Callback)(int)
A type for the pointer to I/O-related callback member function of class EventHandler.
Definition EventHandler.h:236
ASSA::TimerId
unsigned long TimerId
Timer Id is used in handle_timeout() calls.
Definition EventHandler.h:27
ASSA::isReadEvent
bool isReadEvent(EventType e_)
Definition EventHandler.h:51
ASSA::isExceptEvent
bool isExceptEvent(EventType e_)
Definition EventHandler.h:63
ASSA::REACTTRACE
@ REACTTRACE
Extended Reactor/PrioriyQueue messages.
Definition LogMask.h:40
ASSA::isSignalEvent
bool isSignalEvent(EventType e_)
Definition EventHandler.h:75
ASSA::isTimeoutEvent
bool isTimeoutEvent(EventType e_)
Definition EventHandler.h:69
ASSA::isRWEEvents
bool isRWEEvents(EventType e_)
Definition EventHandler.h:81
ASSA::isAllEvents
bool isAllEvents(EventType e_)
Definition EventHandler.h:87
ASSA::isWriteEvent
bool isWriteEvent(EventType e_)
Definition EventHandler.h:57