/src/libtomahawk/network/StreamConnection.h

http://github.com/tomahawk-player/tomahawk · C Header · 99 lines · 56 code · 22 blank · 21 comment · 0 complexity · 58c0a73afef5079e2d3976d7532df374 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 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5. * Copyright 2013, Teo Mrnjavac <teo@kde.org>
  6. *
  7. * Tomahawk is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tomahawk is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef STREAMCONNECTION_H
  21. #define STREAMCONNECTION_H
  22. #include <QObject>
  23. #include <QSharedPointer>
  24. #include <QIODevice>
  25. #include "network/Connection.h"
  26. #include "Result.h"
  27. #include "DllMacro.h"
  28. class ControlConnection;
  29. class BufferIODevice;
  30. class DLLEXPORT StreamConnection : public Connection
  31. {
  32. Q_OBJECT
  33. public:
  34. enum Type
  35. {
  36. SENDING = 0,
  37. RECEIVING = 1
  38. };
  39. // RX:
  40. explicit StreamConnection( Servent* s, ControlConnection* cc, QString fid, const Tomahawk::result_ptr& result );
  41. // TX:
  42. explicit StreamConnection( Servent* s, ControlConnection* cc, QString fid );
  43. virtual ~StreamConnection();
  44. QString id() const;
  45. void setup();
  46. Connection* clone();
  47. const QSharedPointer<QIODevice>& iodevice() { return m_iodev; }
  48. ControlConnection* controlConnection() const { return m_cc; }
  49. Tomahawk::source_ptr source() const;
  50. Tomahawk::result_ptr track() const { return m_result; }
  51. qint64 transferRate() const { return m_transferRate; }
  52. Type type() const { return m_type; }
  53. QString fid() const { return m_fid; }
  54. signals:
  55. void updated();
  56. protected slots:
  57. virtual void handleMsg( msg_ptr msg );
  58. private slots:
  59. void startSending( const Tomahawk::result_ptr& result );
  60. void reallyStartSending( const Tomahawk::result_ptr result, const QString url, QSharedPointer< QIODevice > io ); //only called back from startSending
  61. void sendSome();
  62. void showStats( qint64 tx, qint64 rx );
  63. void onBlockRequest( int pos );
  64. private:
  65. QSharedPointer<QIODevice> m_iodev;
  66. ControlConnection* m_cc;
  67. QString m_fid;
  68. Type m_type;
  69. QSharedPointer<QIODevice> m_readdev;
  70. int m_curBlock;
  71. int m_badded, m_bsent;
  72. bool m_allok; // got last msg ok, transfer complete?
  73. Tomahawk::source_ptr m_source;
  74. Tomahawk::result_ptr m_result;
  75. qint64 m_transferRate;
  76. };
  77. #endif // STREAMCONNECTION_H