mirror of https://github.com/aria2/aria2
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variable * src/AnnounceList.cc * src/AnnounceList.hpull/1/head
parent
b914f6d810
commit
cd48873d41
|
@ -1,3 +1,9 @@
|
||||||
|
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Renamed member variable
|
||||||
|
* src/AnnounceList.cc
|
||||||
|
* src/AnnounceList.h
|
||||||
|
|
||||||
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Made protected member variable private. Added accessor funcs.
|
Made protected member variable private. Added accessor funcs.
|
||||||
|
|
|
@ -50,13 +50,13 @@ const std::string AnnounceList::STOPPED("stopped");
|
||||||
const std::string AnnounceList::COMPLETED("completed");
|
const std::string AnnounceList::COMPLETED("completed");
|
||||||
|
|
||||||
AnnounceList::AnnounceList(const BDE& announceList):
|
AnnounceList::AnnounceList(const BDE& announceList):
|
||||||
currentTrackerInitialized(false) {
|
_currentTrackerInitialized(false) {
|
||||||
reconfigure(announceList);
|
reconfigure(announceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnounceList::AnnounceList
|
AnnounceList::AnnounceList
|
||||||
(const std::deque<SharedHandle<AnnounceTier> >& announceTiers):
|
(const std::deque<SharedHandle<AnnounceTier> >& announceTiers):
|
||||||
tiers(announceTiers), currentTrackerInitialized(false) {
|
_tiers(announceTiers), _currentTrackerInitialized(false) {
|
||||||
resetIterator();
|
resetIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ void AnnounceList::reconfigure(const BDE& announceList)
|
||||||
}
|
}
|
||||||
if(!urls.empty()) {
|
if(!urls.empty()) {
|
||||||
SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
|
SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
|
||||||
tiers.push_back(tier);
|
_tiers.push_back(tier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resetIterator();
|
resetIterator();
|
||||||
|
@ -89,72 +89,72 @@ void AnnounceList::reconfigure(const BDE& announceList)
|
||||||
void AnnounceList::reconfigure(const std::string& url) {
|
void AnnounceList::reconfigure(const std::string& url) {
|
||||||
std::deque<std::string> urls;
|
std::deque<std::string> urls;
|
||||||
urls.push_back(url);
|
urls.push_back(url);
|
||||||
tiers.push_back(SharedHandle<AnnounceTier>(new AnnounceTier(urls)));
|
_tiers.push_back(SharedHandle<AnnounceTier>(new AnnounceTier(urls)));
|
||||||
resetIterator();
|
resetIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::resetIterator() {
|
void AnnounceList::resetIterator() {
|
||||||
currentTier = tiers.begin();
|
_currentTier = _tiers.begin();
|
||||||
if(currentTier != tiers.end() && (*currentTier)->urls.size()) {
|
if(_currentTier != _tiers.end() && (*_currentTier)->urls.size()) {
|
||||||
currentTracker = (*currentTier)->urls.begin();
|
_currentTracker = (*_currentTier)->urls.begin();
|
||||||
currentTrackerInitialized = true;
|
_currentTrackerInitialized = true;
|
||||||
} else {
|
} else {
|
||||||
currentTrackerInitialized = false;
|
_currentTrackerInitialized = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AnnounceList::getAnnounce() const {
|
std::string AnnounceList::getAnnounce() const {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
return *currentTracker;
|
return *_currentTracker;
|
||||||
} else {
|
} else {
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::announceSuccess() {
|
void AnnounceList::announceSuccess() {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
(*currentTier)->nextEvent();
|
(*_currentTier)->nextEvent();
|
||||||
std::string url = *currentTracker;
|
std::string url = *_currentTracker;
|
||||||
(*currentTier)->urls.erase(currentTracker);
|
(*_currentTier)->urls.erase(_currentTracker);
|
||||||
(*currentTier)->urls.push_front(url);
|
(*_currentTier)->urls.push_front(url);
|
||||||
currentTier = tiers.begin();
|
_currentTier = _tiers.begin();
|
||||||
currentTracker = (*currentTier)->urls.begin();
|
_currentTracker = (*_currentTier)->urls.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::announceFailure() {
|
void AnnounceList::announceFailure() {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
++currentTracker;
|
++_currentTracker;
|
||||||
if(currentTracker == (*currentTier)->urls.end()) {
|
if(_currentTracker == (*_currentTier)->urls.end()) {
|
||||||
// force next event
|
// force next event
|
||||||
(*currentTier)->nextEventIfAfterStarted();
|
(*_currentTier)->nextEventIfAfterStarted();
|
||||||
++currentTier;
|
++_currentTier;
|
||||||
if(currentTier == tiers.end()) {
|
if(_currentTier == _tiers.end()) {
|
||||||
currentTrackerInitialized = false;
|
_currentTrackerInitialized = false;
|
||||||
} else {
|
} else {
|
||||||
currentTracker = (*currentTier)->urls.begin();
|
_currentTracker = (*_currentTier)->urls.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnounceTier::AnnounceEvent AnnounceList::getEvent() const {
|
AnnounceTier::AnnounceEvent AnnounceList::getEvent() const {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
return (*currentTier)->event;
|
return (*_currentTier)->event;
|
||||||
} else {
|
} else {
|
||||||
return AnnounceTier::STARTED;
|
return AnnounceTier::STARTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::setEvent(AnnounceTier::AnnounceEvent event) {
|
void AnnounceList::setEvent(AnnounceTier::AnnounceEvent event) {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
(*currentTier)->event = event;
|
(*_currentTier)->event = event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string AnnounceList::getEventString() const {
|
std::string AnnounceList::getEventString() const {
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
switch((*currentTier)->event) {
|
switch((*_currentTier)->event) {
|
||||||
case AnnounceTier::STARTED:
|
case AnnounceTier::STARTED:
|
||||||
case AnnounceTier::STARTED_AFTER_COMPLETION:
|
case AnnounceTier::STARTED_AFTER_COMPLETION:
|
||||||
return STARTED;
|
return STARTED;
|
||||||
|
@ -199,18 +199,18 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t AnnounceList::countStoppedAllowedTier() const {
|
size_t AnnounceList::countStoppedAllowedTier() const {
|
||||||
return count_if(tiers.begin(), tiers.end(), FindStoppedAllowedTier());
|
return count_if(_tiers.begin(), _tiers.end(), FindStoppedAllowedTier());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AnnounceList::countCompletedAllowedTier() const {
|
size_t AnnounceList::countCompletedAllowedTier() const {
|
||||||
return count_if(tiers.begin(), tiers.end(), FindCompletedAllowedTier());
|
return count_if(_tiers.begin(), _tiers.end(), FindCompletedAllowedTier());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::setCurrentTier
|
void AnnounceList::setCurrentTier
|
||||||
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr) {
|
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr) {
|
||||||
if(itr != tiers.end()) {
|
if(itr != _tiers.end()) {
|
||||||
currentTier = itr;
|
_currentTier = itr;
|
||||||
currentTracker = (*currentTier)->urls.begin();
|
_currentTracker = (*_currentTier)->urls.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,23 +227,23 @@ find_wrap_if(InputIterator first, InputIterator last,
|
||||||
|
|
||||||
void AnnounceList::moveToStoppedAllowedTier() {
|
void AnnounceList::moveToStoppedAllowedTier() {
|
||||||
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
|
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
|
||||||
find_wrap_if(tiers.begin(), tiers.end(),
|
find_wrap_if(_tiers.begin(), _tiers.end(),
|
||||||
currentTier,
|
_currentTier,
|
||||||
FindStoppedAllowedTier());
|
FindStoppedAllowedTier());
|
||||||
setCurrentTier(itr);
|
setCurrentTier(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::moveToCompletedAllowedTier() {
|
void AnnounceList::moveToCompletedAllowedTier() {
|
||||||
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
|
std::deque<SharedHandle<AnnounceTier> >::iterator itr =
|
||||||
find_wrap_if(tiers.begin(), tiers.end(),
|
find_wrap_if(_tiers.begin(), _tiers.end(),
|
||||||
currentTier,
|
_currentTier,
|
||||||
FindCompletedAllowedTier());
|
FindCompletedAllowedTier());
|
||||||
setCurrentTier(itr);
|
setCurrentTier(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::shuffle() {
|
void AnnounceList::shuffle() {
|
||||||
for(std::deque<SharedHandle<AnnounceTier> >::const_iterator itr =
|
for(std::deque<SharedHandle<AnnounceTier> >::const_iterator itr =
|
||||||
tiers.begin(), eoi = tiers.end(); itr != eoi; ++itr) {
|
_tiers.begin(), eoi = _tiers.end(); itr != eoi; ++itr) {
|
||||||
std::deque<std::string>& urls = (*itr)->urls;
|
std::deque<std::string>& urls = (*itr)->urls;
|
||||||
std::random_shuffle(urls.begin(), urls.end(),
|
std::random_shuffle(urls.begin(), urls.end(),
|
||||||
*(SimpleRandomizer::getInstance().get()));
|
*(SimpleRandomizer::getInstance().get()));
|
||||||
|
@ -252,7 +252,7 @@ void AnnounceList::shuffle() {
|
||||||
|
|
||||||
bool AnnounceList::allTiersFailed() const
|
bool AnnounceList::allTiersFailed() const
|
||||||
{
|
{
|
||||||
return currentTier == tiers.end();
|
return _currentTier == _tiers.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::resetTier()
|
void AnnounceList::resetTier()
|
||||||
|
@ -262,8 +262,8 @@ void AnnounceList::resetTier()
|
||||||
|
|
||||||
bool AnnounceList::currentTierAcceptsStoppedEvent() const
|
bool AnnounceList::currentTierAcceptsStoppedEvent() const
|
||||||
{
|
{
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
return FindStoppedAllowedTier()(*currentTier);
|
return FindStoppedAllowedTier()(*_currentTier);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -271,8 +271,8 @@ bool AnnounceList::currentTierAcceptsStoppedEvent() const
|
||||||
|
|
||||||
bool AnnounceList::currentTierAcceptsCompletedEvent() const
|
bool AnnounceList::currentTierAcceptsCompletedEvent() const
|
||||||
{
|
{
|
||||||
if(currentTrackerInitialized) {
|
if(_currentTrackerInitialized) {
|
||||||
return FindCompletedAllowedTier()(*currentTier);
|
return FindCompletedAllowedTier()(*_currentTier);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,15 +46,16 @@ class BDE;
|
||||||
class AnnounceList {
|
class AnnounceList {
|
||||||
public:
|
public:
|
||||||
private:
|
private:
|
||||||
std::deque<SharedHandle<AnnounceTier> > tiers;
|
std::deque<SharedHandle<AnnounceTier> > _tiers;
|
||||||
std::deque<SharedHandle<AnnounceTier> >::iterator currentTier;
|
std::deque<SharedHandle<AnnounceTier> >::iterator _currentTier;
|
||||||
std::deque<std::string>::iterator currentTracker;
|
std::deque<std::string>::iterator _currentTracker;
|
||||||
bool currentTrackerInitialized;
|
bool _currentTrackerInitialized;
|
||||||
|
|
||||||
void resetIterator();
|
void resetIterator();
|
||||||
void setCurrentTier(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
|
void setCurrentTier
|
||||||
|
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
|
||||||
public:
|
public:
|
||||||
AnnounceList():currentTrackerInitialized(false) {}
|
AnnounceList():_currentTrackerInitialized(false) {}
|
||||||
AnnounceList(const BDE& announceList);
|
AnnounceList(const BDE& announceList);
|
||||||
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
|
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ public:
|
||||||
void reconfigure(const std::string& url);
|
void reconfigure(const std::string& url);
|
||||||
|
|
||||||
size_t countTier() const {
|
size_t countTier() const {
|
||||||
return tiers.size();
|
return _tiers.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue