connectionbase.h

00001 /*
00002   Copyright (c) 2007-2008 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 
00122       virtual void getStatistics( int &totalIn, int &totalOut ) = 0;
00123 
00130       virtual ConnectionBase* newInstance() const = 0;
00131 
00132     protected:
00133       ConnectionDataHandler *m_handler;
00134       ConnectionState m_state;
00135       std::string m_server;
00136       int m_port;
00137 
00138   };
00139 
00140 }
00141 
00142 #endif // CONNECTIONBASE_H__

Generated on Sun Apr 27 11:08:13 2008 for gloox by  doxygen 1.5.5