libassa  3.5.1
ServiceHandler.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 //------------------------------------------------------------------------------
3 // ServiceHandler.h
4 //------------------------------------------------------------------------------
5 // Copyright (c) 1999 by 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 //------------------------------------------------------------------------------
13 // Created: 06/07/99
14 //------------------------------------------------------------------------------
15 #ifndef SERVICE_HANDLER_H
16 #define SERVICE_HANDLER_H
17 
18 #include "assa/Assure.h"
19 #include "assa/EventHandler.h"
20 
21 namespace ASSA {
22 
30 template <class PEER_STREAM>
32 {
33 public:
39  : m_peerStream (new PEER_STREAM)
40  {
41  trace("ServiceHandler::ServiceHandler");
42  }
43 
49  ServiceHandler (PEER_STREAM* ps_)
50  : m_peerStream (ps_)
51  {
52  trace("ServiceHandler::ServiceHandler");
53  }
54 
56  virtual ~ServiceHandler () {
57  trace("ServiceHandler::~ServiceHandler");
58 
59  if ( m_peerStream ) {
60  delete m_peerStream;
61  m_peerStream = (PEER_STREAM*) NULL;
62  }
63  }
64 
71  virtual int open (void) = 0;
72 
81  virtual void close (void)
82  {
83  trace("ServiceHandler::close");
84  if ( m_peerStream ) m_peerStream->close ();
85  }
86 
93  operator PEER_STREAM& ()
94  {
95  // trace("ServiceHandler::opt PEER_STREAM& ()");
96  return *m_peerStream;
97  }
98 
100  PEER_STREAM& get_stream () { return *m_peerStream; }
101 
102 protected:
106  PEER_STREAM* m_peerStream;
107 };
108 
109 } // end namespace ASSA
110 
111 #endif /* SERVICE_HANDLER_H */
A collection of assert function wrappers.
An abstract interface for handling I/O events, timers, and such.
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition: Logger.h:429
EventHandler class.
Definition: EventHandler.h:103
PEER_STREAM & get_stream()
Return referenct to underlying PEER_STREAM.
PEER_STREAM * m_peerStream
Concrete Socket instance.
virtual void close(void)
Pure virtual method defined by subclass.
ServiceHandler(PEER_STREAM *ps_)
Constructor that takes PEER_STREAM as a parameter.
ServiceHandler()
Default constructor.
virtual ~ServiceHandler()
Destructor closes and deletes PEER_STREAM.
virtual int open(void)=0
Pure virtual method defined by subclass.
Definition: Acceptor.h:40