gloox  1.0.1
connectionbase.h
1 /*
2  Copyright (c) 2007-2012 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 
121  int port() const { return m_port; }
122 
127  virtual int localPort() const { return -1; }
128 
133  virtual const std::string localInterface() const { return EmptyString; }
134 
140  virtual void getStatistics( long int &totalIn, long int &totalOut ) = 0;
141 
148  virtual ConnectionBase* newInstance() const = 0;
149 
150  protected:
153 
156 
158  std::string m_server;
159 
161  int m_port;
162 
163  };
164 
165 }
166 
167 #endif // CONNECTIONBASE_H__