PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 34ms app.codeStats 0ms

/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
21#ifndef STREAMCONNECTION_H
22#define STREAMCONNECTION_H
23
24#include <QObject>
25#include <QSharedPointer>
26#include <QIODevice>
27
28#include "network/Connection.h"
29#include "Result.h"
30
31#include "DllMacro.h"
32
33class ControlConnection;
34class BufferIODevice;
35
36class DLLEXPORT StreamConnection : public Connection
37{
38Q_OBJECT
39
40public:
41    enum Type
42    {
43        SENDING = 0,
44        RECEIVING = 1
45    };
46
47    // RX:
48    explicit StreamConnection( Servent* s, ControlConnection* cc, QString fid, const Tomahawk::result_ptr& result );
49    // TX:
50    explicit StreamConnection( Servent* s, ControlConnection* cc, QString fid );
51
52    virtual ~StreamConnection();
53
54    QString id() const;
55    void setup();
56    Connection* clone();
57
58    const QSharedPointer<QIODevice>& iodevice() { return m_iodev; }
59    ControlConnection* controlConnection() const { return m_cc; }
60
61    Tomahawk::source_ptr source() const;
62    Tomahawk::result_ptr track() const { return m_result; }
63    qint64 transferRate() const { return m_transferRate; }
64
65    Type type() const { return m_type; }
66    QString fid() const { return m_fid; }
67
68signals:
69    void updated();
70
71protected slots:
72    virtual void handleMsg( msg_ptr msg );
73
74private slots:
75    void startSending( const Tomahawk::result_ptr& result );
76    void reallyStartSending( const Tomahawk::result_ptr result, const QString url, QSharedPointer< QIODevice > io ); //only called back from startSending
77    void sendSome();
78    void showStats( qint64 tx, qint64 rx );
79
80    void onBlockRequest( int pos );
81
82private:
83    QSharedPointer<QIODevice> m_iodev;
84    ControlConnection* m_cc;
85    QString m_fid;
86    Type m_type;
87    QSharedPointer<QIODevice> m_readdev;
88
89    int m_curBlock;
90
91    int m_badded, m_bsent;
92    bool m_allok; // got last msg ok, transfer complete?
93
94    Tomahawk::source_ptr m_source;
95    Tomahawk::result_ptr m_result;
96    qint64 m_transferRate;
97};
98
99#endif // STREAMCONNECTION_H