PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/libtomahawk/network/BufferIoDevice.h

http://github.com/tomahawk-player/tomahawk
C Header | 78 lines | 40 code | 20 blank | 18 comment | 0 complexity | 9c213bc565a79390436d149143a6e2a0 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 4 *   Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
 5 *
 6 *   Tomahawk is free software: you can redistribute it and/or modify
 7 *   it under the terms of the GNU General Public License as published by
 8 *   the Free Software Foundation, either version 3 of the License, or
 9 *   (at your option) any later version.
10 *
11 *   Tomahawk is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef BUFFERIODEVICE_H
21#define BUFFERIODEVICE_H
22
23#include <QIODevice>
24
25class BufferIODevicePrivate;
26
27class BufferIODevice : public QIODevice
28{
29Q_OBJECT
30
31public:
32    explicit BufferIODevice( unsigned int size = 0, QObject* parent = 0 );
33    ~BufferIODevice();
34
35    virtual bool open( OpenMode mode );
36    virtual void close();
37
38    virtual bool seek( qint64 pos );
39    void seeked( int block );
40
41    virtual qint64 bytesAvailable() const;
42    virtual qint64 size() const;
43    virtual bool atEnd() const;
44    virtual qint64 pos() const;
45
46    void addData( int block, const QByteArray& ba );
47    void clear();
48
49    OpenMode openMode() const;
50
51    void inputComplete( const QString& errmsg = "" );
52
53    virtual bool isSequential() const;
54
55    static unsigned int blockSize();
56
57    int maxBlocks() const;
58    int nextEmptyBlock() const;
59    bool isBlockEmpty( int block ) const;
60
61signals:
62    void blockRequest( int block );
63
64protected:
65    virtual qint64 readData( char* data, qint64 maxSize );
66    virtual qint64 writeData( const char* data, qint64 maxSize );
67
68private:
69    int blockForPos( qint64 pos ) const;
70    int offsetForPos( qint64 pos ) const;
71    QByteArray getData( qint64 pos, qint64 size );
72
73    Q_DECLARE_PRIVATE( BufferIODevice )
74    BufferIODevicePrivate* d_ptr;
75
76};
77
78#endif // BUFFERIODEVICE_H