2010-06-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Made protected member variable private. Added accessor funcs.
	* src/BtCheckIntegrityEntry.cc
	* src/BtFileAllocationEntry.cc
	* src/CheckIntegrityEntry.cc
	* src/CheckIntegrityEntry.h
	* src/ChecksumCheckIntegrityEntry.cc
	* src/FileAllocationEntry.cc
	* src/PieceHashCheckIntegrityEntry.cc
	* src/RequestGroupEntry.h
	* src/StreamCheckIntegrityEntry.cc
	* src/StreamFileAllocationEntry.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-06-09 15:04:01 +00:00
parent f114c89096
commit a68b29a31a
11 changed files with 62 additions and 36 deletions

View File

@ -1,3 +1,17 @@
2010-06-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs.
* src/BtCheckIntegrityEntry.cc
* src/BtFileAllocationEntry.cc
* src/CheckIntegrityEntry.cc
* src/CheckIntegrityEntry.h
* src/ChecksumCheckIntegrityEntry.cc
* src/FileAllocationEntry.cc
* src/PieceHashCheckIntegrityEntry.cc
* src/RequestGroupEntry.h
* src/StreamCheckIntegrityEntry.cc
* src/StreamFileAllocationEntry.cc
2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs. Made protected member variable private. Added accessor funcs.

View File

@ -55,7 +55,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e) (std::vector<Command*>& commands, DownloadEngine* e)
{ {
const SharedHandle<DiskAdaptor>& diskAdaptor = const SharedHandle<DiskAdaptor>& diskAdaptor =
_requestGroup->getPieceStorage()->getDiskAdaptor(); getRequestGroup()->getPieceStorage()->getDiskAdaptor();
if(diskAdaptor->isReadOnlyEnabled()) { if(diskAdaptor->isReadOnlyEnabled()) {
// Now reopen DiskAdaptor with read only disabled. // Now reopen DiskAdaptor with read only disabled.
diskAdaptor->closeFile(); diskAdaptor->closeFile();
@ -63,7 +63,7 @@ void BtCheckIntegrityEntry::onDownloadIncomplete
diskAdaptor->openFile(); diskAdaptor->openFile();
} }
SharedHandle<BtFileAllocationEntry> entry SharedHandle<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(_requestGroup)); (new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e); proceedFileAllocation(commands, entry, e);
} }
@ -74,9 +74,9 @@ void BtCheckIntegrityEntry::onDownloadFinished
// are valid, then aira2 goes to seeding mode. Sometimes it is better // are valid, then aira2 goes to seeding mode. Sometimes it is better
// to exit rather than doing seeding. So, it would be good to toggle this // to exit rather than doing seeding. So, it would be good to toggle this
// behavior. // behavior.
if(_requestGroup->getOption()->getAsBool(PREF_BT_HASH_CHECK_SEED)) { if(getRequestGroup()->getOption()->getAsBool(PREF_BT_HASH_CHECK_SEED)) {
SharedHandle<BtFileAllocationEntry> entry SharedHandle<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(_requestGroup)); (new BtFileAllocationEntry(getRequestGroup()));
proceedFileAllocation(commands, entry, e); proceedFileAllocation(commands, entry, e);
} }
} }

View File

@ -55,13 +55,15 @@ BtFileAllocationEntry::~BtFileAllocationEntry() {}
void BtFileAllocationEntry::prepareForNextAction void BtFileAllocationEntry::prepareForNextAction
(std::vector<Command*>& commands, DownloadEngine* e) (std::vector<Command*>& commands, DownloadEngine* e)
{ {
BtSetup().setup(commands, _requestGroup, e, _requestGroup->getOption().get()); BtSetup().setup(commands, getRequestGroup(), e,
if(!_requestGroup->downloadFinished()) { getRequestGroup()->getOption().get());
_requestGroup->getDownloadContext()->resetDownloadStartTime(); if(!getRequestGroup()->downloadFinished()) {
getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
const std::vector<SharedHandle<FileEntry> >& fileEntries = const std::vector<SharedHandle<FileEntry> >& fileEntries =
_requestGroup->getDownloadContext()->getFileEntries(); getRequestGroup()->getDownloadContext()->getFileEntries();
if(isUriSuppliedForRequsetFileEntry(fileEntries.begin(), fileEntries.end())) { if(isUriSuppliedForRequsetFileEntry
_requestGroup->createNextCommandWithAdj(commands, e, 0); (fileEntries.begin(), fileEntries.end())) {
getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
} }
} }
} }

