gloox
1.0
|
00001 /* 00002 Copyright (c) 2006-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 #ifndef BYTESTREAM_H__ 00015 #define BYTESTREAM_H__ 00016 00017 #include "jid.h" 00018 #include "logsink.h" 00019 00020 #include <string> 00021 00022 namespace gloox 00023 { 00024 00025 class BytestreamDataHandler; 00026 00036 class GLOOX_API Bytestream 00037 { 00038 public: 00042 enum StreamType 00043 { 00044 S5B, 00045 IBB 00046 }; 00047 00056 Bytestream( StreamType type, LogSink& logInstance, const JID& initiator, const JID& target, 00057 const std::string& sid ) 00058 : m_handler( 0 ), m_logInstance( logInstance ), m_initiator( initiator ), m_target( target ), 00059 m_type( type ), m_sid( sid ), m_open( false ) 00060 {} 00061 00065 virtual ~Bytestream() {} 00066 00072 bool isOpen() const { return m_open; } 00073 00083 virtual bool connect() = 0; 00084 00088 virtual void close() = 0; 00089 00099 virtual bool send( const std::string& data ) = 0; 00100 00108 virtual ConnectionError recv( int timeout = -1 ) = 0; 00109 00114 const std::string& sid() const { return m_sid; } 00115 00120 StreamType type() const { return m_type; } 00121 00127 const JID& target() const { return m_target; } 00128 00134 const JID& initiator() const { return m_initiator; } 00135 00142 void registerBytestreamDataHandler( BytestreamDataHandler* bdh ) 00143 { m_handler = bdh; } 00144 00148 void removeBytestreamDataHandler() 00149 { m_handler = 0; } 00150 00151 protected: 00153 BytestreamDataHandler* m_handler; 00154 00156 const LogSink& m_logInstance; 00157 00159 const JID m_initiator; 00160 00162 const JID m_target; 00163 00165 StreamType m_type; 00166 00168 std::string m_sid; 00169 00171 bool m_open; 00172 00173 private: 00174 Bytestream& operator=( const Bytestream& ); 00175 00176 }; 00177 00178 } 00179 00180 #endif // BYTESTREAM_H__