libktorrent  2.2.0
chunk.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTCHUNK_H
21 #define BTCHUNK_H
22 
23 #include <ktorrent_export.h>
24 #include <util/constants.h>
25 #include <diskio/piecedata.h>
26 
27 namespace bt
28 {
29  class SHA1Hash;
30  class Cache;
31  class PieceData;
32 
45  class KTORRENT_EXPORT Chunk
46  {
47  public:
48  Chunk(Uint32 index,Uint32 size,Cache* cache);
49  ~Chunk();
50 
51  enum Status
52  {
53  ON_DISK,
54  NOT_DOWNLOADED
55  };
56 
63  bool readPiece(Uint32 off,Uint32 len,Uint8* data);
64 
73  PieceData::Ptr getPiece(Uint32 off,Uint32 len,bool read_only);
74 
80  void savePiece(PieceData::Ptr piece);
81 
83  Status getStatus() const {return status;}
84 
89  void setStatus(Status s) {status = s;}
90 
92  Uint32 getIndex() const {return index;}
93 
95  Uint32 getSize() const {return size;}
96 
98  Priority getPriority() const {return priority;}
99 
101  void setPriority(Priority newpriority = NORMAL_PRIORITY) {priority = newpriority;}
102 
104  bool isExcluded() const {return priority == EXCLUDED;}
105 
107  bool isExcludedForDownloading() const {return priority == ONLY_SEED_PRIORITY;}
108 
110  void setExclude(bool yes) {priority = yes ? EXCLUDED : NORMAL_PRIORITY;}
111 
117  bool checkHash(const SHA1Hash & h);
118 
119  private:
120  Status status;
121  Uint32 index;
122  Uint32 size;
123  Priority priority;
124  Cache* cache;
125  };
126 }
127 
128 #endif
bt::Chunk::getPriority
Priority getPriority() const
get chunk priority
Definition: chunk.h:98
bt::Chunk::isExcludedForDownloading
bool isExcludedForDownloading() const
Is this a seed only chunk.
Definition: chunk.h:107
bt::Chunk
Keep track of a piece of the file.
Definition: chunk.h:46
bt::Chunk::getIndex
Uint32 getIndex() const
Get the chunk's index.
Definition: chunk.h:92
bt::Chunk::checkHash
bool checkHash(const SHA1Hash &h)
bt::Chunk::readPiece
bool readPiece(Uint32 off, Uint32 len, Uint8 *data)
bt::Chunk::getPiece
PieceData::Ptr getPiece(Uint32 off, Uint32 len, bool read_only)
bt::Chunk::getStatus
Status getStatus() const
Get the chunks status.
Definition: chunk.h:83
bt::Chunk::getSize
Uint32 getSize() const
Get the chunk's size.
Definition: chunk.h:95
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::Cache
Manages the temporary data.
Definition: cache.h:50
bt::Chunk::setExclude
void setExclude(bool yes)
In/Exclude chunk.
Definition: chunk.h:110
bt::Chunk::savePiece
void savePiece(PieceData::Ptr piece)
bt::Chunk::setStatus
void setStatus(Status s)
Definition: chunk.h:89
bt::Chunk::isExcluded
bool isExcluded() const
Is chunk excluded.
Definition: chunk.h:104
bt::Chunk::setPriority
void setPriority(Priority newpriority=NORMAL_PRIORITY)
set chunk priority
Definition: chunk.h:101