libassa 3.5.1
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
ASSA::ServiceHandler< PEER_STREAM > Class Template Referenceabstract

#include <ServiceHandler.h>

Inheritance diagram for ASSA::ServiceHandler< PEER_STREAM >:
ASSA::EventHandler

Public Member Functions

 ServiceHandler ()
 Default constructor.
 
 ServiceHandler (PEER_STREAM *ps_)
 Constructor that takes PEER_STREAM as a parameter.
 
virtual ~ServiceHandler ()
 Destructor closes and deletes PEER_STREAM.
 
virtual int open (void)=0
 Pure virtual method defined by subclass.
 
virtual void close (void)
 Pure virtual method defined by subclass.
 
 operator PEER_STREAM & ()
 Conversion operator to type PEER_STREAM &.
 
PEER_STREAMget_stream ()
 Return referenct to underlying PEER_STREAM.
 
- Public Member Functions inherited from ASSA::EventHandler
 EventHandler ()
 Constructor.
 
virtual ~EventHandler ()
 Virtual destructor.
 
virtual int handle_read (int fd)
 Read event callback.
 
virtual int handle_write (int fd)
 Write handler callback.
 
virtual int handle_except (int fd)
 Exception handler callback.
 
virtual int handle_timeout (TimerId tid)
 Timeout handler callback.
 
virtual int handle_signal (int signum_)
 Signal handler callback.
 
virtual int handle_close (int fd)
 EOF on peer socket handler callback.
 
virtual void resetState (void)
 A hook for derived class to reset internal state as needed.
 
void set_id (const std::string &id_)
 Set EventHandler ID.
 
std::string get_id () const
 Retrieve EventHandler ID.
 

Protected Attributes

PEER_STREAMm_peerStream
 Concrete Socket instance.
 
- Protected Attributes inherited from ASSA::EventHandler
std::string m_id
 

Detailed Description

template<class PEER_STREAM>
class ASSA::ServiceHandler< PEER_STREAM >

Definition at line 31 of file ServiceHandler.h.

Constructor & Destructor Documentation

◆ ServiceHandler() [1/2]

template<class PEER_STREAM >
ASSA::ServiceHandler< PEER_STREAM >::ServiceHandler ( )
inline

Default constructor.

In case of server-side, ServiceHandler is created by Acceptor, when new connection is detected.

Definition at line 38 of file ServiceHandler.h.

39 : m_peerStream (new PEER_STREAM)
40 {
41 trace("ServiceHandler::ServiceHandler");
42 }
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429
PEER_STREAM * m_peerStream
Concrete Socket instance.

References trace.

◆ ServiceHandler() [2/2]

template<class PEER_STREAM >
ASSA::ServiceHandler< PEER_STREAM >::ServiceHandler ( PEER_STREAM ps_)
inline

Constructor that takes PEER_STREAM as a parameter.

In case of server-side, ServiceHandler is created by Acceptor, when new connection is detected. Note that PEER_STREAM is created by PEER_STREAM::accept () method.

Definition at line 49 of file ServiceHandler.h.

50 : m_peerStream (ps_)
51 {
52 trace("ServiceHandler::ServiceHandler");
53 }

References trace.

◆ ~ServiceHandler()

Destructor closes and deletes PEER_STREAM.

Definition at line 56 of file ServiceHandler.h.

56 {
57 trace("ServiceHandler::~ServiceHandler");
58
59 if ( m_peerStream ) {
60 delete m_peerStream;
61 m_peerStream = (PEER_STREAM*) NULL;
62 }
63 }

References ASSA::ServiceHandler< PEER_STREAM >::m_peerStream, and trace.

Member Function Documentation

◆ close()

template<class PEER_STREAM >
virtual void ASSA::ServiceHandler< PEER_STREAM >::close ( void  )
inlinevirtual

Pure virtual method defined by subclass.

The close() hook closes PEER_STREAM by default The behavior of this method can be changed by a subclass, which typically performs any service-specific cleanup. EventHandler::handle_close() method of base class EventHandler is called when client closes connection. ServiceHandler object can destroy itself from there.

Definition at line 81 of file ServiceHandler.h.

82 {
83 trace("ServiceHandler::close");
84 if ( m_peerStream ) m_peerStream->close ();
85 }

References ASSA::ServiceHandler< PEER_STREAM >::m_peerStream, and trace.

◆ get_stream()

template<class PEER_STREAM >
PEER_STREAM & ASSA::ServiceHandler< PEER_STREAM >::get_stream ( )
inline

Return referenct to underlying PEER_STREAM.

Definition at line 100 of file ServiceHandler.h.

100{ return *m_peerStream; }

References ASSA::ServiceHandler< PEER_STREAM >::m_peerStream.

◆ open()

template<class PEER_STREAM >
virtual int ASSA::ServiceHandler< PEER_STREAM >::open ( void  )
pure virtual

Pure virtual method defined by subclass.

The open() hook is called by the Acceptor or Connector once a connection is established. The behavior of this method must be defined by a subclass, which typically performs any service-specific initialization.

Implemented in ASSA::RemoteLogger.

◆ operator PEER_STREAM &()

template<class PEER_STREAM >
ASSA::ServiceHandler< PEER_STREAM >::operator PEER_STREAM & ( )
inline

Conversion operator to type PEER_STREAM &.

Comes handy when you want to call underlying PEER_STREAM member functions directly.

Returns
reference to underlying stream mechanism

Definition at line 93 of file ServiceHandler.h.

94 {
95 // trace("ServiceHandler::opt PEER_STREAM& ()");
96 return *m_peerStream;
97 }

Member Data Documentation

◆ m_peerStream

template<class PEER_STREAM >
PEER_STREAM* ASSA::ServiceHandler< PEER_STREAM >::m_peerStream
protected

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