/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. #ifndef BUFFERIODEVICE_H
  20. #define BUFFERIODEVICE_H
  21. #include <QIODevice>
  22. class BufferIODevicePrivate;
  23. class BufferIODevice : public QIODevice
  24. {
  25. Q_OBJECT
  26. public:
  27. explicit BufferIODevice( unsigned int size = 0, QObject* parent = 0 );
  28. ~BufferIODevice();
  29. virtual bool open( OpenMode mode );
  30. virtual void close();
  31. virtual bool seek( qint64 pos );
  32. void seeked( int block );
  33. virtual qint64 bytesAvailable() const;
  34. virtual qint64 size() const;
  35. virtual bool atEnd() const;
  36. virtual qint64 pos() const;
  37. void addData( int block, const QByteArray& ba );
  38. void clear();
  39. OpenMode openMode() const;
  40. void inputComplete( const QString& errmsg = "" );
  41. virtual bool isSequential() const;
  42. static unsigned int blockSize();
  43. int maxBlocks() const;
  44. int nextEmptyBlock() const;
  45. bool isBlockEmpty( int block ) const;
  46. signals:
  47. void blockRequest( int block );
  48. protected:
  49. virtual qint64 readData( char* data, qint64 maxSize );
  50. virtual qint64 writeData( const char* data, qint64 maxSize );
  51. private:
  52. int blockForPos( qint64 pos ) const;
  53. int offsetForPos( qint64 pos ) const;
  54. QByteArray getData( qint64 pos, qint64 size );
  55. Q_DECLARE_PRIVATE( BufferIODevice )
  56. BufferIODevicePrivate* d_ptr;
  57. };
  58. #endif // BUFFERIODEVICE_H