libktorrent  2.2.0
piecedownloader.h
1 /***************************************************************************
2  * Copyright (C) 2007 by Joris Guisson and Ivan Vasic *
3  * joris.guisson@gmail.com *
4  * ivasic@gmail.com *
5  * *
6  * This program 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 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program 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 this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20  ***************************************************************************/
21 #ifndef BTPIECEDOWNLOADER_H
22 #define BTPIECEDOWNLOADER_H
23 
24 #include <QObject>
25 #include <ktorrent_export.h>
26 #include <util/constants.h>
27 
28 namespace bt
29 {
30  class Piece;
31  class Request;
32 
37  class KTORRENT_EXPORT PieceDownloader : public QObject
38  {
39  Q_OBJECT
40  public:
42  ~PieceDownloader() override;
43 
49  int grab();
50 
55  void release();
56 
58  int getNumGrabbed() const {return grabbed;}
59 
64  virtual void download(const bt::Request & req) = 0;
65 
70  virtual void cancel(const bt::Request & req) = 0;
71 
75  virtual void cancelAll() = 0;
76 
83  virtual QString getName() const = 0;
84 
89  virtual bt::Uint32 getDownloadRate() const = 0;
90 
95  virtual bool isChoked() const {return false;}
96 
100  virtual bool canAddRequest() const = 0;
101 
105  virtual bool canDownloadChunk() const = 0;
106 
108  bool isNearlyDone() const {return getNumGrabbed() == 1 && nearly_done;}
109 
111  void setNearlyDone(bool nd) {nearly_done = nd;}
112 
119  virtual bool hasChunk(bt::Uint32 /*idx*/) const {return true;}
120 
124  virtual void checkTimeouts() = 0;
125 
126  Q_SIGNALS:
133  void timedout(const bt::Request & r);
134 
139  void rejected(const bt::Request & req);
140 
141  private:
142  int grabbed;
143  bool nearly_done;
144  };
145 
146 }
147 
148 #endif
bt::PieceDownloader::checkTimeouts
virtual void checkTimeouts()=0
bt::PieceDownloader::canDownloadChunk
virtual bool canDownloadChunk() const =0
bt::PieceDownloader::cancelAll
virtual void cancelAll()=0
bt::PieceDownloader
Definition: piecedownloader.h:38
bt::PieceDownloader::cancel
virtual void cancel(const bt::Request &req)=0
bt::PieceDownloader::isChoked
virtual bool isChoked() const
Definition: piecedownloader.h:95
bt::PieceDownloader::getName
virtual QString getName() const =0
bt::PieceDownloader::grab
int grab()
bt::Request
Request of a piece sent to other peers.
Definition: request.h:40
bt::PieceDownloader::rejected
void rejected(const bt::Request &req)
bt::PieceDownloader::canAddRequest
virtual bool canAddRequest() const =0
bt::PieceDownloader::getNumGrabbed
int getNumGrabbed() const
Get the number of times this PeerDownloader was grabbed.
Definition: piecedownloader.h:58
bt::PieceDownloader::download
virtual void download(const bt::Request &req)=0
bt::PieceDownloader::setNearlyDone
void setNearlyDone(bool nd)
Set the nearly done status of the PeerDownloader.
Definition: piecedownloader.h:111
bt::PieceDownloader::isNearlyDone
bool isNearlyDone() const
See if this PieceDownloader has nearly finished a chunk.
Definition: piecedownloader.h:108
bt::PieceDownloader::release
void release()
bt::PieceDownloader::getDownloadRate
virtual bt::Uint32 getDownloadRate() const =0
bt::PieceDownloader::timedout
void timedout(const bt::Request &r)
bt::PieceDownloader::hasChunk
virtual bool hasChunk(bt::Uint32) const
Definition: piecedownloader.h:119