* DownloadEngine.{h, cc}:

* ConsoleDownloadEngine.{h, cc}: Console output message(size, 
speed)
	is now generated by ConsoleDownloadEngine not by DownloadEngine.
	* main.cc: Download complete/abort message is now generated by 
main.
pull/1/head
Tatsuhiro Tsujikawa 2006-03-02 02:54:49 +00:00
parent bea6e0e016
commit 0f6d2fd451
6 changed files with 65 additions and 40 deletions

View File

@ -2,6 +2,10 @@
* HttpConnection.cc: * HttpConnection.cc:
* common.h: defined the user agent name as macro * common.h: defined the user agent name as macro
* DownloadEngine.{h, cc}:
* ConsoleDownloadEngine.{h, cc}: Console output message(size, speed)
is now generated by ConsoleDownloadEngine not by DownloadEngine.
* main.cc: Download complete/abort message is now generated by main.
2006-03-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2006-03-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

View File

@ -38,9 +38,7 @@ DownloadEngine::~DownloadEngine() {
} }
void DownloadEngine::run() { void DownloadEngine::run() {
struct timeval cp = { 0, 0 }; initStatistics();
int speed = 0;
long long int psize = 0;
while(!commands.empty()) { while(!commands.empty()) {
int max = commands.size(); int max = commands.size();
for(int i = 0; i < max; i++) { for(int i = 0; i < max; i++) {
@ -54,7 +52,23 @@ void DownloadEngine::run() {
waitData(); waitData();
} }
noWait = false; noWait = false;
calculateStatistics();
}
diskWriter->closeFile();
if(segmentMan->finished()) {
segmentMan->remove();
} else {
segmentMan->save();
}
}
void DownloadEngine::initStatistics() {
cp.tv_sec = cp.tv_usec = 0;
speed = 0;
psize = 0;
}
void DownloadEngine::calculateStatistics() {
long long int dlSize = segmentMan->getDownloadedSize(); long long int dlSize = segmentMan->getDownloadedSize();
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
@ -68,35 +82,11 @@ void DownloadEngine::run() {
speed = (nspeed+speed)/2; speed = (nspeed+speed)/2;
cp = now; cp = now;
psize = dlSize; psize = dlSize;
cout << "\r "; sendStatistics(dlSize, segmentMan->totalSize);
cout << "\rProgress " << Util::llitos(dlSize, true) << " Bytes/" <<
Util::llitos(segmentMan->totalSize, true) << " Bytes " <<
(segmentMan->totalSize == 0 ? 0 : (dlSize*100)/segmentMan->totalSize) << "% " <<
speed/1000.0 << "KB/s " <<
"(" << commands.size() << " connections)" << flush;
} }
} }
}
diskWriter->closeFile();
if(segmentMan->finished()) {
segmentMan->remove();
cout << "\nThe download was complete. <" << segmentMan->getFilePath() << ">" << endl;
} else {
segmentMan->save();
cout << "\nThe download was not complete because of errors. Check the log." << endl;
}
} }
// void DownloadEngine::shortSleep() {
// int wait = rpm == 0 ? 0 : 4096*1000/rpm;
// struct timeval tv;
// int retval;
// tv.tv_sec = 0;
// tv.tv_usec = wait*1000;
// retval = select(0, NULL, NULL, NULL, &tv);
// }
void DownloadEngine::waitData() { void DownloadEngine::waitData() {
fd_set rfds; fd_set rfds;
fd_set wfds; fd_set wfds;

View File

@ -42,6 +42,13 @@ private:
bool addSocket(vector<Socket*>& sockets, Socket* socket); bool addSocket(vector<Socket*>& sockets, Socket* socket);
bool deleteSocket(vector<Socket*>& sockets, Socket* socket); bool deleteSocket(vector<Socket*>& sockets, Socket* socket);
struct timeval cp;
long long int psize;
void initStatistics();
void calculateStatistics();
protected:
int speed;
virtual void sendStatistics(long long int currentSize, long long int totalSize) {};
public: public:
bool noWait; bool noWait;
queue<Command*> commands; queue<Command*> commands;
@ -51,7 +58,7 @@ public:
const Option* option; const Option* option;
DownloadEngine(); DownloadEngine();
~DownloadEngine(); virtual ~DownloadEngine();
void run(); void run();

View File

@ -22,6 +22,7 @@ SRCS = Socket.cc Socket.h\
FtpTunnelResponseCommand.cc FtpTunnelResponseCommand.h\ FtpTunnelResponseCommand.cc FtpTunnelResponseCommand.h\
SleepCommand.cc SleepCommand.h\ SleepCommand.cc SleepCommand.h\
DownloadEngine.cc DownloadEngine.h\ DownloadEngine.cc DownloadEngine.h\
ConsoleDownloadEngine.cc ConsoleDownloadEngine.h\
Segment.h\ Segment.h\
SegmentMan.cc SegmentMan.h\ SegmentMan.cc SegmentMan.h\
SegmentSplitter.cc SegmentSplitter.h\ SegmentSplitter.cc SegmentSplitter.h\

View File

@ -71,6 +71,7 @@ am__objects_1 = libaria2c_a-Socket.$(OBJEXT) \
libaria2c_a-FtpTunnelResponseCommand.$(OBJEXT) \ libaria2c_a-FtpTunnelResponseCommand.$(OBJEXT) \
libaria2c_a-SleepCommand.$(OBJEXT) \ libaria2c_a-SleepCommand.$(OBJEXT) \
libaria2c_a-DownloadEngine.$(OBJEXT) \ libaria2c_a-DownloadEngine.$(OBJEXT) \
libaria2c_a-ConsoleDownloadEngine.$(OBJEXT) \
libaria2c_a-SegmentMan.$(OBJEXT) \ libaria2c_a-SegmentMan.$(OBJEXT) \
libaria2c_a-SegmentSplitter.$(OBJEXT) \ libaria2c_a-SegmentSplitter.$(OBJEXT) \
libaria2c_a-SplitFirstSegmentSplitter.$(OBJEXT) \ libaria2c_a-SplitFirstSegmentSplitter.$(OBJEXT) \
@ -212,6 +213,7 @@ SRCS = Socket.cc Socket.h\
FtpTunnelResponseCommand.cc FtpTunnelResponseCommand.h\ FtpTunnelResponseCommand.cc FtpTunnelResponseCommand.h\
SleepCommand.cc SleepCommand.h\ SleepCommand.cc SleepCommand.h\
DownloadEngine.cc DownloadEngine.h\ DownloadEngine.cc DownloadEngine.h\
ConsoleDownloadEngine.cc ConsoleDownloadEngine.h\
Segment.h\ Segment.h\
SegmentMan.cc SegmentMan.h\ SegmentMan.cc SegmentMan.h\
SegmentSplitter.cc SegmentSplitter.h\ SegmentSplitter.cc SegmentSplitter.h\
@ -320,6 +322,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-AbstractDiskWriter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-AbstractDiskWriter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Base64.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-Base64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-ChunkedEncoding.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-ChunkedEncoding.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-CookieBox.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-CookieBox.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-DefaultDiskWriter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-DefaultDiskWriter.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-DownloadCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libaria2c_a-DownloadCommand.Po@am__quote@
@ -660,6 +663,20 @@ libaria2c_a-DownloadEngine.obj: DownloadEngine.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-DownloadEngine.obj `if test -f 'DownloadEngine.cc'; then $(CYGPATH_W) 'DownloadEngine.cc'; else $(CYGPATH_W) '$(srcdir)/DownloadEngine.cc'; fi` @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-DownloadEngine.obj `if test -f 'DownloadEngine.cc'; then $(CYGPATH_W) 'DownloadEngine.cc'; else $(CYGPATH_W) '$(srcdir)/DownloadEngine.cc'; fi`
libaria2c_a-ConsoleDownloadEngine.o: ConsoleDownloadEngine.cc
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-ConsoleDownloadEngine.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo" -c -o libaria2c_a-ConsoleDownloadEngine.o `test -f 'ConsoleDownloadEngine.cc' || echo '$(srcdir)/'`ConsoleDownloadEngine.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo" "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Po"; else rm -f "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ConsoleDownloadEngine.cc' object='libaria2c_a-ConsoleDownloadEngine.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-ConsoleDownloadEngine.o `test -f 'ConsoleDownloadEngine.cc' || echo '$(srcdir)/'`ConsoleDownloadEngine.cc
libaria2c_a-ConsoleDownloadEngine.obj: ConsoleDownloadEngine.cc
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-ConsoleDownloadEngine.obj -MD -MP -MF "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo" -c -o libaria2c_a-ConsoleDownloadEngine.obj `if test -f 'ConsoleDownloadEngine.cc'; then $(CYGPATH_W) 'ConsoleDownloadEngine.cc'; else $(CYGPATH_W) '$(srcdir)/ConsoleDownloadEngine.cc'; fi`; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo" "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Po"; else rm -f "$(DEPDIR)/libaria2c_a-ConsoleDownloadEngine.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='ConsoleDownloadEngine.cc' object='libaria2c_a-ConsoleDownloadEngine.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -c -o libaria2c_a-ConsoleDownloadEngine.obj `if test -f 'ConsoleDownloadEngine.cc'; then $(CYGPATH_W) 'ConsoleDownloadEngine.cc'; else $(CYGPATH_W) '$(srcdir)/ConsoleDownloadEngine.cc'; fi`
libaria2c_a-SegmentMan.o: SegmentMan.cc libaria2c_a-SegmentMan.o: SegmentMan.cc
@am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SegmentMan.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo" -c -o libaria2c_a-SegmentMan.o `test -f 'SegmentMan.cc' || echo '$(srcdir)/'`SegmentMan.cc; \ @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libaria2c_a_CXXFLAGS) $(CXXFLAGS) -MT libaria2c_a-SegmentMan.o -MD -MP -MF "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo" -c -o libaria2c_a-SegmentMan.o `test -f 'SegmentMan.cc' || echo '$(srcdir)/'`SegmentMan.cc; \
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo" "$(DEPDIR)/libaria2c_a-SegmentMan.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo"; exit 1; fi @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo" "$(DEPDIR)/libaria2c_a-SegmentMan.Po"; else rm -f "$(DEPDIR)/libaria2c_a-SegmentMan.Tpo"; exit 1; fi

View File

@ -20,7 +20,7 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "HttpInitiateConnectionCommand.h" #include "HttpInitiateConnectionCommand.h"
#include "DownloadEngine.h" #include "ConsoleDownloadEngine.h"
#include "SegmentMan.h" #include "SegmentMan.h"
#include "SplitSlowestSegmentSplitter.h" #include "SplitSlowestSegmentSplitter.h"
#include "SimpleLogger.h" #include "SimpleLogger.h"
@ -411,7 +411,7 @@ int main(int argc, char* argv[]) {
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter(); SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE)); splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
splitter->logger = logger; splitter->logger = logger;
e = new DownloadEngine(); e = new ConsoleDownloadEngine();
e->logger = logger; e->logger = logger;
e->option = op; e->option = op;
e->diskWriter = new DefaultDiskWriter(); e->diskWriter = new DefaultDiskWriter();
@ -435,6 +435,12 @@ int main(int argc, char* argv[]) {
e->run(); e->run();
if(e->segmentMan->finished()) {
cout << "\nThe download was complete. <" << e->segmentMan->getFilePath() << ">" << endl;
} else {
cout << "\nThe download was not complete because of errors. Check the log." << endl;
}
for_each(requests.begin(), requests.end(), clearRequest); for_each(requests.begin(), requests.end(), clearRequest);
requests.clear(); requests.clear();
delete(logger); delete(logger);