00001 /* 00002 Copyright (c) 2007-2009 by Jakob Schroeter <js@camaya.net> 00003 This file is part of the gloox library. http://camaya.net/gloox 00004 00005 This software is distributed under a license. The full license 00006 agreement can be found in the file LICENSE in this distribution. 00007 This software may not be copied, modified, sold or distributed 00008 other than expressed in the named license agreement. 00009 00010 This software is distributed without any warranty. 00011 */ 00012 00013 00014 00015 #ifndef CONNECTIONBASE_H__ 00016 #define CONNECTIONBASE_H__ 00017 00018 #include "gloox.h" 00019 #include "connectiondatahandler.h" 00020 00021 #include <string> 00022 00023 namespace gloox 00024 { 00025 00034 class GLOOX_API ConnectionBase 00035 { 00036 public: 00042 ConnectionBase( ConnectionDataHandler* cdh ) 00043 : m_handler( cdh ), m_state( StateDisconnected ), m_port( -1 ) 00044 {} 00045 00049 virtual ~ConnectionBase() { cleanup(); } 00050 00055 virtual ConnectionError connect() = 0; 00056 00062 virtual ConnectionError recv( int timeout = -1 ) = 0; 00063 00071 virtual bool send( const std::string& data ) = 0; 00072 00078 virtual ConnectionError receive() = 0; 00079 00083 virtual void disconnect() = 0; 00084 00089 virtual void cleanup() {} 00090 00095 ConnectionState state() const { return m_state; } 00096 00102 void registerConnectionDataHandler( ConnectionDataHandler* cdh ) { m_handler = cdh; } 00103 00109 void setServer( const std::string &server, int port = -1 ) { m_server = server; m_port = port; } 00110 00115 const std::string& server() const { return m_server; } 00116 00121 int port() const { return m_port; } 00122 00127 virtual int localPort() const { return -1; } 00128 00133 virtual const std::string localInterface() const { return EmptyString; } 00134 00140 virtual void getStatistics( long int &totalIn, long int &totalOut ) = 0; 00141 00148 virtual ConnectionBase* newInstance() const = 0; 00149 00150 protected: 00152 ConnectionDataHandler* m_handler; 00153 00155 ConnectionState m_state; 00156 00158 std::string m_server; 00159 00161 int m_port; 00162 00163 }; 00164 00165 } 00166 00167 #endif // CONNECTIONBASE_H__