13 #include "connectioncompression.h"
15 #include <gloox/compressiondefault.h>
16 #include <gloox/compressionbase.h>
17 #include <gloox/gloox.h>
18 #include <gloox/logsink.h>
24 const gloox::LogSink& log )
25 : gloox::ConnectionBase( cdh ),
26 m_connection( conn ), m_compression( 0 ), m_log( log )
29 m_connection->registerConnectionDataHandler(
this );
33 : gloox::ConnectionBase( 0 ),
34 m_connection( conn ), m_compression( 0 ), m_log( log )
37 m_connection->registerConnectionDataHandler(
this );
49 m_connection->registerConnectionDataHandler( 0 );
51 m_connection = connection;
54 m_connection->registerConnectionDataHandler(
this );
57 gloox::ConnectionError ConnectionCompression::connect()
60 return gloox::ConnNotConnected;
62 if( m_state == gloox::StateConnected )
63 return gloox::ConnNoError;
66 m_compression =
new gloox::CompressionDefault(
this );
69 return gloox::ConnCompressionFailed;
71 if( !m_compression->init() )
72 return gloox::ConnCompressionFailed;
74 m_state = gloox::StateConnected;
76 if( m_connection->state() != gloox::StateConnected )
77 return m_connection->connect();
79 return gloox::ConnNoError;
82 gloox::ConnectionError ConnectionCompression::recv(
int timeout )
84 if( m_connection->state() == gloox::StateConnected )
85 return m_connection->recv( timeout );
87 return gloox::ConnNotConnected;
90 bool ConnectionCompression::send(
const std::string& data )
95 m_compression->compress( data );
99 gloox::ConnectionError ConnectionCompression::receive()
102 return m_connection->receive();
104 return gloox::ConnNotConnected;
107 void ConnectionCompression::disconnect()
110 m_connection->disconnect();
115 void ConnectionCompression::cleanup()
118 m_connection->cleanup();
120 m_compression->cleanup();
121 delete m_compression;
126 void ConnectionCompression::getStatistics(
long int& totalIn,
long int& totalOut )
129 m_connection->getStatistics( totalIn, totalOut );
132 gloox::ConnectionBase* ConnectionCompression::newInstance()
const
134 gloox::ConnectionBase* newConn = 0;
136 newConn = m_connection->newInstance();
140 void ConnectionCompression::handleReceivedData(
const gloox::ConnectionBase* ,
141 const std::string& data )
144 m_compression->decompress( data );
147 void ConnectionCompression::handleConnect(
const gloox::ConnectionBase* )
150 m_handler->handleConnect(
this );
153 void ConnectionCompression::handleDisconnect(
const gloox::ConnectionBase* , gloox::ConnectionError reason )
156 m_handler->handleDisconnect(
this, reason );
161 void ConnectionCompression::handleCompressedData(
const std::string& data )
164 m_connection->send( data );
167 void ConnectionCompression::handleDecompressedData(
const std::string& data )
170 m_handler->handleReceivedData(
this, data );