View File

@ -84,7 +84,7 @@ bool CheckIntegrityEntry::finished()
void CheckIntegrityEntry::cutTrailingGarbage() void CheckIntegrityEntry::cutTrailingGarbage()
{ {
_requestGroup->getPieceStorage()->getDiskAdaptor()->cutTrailingGarbage(); getRequestGroup()->getPieceStorage()->getDiskAdaptor()->cutTrailingGarbage();
} }
void CheckIntegrityEntry::proceedFileAllocation void CheckIntegrityEntry::proceedFileAllocation
@ -92,16 +92,21 @@ void CheckIntegrityEntry::proceedFileAllocation
const SharedHandle<FileAllocationEntry>& entry, const SharedHandle<FileAllocationEntry>& entry,
DownloadEngine* e) DownloadEngine* e)
{ {
if(_requestGroup->needsFileAllocation()) { if(getRequestGroup()->needsFileAllocation()) {
e->getFileAllocationMan()->pushEntry(entry); e->getFileAllocationMan()->pushEntry(entry);
} else { } else {
entry->prepareForNextAction(commands, e); entry->prepareForNextAction(commands, e);
} }
// Disable directIO when fallocation() is going to be used. // Disable directIO when fallocation() is going to be used.
if(_requestGroup->getOption()->get(PREF_FILE_ALLOCATION) == V_FALLOC) { if(getRequestGroup()->getOption()->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
entry->disableDirectIO(); entry->disableDirectIO();
} }
} }
void CheckIntegrityEntry::setValidator
(const SharedHandle<IteratableValidator>& validator)
{
_validator = validator;
}
} // namespace aria2 } // namespace aria2

View File

