~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to iris/src/xmpp/xmpp-core/compressionhandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QTimer>
 
2
#include <QDebug>
 
3
 
 
4
#include "compressionhandler.h"
 
5
#include "xmpp/zlib/zlibcompressor.h"
 
6
#include "xmpp/zlib/zlibdecompressor.h"
 
7
 
 
8
CompressionHandler::CompressionHandler()
 
9
        : errorCode_(0)
 
10
{
 
11
        outgoing_buffer_.open(QIODevice::ReadWrite);
 
12
        compressor_ = new ZLibCompressor(&outgoing_buffer_);
 
13
        
 
14
        incoming_buffer_.open(QIODevice::ReadWrite);
 
15
        decompressor_ = new ZLibDecompressor(&incoming_buffer_);
 
16
}
 
17
 
 
18
CompressionHandler::~CompressionHandler()
 
19
{
 
20
        delete compressor_;
 
21
        delete decompressor_;
 
22
}
 
23
 
 
24
void CompressionHandler::writeIncoming(const QByteArray& a)
 
25
{
 
26
        //qDebug("CompressionHandler::writeIncoming");
 
27
        //qDebug() << QString("Incoming %1 bytes").arg(a.size());
 
28
        errorCode_ = decompressor_->write(a);
 
29
        if (!errorCode_) 
 
30
                QTimer::singleShot(0, this, SIGNAL(readyRead()));
 
31
        else
 
32
                QTimer::singleShot(0, this, SIGNAL(error()));
 
33
}
 
34
 
 
35
void CompressionHandler::write(const QByteArray& a)
 
36
{
 
37
        //qDebug() << QString("CompressionHandler::write(%1)").arg(a.size());
 
38
        errorCode_ = compressor_->write(a);
 
39
        if (!errorCode_)
 
40
                QTimer::singleShot(0, this, SIGNAL(readyReadOutgoing()));
 
41
        else
 
42
                QTimer::singleShot(0, this, SIGNAL(error()));
 
43
}
 
44
 
 
45
QByteArray CompressionHandler::read()
 
46
{
 
47
        //qDebug("CompressionHandler::read");
 
48
        QByteArray b = incoming_buffer_.buffer();
 
49
        incoming_buffer_.buffer().clear();
 
50
        incoming_buffer_.reset();
 
51
        return b;
 
52
}
 
53
 
 
54
QByteArray CompressionHandler::readOutgoing(int* i) 
 
55
{
 
56
        //qDebug("CompressionHandler::readOutgoing");
 
57
        //qDebug() << QString("Outgoing %1 bytes").arg(outgoing_buffer_.size());
 
58
        QByteArray b = outgoing_buffer_.buffer();
 
59
        outgoing_buffer_.buffer().clear();
 
60
        outgoing_buffer_.reset();
 
61
        *i = b.size();
 
62
        return b;
 
63
}
 
64
 
 
65
int CompressionHandler::errorCode()
 
66
{
 
67
        return errorCode_;
 
68
}