2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Rewritten AccRequestGroup
	* src/main.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-05-11 13:31:30 +00:00
parent b22e86a6eb
commit 3884d710d3
2 changed files with 20 additions and 27 deletions

View File

@ -1,3 +1,8 @@
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten AccRequestGroup
* src/main.cc
2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-05-11 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten. Rewritten.

View File

@ -200,14 +200,16 @@ int32_t downloadMetalink(Option* op)
class AccRequestGroup { class AccRequestGroup {
private: private:
std::deque<SharedHandle<RequestGroup> >& _requestGroups;
ProtocolDetector _detector; ProtocolDetector _detector;
Option* _op; Option* _op;
public: public:
AccRequestGroup(Option* op):_op(op) {} AccRequestGroup(std::deque<SharedHandle<RequestGroup> >& requestGroups,
Option* op):
_requestGroups(requestGroups), _op(op) {}
std::deque<SharedHandle<RequestGroup> >& void
operator()(std::deque<SharedHandle<RequestGroup> >& groups, operator()(const std::string& uri)
const std::string& uri)
{ {
if(_detector.isStreamProtocol(uri)) { if(_detector.isStreamProtocol(uri)) {
std::deque<std::string> xuris; std::deque<std::string> xuris;
@ -215,13 +217,13 @@ public:
xuris.push_back(uri); xuris.push_back(uri);
} }
RequestGroupHandle rg = createRequestGroup(_op, xuris); RequestGroupHandle rg = createRequestGroup(_op, xuris);
groups.push_back(rg); _requestGroups.push_back(rg);
} }
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
else if(_detector.guessTorrentFile(uri)) { else if(_detector.guessTorrentFile(uri)) {
try { try {
groups.push_back(createBtRequestGroup(uri, _op, _requestGroups.push_back(createBtRequestGroup(uri, _op,
std::deque<std::string>())); std::deque<std::string>()));
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
// error occurred while parsing torrent file. // error occurred while parsing torrent file.
// We simply ignore it. // We simply ignore it.
@ -234,7 +236,7 @@ public:
try { try {
std::deque<SharedHandle<RequestGroup> > metalinkGroups = std::deque<SharedHandle<RequestGroup> > metalinkGroups =
Metalink2RequestGroup(_op).generate(uri); Metalink2RequestGroup(_op).generate(uri);
groups.insert(groups.end(), metalinkGroups.begin(), metalinkGroups.end()); _requestGroups.insert(_requestGroups.end(), metalinkGroups.begin(), metalinkGroups.end());
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
// error occurred while parsing metalink file. // error occurred while parsing metalink file.
// We simply ignore it. // We simply ignore it.
@ -245,7 +247,6 @@ public:
else { else {
LogFactory::getInstance()->error(MSG_UNRECOGNIZED_URI, (uri).c_str()); LogFactory::getInstance()->error(MSG_UNRECOGNIZED_URI, (uri).c_str());
} }
return groups;
} }
}; };
@ -257,17 +258,10 @@ int32_t downloadUriList(Option* op, std::istream& in)
std::deque<std::string> uris = p.parseNext(in); std::deque<std::string> uris = p.parseNext(in);
if(uris.size() == 1 && op->get(PREF_PARAMETERIZED_URI) == V_TRUE) { if(uris.size() == 1 && op->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
std::deque<std::string> unfoldedURIs = unfoldURI(uris); std::deque<std::string> unfoldedURIs = unfoldURI(uris);
std::deque<SharedHandle<RequestGroup> > thisGroups = std::for_each(unfoldedURIs.begin(), unfoldedURIs.end(),
std::accumulate(unfoldedURIs.begin(), unfoldedURIs.end(), AccRequestGroup(groups, op));
std::deque<SharedHandle<RequestGroup> >(),
AccRequestGroup(op));
groups.insert(groups.end(), thisGroups.begin(), thisGroups.end());
} else if(uris.size() == 1) { } else if(uris.size() == 1) {
std::deque<SharedHandle<RequestGroup> > thisGroups = std::for_each(uris.begin(), uris.end(), AccRequestGroup(groups, op));
std::accumulate(uris.begin(), uris.end(),
std::deque<SharedHandle<RequestGroup> >(),
AccRequestGroup(op));
groups.insert(groups.end(), thisGroups.begin(), thisGroups.end());
} else if(uris.size() > 0) { } else if(uris.size() > 0) {
std::deque<std::string> xuris; std::deque<std::string> xuris;
ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT), ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT),
@ -313,9 +307,7 @@ int32_t downloadUri(Option* op, const std::deque<std::string>& uris)
} }
RequestGroups groups; RequestGroups groups;
if(op->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) { if(op->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
groups = std::accumulate(nargs.begin(), nargs.end(), std::for_each(nargs.begin(), nargs.end(), AccRequestGroup(groups, op));
std::deque<SharedHandle<RequestGroup> >(),
AccRequestGroup(op));
} else { } else {
std::deque<std::string>::iterator strmProtoEnd = std::deque<std::string>::iterator strmProtoEnd =
std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter()); std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
@ -328,11 +320,7 @@ int32_t downloadUri(Option* op, const std::deque<std::string>& uris)
groups.push_back(rg); groups.push_back(rg);
} }
// process remaining URIs(local metalink, BitTorrent files) // process remaining URIs(local metalink, BitTorrent files)
std::deque<SharedHandle<RequestGroup> > remGroups = std::for_each(strmProtoEnd, nargs.end(), AccRequestGroup(groups, op));
std::accumulate(strmProtoEnd, nargs.end(),
std::deque<SharedHandle<RequestGroup> >(),
AccRequestGroup(op));
groups.insert(groups.end(), remGroups.begin(), remGroups.end());
} }
return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute(); return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
} }