@ -48,8 +48,10 @@ class FileAllocationEntry;
class CheckIntegrityEntry : public RequestGroupEntry, class CheckIntegrityEntry : public RequestGroupEntry,
public ProgressAwareEntry { public ProgressAwareEntry {
protected: private:
SharedHandle<IteratableValidator> _validator; SharedHandle<IteratableValidator> _validator;
protected:
void setValidator(const SharedHandle<IteratableValidator>& validator);
void proceedFileAllocation(std::vector<Command*>& commands, void proceedFileAllocation(std::vector<Command*>& commands,
const SharedHandle<FileAllocationEntry>& entry, const SharedHandle<FileAllocationEntry>& entry,

View File

@ -52,16 +52,17 @@ ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
bool ChecksumCheckIntegrityEntry::isValidationReady() bool ChecksumCheckIntegrityEntry::isValidationReady()
{ {
return !_requestGroup->getDownloadContext()->getChecksum().empty() && return !getRequestGroup()->getDownloadContext()->getChecksum().empty() &&
!_requestGroup->getDownloadContext()->getChecksumHashAlgo().empty(); !getRequestGroup()->getDownloadContext()->getChecksumHashAlgo().empty();
} }
void ChecksumCheckIntegrityEntry::initValidator() void ChecksumCheckIntegrityEntry::initValidator()
{ {
_validator.reset(new IteratableChecksumValidator SharedHandle<IteratableChecksumValidator> validator
(_requestGroup->getDownloadContext(), (new IteratableChecksumValidator(getRequestGroup()->getDownloadContext(),
_requestGroup->getPieceStorage())); getRequestGroup()->getPieceStorage()));
_validator->init(); validator->init();
setValidator(validator);
} }
void void

View File

@ -49,12 +49,12 @@ FileAllocationEntry::FileAllocationEntry(RequestGroup* requestGroup, Command* ne
RequestGroupEntry(requestGroup, nextCommand), RequestGroupEntry(requestGroup, nextCommand),
_fileAllocationIterator(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator()) _fileAllocationIterator(requestGroup->getPieceStorage()->getDiskAdaptor()->fileAllocationIterator())
{ {
_requestGroup->getPieceStorage()->getDiskAdaptor()->enableDirectIO(); getRequestGroup()->getPieceStorage()->getDiskAdaptor()->enableDirectIO();
} }
FileAllocationEntry:: ~FileAllocationEntry() FileAllocationEntry:: ~FileAllocationEntry()
{ {
_requestGroup->getPieceStorage()->getDiskAdaptor()->disableDirectIO(); getRequestGroup()->getPieceStorage()->getDiskAdaptor()->disableDirectIO();
} }
off_t FileAllocationEntry::getCurrentLength() off_t FileAllocationEntry::getCurrentLength()
@ -79,7 +79,7 @@ void FileAllocationEntry::allocateChunk()
void FileAllocationEntry::disableDirectIO() void FileAllocationEntry::disableDirectIO()
{ {
_requestGroup->getPieceStorage()->getDiskAdaptor()->disableDirectIO(); getRequestGroup()->getPieceStorage()->getDiskAdaptor()->disableDirectIO();
} }
} // namespace aria2 } // namespace aria2

View File

@ -40,8 +40,9 @@
namespace aria2 { namespace aria2 {
PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry(RequestGroup* requestGroup, PieceHashCheckIntegrityEntry::PieceHashCheckIntegrityEntry
Command* nextCommand): (RequestGroup* requestGroup,
Command* nextCommand):
CheckIntegrityEntry(requestGroup, nextCommand) {} CheckIntegrityEntry(requestGroup, nextCommand) {}
PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {} PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
@ -49,7 +50,7 @@ PieceHashCheckIntegrityEntry::~PieceHashCheckIntegrityEntry() {}
bool PieceHashCheckIntegrityEntry::isValidationReady() bool PieceHashCheckIntegrityEntry::isValidationReady()
{ {
const SharedHandle<DownloadContext>& dctx = const SharedHandle<DownloadContext>& dctx =
_requestGroup->getDownloadContext(); getRequestGroup()->getDownloadContext();
return !dctx->getPieceHashAlgo().empty() && return !dctx->getPieceHashAlgo().empty() &&
dctx->getPieceHashes().size() > 0 && dctx->getPieceHashes().size() > 0 &&
dctx->getPieceHashes().size() == dctx->getNumPieces(); dctx->getPieceHashes().size() == dctx->getNumPieces();
@ -59,10 +60,11 @@ void PieceHashCheckIntegrityEntry::initValidator()
{ {
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
IteratableChunkChecksumValidatorHandle validator IteratableChunkChecksumValidatorHandle validator
(new IteratableChunkChecksumValidator(_requestGroup->getDownloadContext(), (new IteratableChunkChecksumValidator
_requestGroup->getPieceStorage())); (getRequestGroup()->getDownloadContext(),
getRequestGroup()->getPieceStorage()));
validator->init(); validator->init();
_validator = validator; setValidator(validator);
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
} }

View File

@ -44,7 +44,7 @@ class RequestGroup;
class Command; class Command;
class RequestGroupEntry { class RequestGroupEntry {
protected: private:
RequestGroup* _requestGroup; RequestGroup* _requestGroup;
Command* _nextCommand; Command* _nextCommand;
public: public:

View File

@ -53,7 +53,7 @@ void StreamCheckIntegrityEntry::onDownloadIncomplete
(std::vector<Command*>& commands, DownloadEngine* e) (std::vector<Command*>& commands, DownloadEngine* e)
{ {
SharedHandle<FileAllocationEntry> entry SharedHandle<FileAllocationEntry> entry
(new StreamFileAllocationEntry(_requestGroup, popNextCommand())); (new StreamFileAllocationEntry(getRequestGroup(), popNextCommand()));
proceedFileAllocation(commands, entry, e); proceedFileAllocation(commands, entry, e);
} }

View File

@ -59,16 +59,16 @@ void StreamFileAllocationEntry::prepareForNextAction
(std::vector<Command*>& commands, (std::vector<Command*>& commands,
DownloadEngine* e) DownloadEngine* e)
{ {
_requestGroup->getDownloadContext()->resetDownloadStartTime(); getRequestGroup()->getDownloadContext()->resetDownloadStartTime();
if(_nextCommand) { if(getNextCommand()) {
// give _nextCommand a chance to execute in the next execution loop. // give _nextCommand a chance to execute in the next execution loop.
_nextCommand->setStatus(Command::STATUS_ONESHOT_REALTIME); getNextCommand()->setStatus(Command::STATUS_ONESHOT_REALTIME);
e->setNoWait(true); e->setNoWait(true);
commands.push_back(popNextCommand()); commands.push_back(popNextCommand());
// try remaining uris // try remaining uris
_requestGroup->createNextCommandWithAdj(commands, e, -1); getRequestGroup()->createNextCommandWithAdj(commands, e, -1);
} else { } else {
_requestGroup->createNextCommandWithAdj(commands, e, 0); getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
} }
} }