mirror of https://github.com/aria2/aria2
Refactor MultiUrlRequestInfo ctor
StatCalc creation is moved to MultiUrlRequestInfo. The summary output is done only when PREF_QUIET is false and it is always to global::cout(), so remove summaryOut_ and just use global::cout() in that case. Also use std::unique_ptr for statCalc_ in DownloadEngine.pull/106/head
parent
162c138362
commit
f83b0fcfa3
|
@ -57,8 +57,6 @@
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "ConsoleStatCalc.h"
|
|
||||||
#include "NullStatCalc.h"
|
|
||||||
#include "download_helper.h"
|
#include "download_helper.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "ProtocolDetector.h"
|
#include "ProtocolDetector.h"
|
||||||
|
@ -66,7 +64,6 @@
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "NullOutputFile.h"
|
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "UriListParser.h"
|
#include "UriListParser.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
@ -85,31 +82,6 @@ extern int optind, opterr, optopt;
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
std::shared_ptr<StatCalc> getStatCalc(const std::shared_ptr<Option>& op)
|
|
||||||
{
|
|
||||||
std::shared_ptr<StatCalc> statCalc;
|
|
||||||
if(op->getAsBool(PREF_QUIET)) {
|
|
||||||
statCalc.reset(new NullStatCalc());
|
|
||||||
} else {
|
|
||||||
std::shared_ptr<ConsoleStatCalc> impl
|
|
||||||
(new ConsoleStatCalc(op->getAsInt(PREF_SUMMARY_INTERVAL),
|
|
||||||
op->getAsBool(PREF_HUMAN_READABLE)));
|
|
||||||
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
|
|
||||||
impl->setTruncate(op->getAsBool(PREF_TRUNCATE_CONSOLE_READOUT));
|
|
||||||
statCalc = impl;
|
|
||||||
}
|
|
||||||
return statCalc;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<OutputFile> getSummaryOut(const std::shared_ptr<Option>& op)
|
|
||||||
{
|
|
||||||
if(op->getAsBool(PREF_QUIET)) {
|
|
||||||
return std::shared_ptr<OutputFile>(new NullOutputFile());
|
|
||||||
} else {
|
|
||||||
return global::cout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
namespace {
|
namespace {
|
||||||
void showTorrentFile(const std::string& uri)
|
void showTorrentFile(const std::string& uri)
|
||||||
|
@ -281,8 +253,7 @@ Context::Context(bool standalone,
|
||||||
global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);
|
global::cout()->printf("%s\n", MSG_NO_FILES_TO_DOWNLOAD);
|
||||||
} else {
|
} else {
|
||||||
reqinfo.reset(new MultiUrlRequestInfo(std::move(requestGroups),
|
reqinfo.reset(new MultiUrlRequestInfo(std::move(requestGroups),
|
||||||
op, getStatCalc(op),
|
op,
|
||||||
getSummaryOut(op),
|
|
||||||
uriListParser));
|
uriListParser));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,9 +251,9 @@ void DownloadEngine::requestForceHalt()
|
||||||
requestGroupMan_->forceHalt();
|
requestGroupMan_->forceHalt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadEngine::setStatCalc(const std::shared_ptr<StatCalc>& statCalc)
|
void DownloadEngine::setStatCalc(std::unique_ptr<StatCalc> statCalc)
|
||||||
{
|
{
|
||||||
statCalc_ = statCalc;
|
statCalc_ = std::move(statCalc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
|
|
|
@ -82,7 +82,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<EventPoll> eventPoll_;
|
std::shared_ptr<EventPoll> eventPoll_;
|
||||||
|
|
||||||
std::shared_ptr<StatCalc> statCalc_;
|
std::unique_ptr<StatCalc> statCalc_;
|
||||||
|
|
||||||
int haltRequested_;
|
int haltRequested_;
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ public:
|
||||||
option_ = op;
|
option_ = op;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStatCalc(const std::shared_ptr<StatCalc>& statCalc);
|
void setStatCalc(std::unique_ptr<StatCalc> statCalc);
|
||||||
|
|
||||||
bool isHaltRequested() const
|
bool isHaltRequested() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -50,7 +50,8 @@
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "StatCalc.h"
|
#include "ConsoleStatCalc.h"
|
||||||
|
#include "NullStatCalc.h"
|
||||||
#include "CookieStorage.h"
|
#include "CookieStorage.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Netrc.h"
|
#include "Netrc.h"
|
||||||
|
@ -59,10 +60,11 @@
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
#include "OutputFile.h"
|
#include "NullOutputFile.h"
|
||||||
#include "UriListParser.h"
|
#include "UriListParser.h"
|
||||||
#include "SingletonHolder.h"
|
#include "SingletonHolder.h"
|
||||||
#include "Notifier.h"
|
#include "Notifier.h"
|
||||||
|
#include "console.h"
|
||||||
#ifdef ENABLE_WEBSOCKET
|
#ifdef ENABLE_WEBSOCKET
|
||||||
# include "WebSocketSessionMan.h"
|
# include "WebSocketSessionMan.h"
|
||||||
#else // !ENABLE_WEBSOCKET
|
#else // !ENABLE_WEBSOCKET
|
||||||
|
@ -103,16 +105,30 @@ void handler(int signal) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
std::unique_ptr<StatCalc> getStatCalc(const std::shared_ptr<Option>& op)
|
||||||
|
{
|
||||||
|
if(op->getAsBool(PREF_QUIET)) {
|
||||||
|
return make_unique<NullStatCalc>();
|
||||||
|
} else {
|
||||||
|
auto impl = make_unique<ConsoleStatCalc>
|
||||||
|
(op->getAsInt(PREF_SUMMARY_INTERVAL),
|
||||||
|
op->getAsBool(PREF_HUMAN_READABLE));
|
||||||
|
impl->setReadoutVisibility(op->getAsBool(PREF_SHOW_CONSOLE_READOUT));
|
||||||
|
impl->setTruncate(op->getAsBool(PREF_TRUNCATE_CONSOLE_READOUT));
|
||||||
|
return std::move(impl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
MultiUrlRequestInfo::MultiUrlRequestInfo
|
MultiUrlRequestInfo::MultiUrlRequestInfo
|
||||||
(std::vector<std::shared_ptr<RequestGroup> > requestGroups,
|
(std::vector<std::shared_ptr<RequestGroup> > requestGroups,
|
||||||
const std::shared_ptr<Option>& op,
|
const std::shared_ptr<Option>& op,
|
||||||
const std::shared_ptr<StatCalc>& statCalc,
|
|
||||||
const std::shared_ptr<OutputFile>& summaryOut,
|
|
||||||
const std::shared_ptr<UriListParser>& uriListParser)
|
const std::shared_ptr<UriListParser>& uriListParser)
|
||||||
: requestGroups_(std::move(requestGroups)),
|
: requestGroups_(std::move(requestGroups)),
|
||||||
option_(op),
|
option_(op),
|
||||||
statCalc_(statCalc),
|
|
||||||
summaryOut_(summaryOut),
|
|
||||||
uriListParser_(uriListParser),
|
uriListParser_(uriListParser),
|
||||||
useSignalHandler_(true)
|
useSignalHandler_(true)
|
||||||
{
|
{
|
||||||
|
@ -127,10 +143,12 @@ MultiUrlRequestInfo::~MultiUrlRequestInfo() {}
|
||||||
|
|
||||||
void MultiUrlRequestInfo::printMessageForContinue()
|
void MultiUrlRequestInfo::printMessageForContinue()
|
||||||
{
|
{
|
||||||
summaryOut_->printf
|
if(!option_->getAsBool(PREF_QUIET)) {
|
||||||
("\n%s\n%s\n",
|
global::cout()->printf
|
||||||
_("aria2 will resume download if the transfer is restarted."),
|
("\n%s\n%s\n",
|
||||||
_("If there are any errors, then see the log file. See '-l' option in help/man page for details."));
|
_("aria2 will resume download if the transfer is restarted."),
|
||||||
|
_("If there are any errors, then see the log file. See '-l' option in help/man page for details."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultiUrlRequestInfo::prepare()
|
int MultiUrlRequestInfo::prepare()
|
||||||
|
@ -242,7 +260,7 @@ int MultiUrlRequestInfo::prepare()
|
||||||
e_->getRequestGroupMan()->removeStaleServerStat
|
e_->getRequestGroupMan()->removeStaleServerStat
|
||||||
(option_->getAsInt(PREF_SERVER_STAT_TIMEOUT));
|
(option_->getAsInt(PREF_SERVER_STAT_TIMEOUT));
|
||||||
}
|
}
|
||||||
e_->setStatCalc(statCalc_);
|
e_->setStatCalc(getStatCalc(option_));
|
||||||
if(uriListParser_) {
|
if(uriListParser_) {
|
||||||
e_->getRequestGroupMan()->setUriListParser(uriListParser_);
|
e_->getRequestGroupMan()->setUriListParser(uriListParser_);
|
||||||
}
|
}
|
||||||
|
@ -271,9 +289,11 @@ error_code::Value MultiUrlRequestInfo::getResult()
|
||||||
if(!serverStatOf.empty()) {
|
if(!serverStatOf.empty()) {
|
||||||
e_->getRequestGroupMan()->saveServerStat(serverStatOf);
|
e_->getRequestGroupMan()->saveServerStat(serverStatOf);
|
||||||
}
|
}
|
||||||
e_->getRequestGroupMan()->showDownloadResults
|
if(!option_->getAsBool(PREF_QUIET)) {
|
||||||
(*summaryOut_, option_->get(PREF_DOWNLOAD_RESULT) == A2_V_FULL);
|
e_->getRequestGroupMan()->showDownloadResults
|
||||||
summaryOut_->flush();
|
(*global::cout(), option_->get(PREF_DOWNLOAD_RESULT) == A2_V_FULL);
|
||||||
|
global::cout()->flush();
|
||||||
|
}
|
||||||
|
|
||||||
RequestGroupMan::DownloadStat s =
|
RequestGroupMan::DownloadStat s =
|
||||||
e_->getRequestGroupMan()->getDownloadStat();
|
e_->getRequestGroupMan()->getDownloadStat();
|
||||||
|
|
|
@ -49,8 +49,6 @@ namespace aria2 {
|
||||||
|
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
class Option;
|
class Option;
|
||||||
class StatCalc;
|
|
||||||
class OutputFile;
|
|
||||||
class UriListParser;
|
class UriListParser;
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
|
|
||||||
|
@ -60,10 +58,6 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<Option> option_;
|
std::shared_ptr<Option> option_;
|
||||||
|
|
||||||
std::shared_ptr<StatCalc> statCalc_;
|
|
||||||
|
|
||||||
std::shared_ptr<OutputFile> summaryOut_;
|
|
||||||
|
|
||||||
std::shared_ptr<UriListParser> uriListParser_;
|
std::shared_ptr<UriListParser> uriListParser_;
|
||||||
|
|
||||||
std::shared_ptr<DownloadEngine> e_;
|
std::shared_ptr<DownloadEngine> e_;
|
||||||
|
@ -83,8 +77,6 @@ public:
|
||||||
MultiUrlRequestInfo
|
MultiUrlRequestInfo
|
||||||
(std::vector<std::shared_ptr<RequestGroup> > requestGroups,
|
(std::vector<std::shared_ptr<RequestGroup> > requestGroups,
|
||||||
const std::shared_ptr<Option>& op,
|
const std::shared_ptr<Option>& op,
|
||||||
const std::shared_ptr<StatCalc>& statCalc,
|
|
||||||
const std::shared_ptr<OutputFile>& summaryOut,
|
|
||||||
const std::shared_ptr<UriListParser>& uriListParser);
|
const std::shared_ptr<UriListParser>& uriListParser);
|
||||||
|
|
||||||
~MultiUrlRequestInfo();
|
~MultiUrlRequestInfo();
|
||||||
|
|
Loading…
Reference in New Issue