libassa  3.5.1
Public Member Functions | Protected Attributes | List of all members
ASSA::EventHandler Class Reference

EventHandler class. More...

#include <EventHandler.h>

Inheritance diagram for ASSA::EventHandler:
ASSA::ServiceHandler< ASSA::IPv4Socket > ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR > ASSA::CFUNC_Handler ASSA::ChildStatusHandler ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR > ASSA::GenServer ASSA::SIGALRMHandler ASSA::SIGCHLDHandler ASSA::SIGINTHandler ASSA::SIGPOLLHandler ASSA::SIGUSR1Handler ASSA::SIGUSR2Handler ASSA::ServiceHandler< PEER_STREAM >

Public Member Functions

 EventHandler ()
 Constructor. More...
 
virtual ~EventHandler ()
 Virtual destructor. More...
 
virtual int handle_read (int fd)
 Read event callback. More...
 
virtual int handle_write (int fd)
 Write handler callback. More...
 
virtual int handle_except (int fd)
 Exception handler callback. More...
 
virtual int handle_timeout (TimerId tid)
 Timeout handler callback. More...
 
virtual int handle_signal (int signum_)
 Signal handler callback. More...
 
virtual int handle_close (int fd)
 EOF on peer socket handler callback. More...
 
virtual void resetState (void)
 A hook for derived class to reset internal state as needed. More...
 
void set_id (const std::string &id_)
 Set EventHandler ID. More...
 
std::string get_id () const
 Retrieve EventHandler ID. More...
 

Protected Attributes

std::string m_id
 

Detailed Description

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 also
EventType

Definition at line 102 of file EventHandler.h.

Constructor & Destructor Documentation

◆ EventHandler()

ASSA::EventHandler::EventHandler ( )
inline

Constructor.

Definition at line 164 of file EventHandler.h.

165  : m_id ("EventHandler")
166 {
167  trace_with_mask("EventHandler::EventHandler",REACTTRACE);
168 }
#define trace_with_mask(s, m)
trace_with_mask() is used to trace function call chain in C++ program.
Definition: Logger.h:437
std::string m_id
Definition: EventHandler.h:160
@ REACTTRACE
Extended Reactor/PrioriyQueue messages
Definition: LogMask.h:40

References ASSA::REACTTRACE, and trace_with_mask.

◆ ~EventHandler()

virtual ASSA::EventHandler::~EventHandler ( )
inlinevirtual

Virtual destructor.

Definition at line 109 of file EventHandler.h.

109 { /* no-op */ }

Member Function Documentation

◆ get_id()

std::string ASSA::EventHandler::get_id ( ) const
inline

◆ handle_close()

int ASSA::EventHandler::handle_close ( int  fd)
inlinevirtual

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.

Returns
0 on success, -1 on error

Reimplemented in ASSA::RemoteLogger, and ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >.

Definition at line 211 of file EventHandler.h.

213 {
214  trace_with_mask("EventHandler::handle_close",REACTTRACE);
215  return -1;
216 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::Reactor::removeHandler(), and ASSA::Reactor::removeIOHandler().

◆ handle_except()

int ASSA::EventHandler::handle_except ( int  fd)
inlinevirtual

Exception handler callback.

Returns
0 on success, -1 on error

Definition at line 187 of file EventHandler.h.

189 {
190  trace_with_mask("EventHandler::handle_except",REACTTRACE);
191  return -1;
192 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::Reactor::dispatch().

◆ handle_read()

int ASSA::EventHandler::handle_read ( int  fd)
inlinevirtual

Read event callback.

If reader detects EOF, it must return error to the Reactor. (See Reactor for details).

Returns
0 on success, -1 on error

Reimplemented in ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >.

Definition at line 171 of file EventHandler.h.

173 {
174  trace_with_mask("EventHandler::handle_read",REACTTRACE);
175  return -1;
176 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::Reactor::dispatch().

◆ handle_signal()

int ASSA::EventHandler::handle_signal ( int  signum_)
inlinevirtual

Signal handler callback.

Returns
0 on success, -1 on error

Reimplemented in ASSA::CFUNC_Handler, ASSA::SIGPOLLHandler, ASSA::SIGALRMHandler, ASSA::SIGCHLDHandler, ASSA::SIGUSR2Handler, ASSA::SIGUSR1Handler, ASSA::SIGINTHandler, ASSA::GenServer, and ASSA::ChildStatusHandler.

Definition at line 203 of file EventHandler.h.

205 {
206  trace_with_mask("EventHandler::handle_signal",REACTTRACE);
207  return -1;
208 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::SigHandler::dispatch(), and ASSA::SigHandlers::dispatch().

◆ handle_timeout()

int ASSA::EventHandler::handle_timeout ( TimerId  tid)
inlinevirtual

Timeout handler callback.

Returns
1 to reschedule the timer, 0 otherwise

Reimplemented in ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >.

Definition at line 195 of file EventHandler.h.

197 {
198  trace_with_mask("EventHandler::handle_timeout",REACTTRACE);
199  return -1;
200 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::TimerQueue::expire().

◆ handle_write()

int ASSA::EventHandler::handle_write ( int  fd)
inlinevirtual

Write handler callback.

Returns
0 on success, -1 on error

Reimplemented in ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >.

Definition at line 179 of file EventHandler.h.

181 {
182  trace_with_mask("EventHandler::handle_write",REACTTRACE);
183  return -1;
184 }

References ASSA::REACTTRACE, and trace_with_mask.

Referenced by ASSA::Reactor::dispatch().

◆ resetState()

void ASSA::EventHandler::resetState ( void  )
inlinevirtual

A hook for derived class to reset internal state as needed.

Reimplemented in ASSA::SIGALRMHandler, ASSA::SIGCHLDHandler, ASSA::SIGUSR2Handler, ASSA::SIGUSR1Handler, and ASSA::SIGINTHandler.

Definition at line 219 of file EventHandler.h.

221 {
222  trace_with_mask("EventHandler::reset",REACTTRACE);
223 }

References ASSA::REACTTRACE, and trace_with_mask.

◆ set_id()

void ASSA::EventHandler::set_id ( const std::string &  id_)
inline

Set EventHandler ID.

ID allows Reactor and application-level code describe intelligently the kind of the EventHandler.

Definition at line 153 of file EventHandler.h.

153 { m_id = id_; }

References m_id.

Referenced by ASSA::Connector< SERVICE_HANDLER, PEER_CONNECTOR >::Connector().

Member Data Documentation

◆ m_id

std::string ASSA::EventHandler::m_id
protected

Definition at line 160 of file EventHandler.h.

Referenced by get_id(), and set_id().


The documentation for this class was generated from the following file: