gloox  0.9.9.12
connectionbase.h
1 /*
2  Copyright (c) 2007-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 
15 #ifndef CONNECTIONBASE_H__
16 #define CONNECTIONBASE_H__
17 
18 #include "gloox.h"
19 #include "connectiondatahandler.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
34  class GLOOX_API ConnectionBase
35  {
36  public:
43  : m_handler( cdh ), m_state( StateDisconnected ), m_port( -1 )
44  {}
45 
49  virtual ~ConnectionBase() { cleanup(); }
50 
55  virtual ConnectionError connect() = 0;
56 
62  virtual ConnectionError recv( int timeout = -1 ) = 0;
63 
71  virtual bool send( const std::string& data ) = 0;
72 
78  virtual ConnectionError receive() = 0;
79 
83  virtual void disconnect() = 0;
84 
89  virtual void cleanup() {}
90 
95  ConnectionState state() const { return m_state; }
96 
102  void registerConnectionDataHandler( ConnectionDataHandler *cdh ) { m_handler = cdh; }
103 
109  void setServer( const std::string &server, int port = -1 ) { m_server = server; m_port = port; }
110 
115  const std::string& server() const { return m_server; }
116 
122  virtual void getStatistics( int &totalIn, int &totalOut ) = 0;
123 
130  virtual ConnectionBase* newInstance() const = 0;
131 
132  protected:
133  ConnectionDataHandler *m_handler;
134  ConnectionState m_state;
135  std::string m_server;
136  int m_port;
137 
138  };
139 
140 }
141 
142 #endif // CONNECTIONBASE_H__