2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

DownloadContext now has _fileEntries so that
	DownloadContext::getFileEntries() can returns its const reference.
	* src/DefaultBtContext.cc
	* src/DefaultBtContext.h
	* src/DownloadContext.cc
	* src/DownloadContext.h
	* src/SingleFileDownloadContext.cc
	* src/SingleFileDownloadContext.h
pull/1/head
Tatsuhiro Tsujikawa 2009-06-14 11:12:20 +00:00
parent 9120e79ff1
commit 39472a64eb
7 changed files with 40 additions and 38 deletions

View File

@ -1,3 +1,14 @@
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
DownloadContext now has _fileEntries so that
DownloadContext::getFileEntries() can returns its const reference.
* src/DefaultBtContext.cc
* src/DefaultBtContext.h
* src/DownloadContext.cc
* src/DownloadContext.h
* src/SingleFileDownloadContext.cc
* src/SingleFileDownloadContext.h
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved getFirstRequestedFileEntry(), countRequestedFileEntry() and

View File

@ -122,7 +122,7 @@ void DefaultBtContext::clear() {
memset(infoHash, 0, INFO_HASH_LENGTH);
infoHashString = A2STR::NIL;
pieceHashes.clear();
fileEntries.clear();
_fileEntries.clear();
totalLength = 0;
pieceLength = 0;
fileMode = BtContext::SINGLE;
@ -211,7 +211,7 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
FileEntryHandle fileEntry(new FileEntry(strconcat(_dir, "/", path),
fileLengthData.i(),
offset, uris));
fileEntries.push_back(fileEntry);
_fileEntries.push_back(fileEntry);
offset += fileEntry->getLength();
}
totalLength = length;
@ -245,7 +245,7 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
Util::joinPath(pathelems.begin(),
pathelems.end())),
totalLength, 0, uris));
fileEntries.push_back(fileEntry);
_fileEntries.push_back(fileEntry);
}
}
@ -435,10 +435,6 @@ BtContext::FILE_MODE DefaultBtContext::getFileMode() const {
return fileMode;
}
FileEntries DefaultBtContext::getFileEntries() const {
return fileEntries;
}
const std::string& DefaultBtContext::getPieceHashAlgo() const
{
return MessageDigestContext::SHA1;
@ -464,8 +460,8 @@ size_t DefaultBtContext::getNumPieces() const {
std::string DefaultBtContext::getActualBasePath() const
{
if(fileEntries.size() == 1) {
return fileEntries.front()->getPath();
if(_fileEntries.size() == 1) {
return _fileEntries.front()->getPath();
} else {
return strconcat(_dir, "/", name);
}
@ -552,8 +548,8 @@ void DefaultBtContext::setInfoHash(const unsigned char* infoHash)
void DefaultBtContext::setFilePathWithIndex
(size_t index, const std::string& path)
{
if(0 < index && index <= fileEntries.size()) {
fileEntries[index-1]->setPath(path);
if(0 < index && index <= _fileEntries.size()) {
_fileEntries[index-1]->setPath(path);
} else {
throw DL_ABORT_EX(StringFormat("No such file with index=%u",
static_cast<unsigned int>(index)).str());
@ -567,11 +563,11 @@ void DefaultBtContext::setFileFilter(IntSequence seq)
fileIndexes.erase(std::unique(fileIndexes.begin(), fileIndexes.end()),
fileIndexes.end());
bool selectAll = fileIndexes.empty() || fileEntries.size() == 1;
bool selectAll = fileIndexes.empty() || _fileEntries.size() == 1;
int32_t index = 1;
for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
fileEntries.begin(); i != fileEntries.end(); ++i, ++index) {
_fileEntries.begin(); i != _fileEntries.end(); ++i, ++index) {
(*i)->setRequested
(selectAll ||
std::binary_search(fileIndexes.begin(), fileIndexes.end(), index));

View File

@ -55,7 +55,6 @@ private:
unsigned char infoHash[INFO_HASH_LENGTH];
std::string infoHashString;
std::deque<std::string> pieceHashes;
std::deque<SharedHandle<FileEntry> > fileEntries;
FILE_MODE fileMode;
uint64_t totalLength;
size_t pieceLength;
@ -143,8 +142,6 @@ private:
virtual FILE_MODE getFileMode() const;
virtual std::deque<SharedHandle<FileEntry> > getFileEntries() const;
virtual const std::string& getPieceHashAlgo() const;
virtual const std::deque<SharedHandle<AnnounceTier> >&

View File

@ -33,6 +33,7 @@
*/
/* copyright --> */
#include "DownloadContext.h"
#include "FileEntry.h"
namespace aria2 {

View File

@ -51,8 +51,9 @@ class FileEntry;
class DownloadContext
{
protected:
std::string _dir;
std::deque<SharedHandle<FileEntry> > _fileEntries;
std::string _dir;
private:
Time _downloadStartTime;
@ -79,7 +80,10 @@ public:
virtual FILE_MODE getFileMode() const = 0;
virtual std::deque<SharedHandle<FileEntry> > getFileEntries() const = 0;
const std::deque<SharedHandle<FileEntry> >& getFileEntries() const
{
return _fileEntries;
}
virtual size_t getPieceLength() const = 0;

View File

@ -44,22 +44,24 @@ SingleFileDownloadContext::SingleFileDownloadContext(size_t pieceLength,
const std::string& filename,
const std::string& ufilename):
_pieceLength(pieceLength),
_fileEntry(new FileEntry(filename, totalLength, 0)),
_filename(filename),
_ufilename(ufilename),
_knowsTotalLength(true)
{
_fileEntries.push_back
(SharedHandle<FileEntry>(new FileEntry(filename, totalLength, 0)));
updateFileEntry();
}
void SingleFileDownloadContext::updateFileEntry()
{
const SharedHandle<FileEntry>& fileEntry = _fileEntries.front();
if(!_ufilename.empty()) {
_fileEntry->setPath(_ufilename);
fileEntry->setPath(_ufilename);
} else if(!_filename.empty()) {
_fileEntry->setPath(_filename);
fileEntry->setPath(_filename);
} else {
_fileEntry->setPath("");
fileEntry->setPath("");
}
}
@ -71,7 +73,7 @@ SingleFileDownloadContext::getPieceHashes() const
uint64_t SingleFileDownloadContext::getTotalLength() const
{
return _fileEntry->getLength();
return _fileEntries.front()->getLength();
}
bool SingleFileDownloadContext::knowsTotalLength() const
@ -79,27 +81,19 @@ bool SingleFileDownloadContext::knowsTotalLength() const
return _knowsTotalLength;
}
FileEntries
SingleFileDownloadContext::getFileEntries() const
{
FileEntries fs;
fs.push_back(_fileEntry);
return fs;
}
size_t SingleFileDownloadContext::getNumPieces() const
{
return (_fileEntry->getLength()+_pieceLength-1)/_pieceLength;
return (_fileEntries.front()->getLength()+_pieceLength-1)/_pieceLength;
}
std::string SingleFileDownloadContext::getActualBasePath() const
{
return _fileEntry->getPath();
return _fileEntries.front()->getPath();
}
void SingleFileDownloadContext::setTotalLength(uint64_t totalLength)
{
_fileEntry->setLength(totalLength);
_fileEntries.front()->setLength(totalLength);
}
void SingleFileDownloadContext::markTotalLengthIsUnknown()

View File

@ -36,17 +36,18 @@
#define _D_SINGLE_FILE_DOWNLOAD_CONTEXT_H_
#include "DownloadContext.h"
#include "A2STR.h"
#include <string>
#include <deque>
#include "A2STR.h"
namespace aria2 {
class SingleFileDownloadContext:public DownloadContext
{
private:
size_t _pieceLength;
SharedHandle<FileEntry> _fileEntry;
/**
* _filename and _ufilename may contains directory path name. So
* /usr/local/aria2c is acceptable here. These should be complete
@ -95,8 +96,6 @@ public:
return SINGLE;
}
virtual std::deque<SharedHandle<FileEntry> > getFileEntries() const;
virtual size_t getPieceLength() const
{
return _pieceLength;