From cdbfde719e11e2ed71593a8827c86d848c9fe944 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 10 Jun 2007 15:22:36 +0000 Subject: [PATCH] Set GID to RequestGroup. Print GID in console readout. Hide the part of log header when writing it to console --- src/ConsoleDownloadEngine.cc | 7 +++++-- src/RequestGroup.h | 13 +++++++++++++ src/RequestGroupMan.cc | 4 +++- src/RequestGroupMan.h | 6 ++++-- src/SimpleLogger.cc | 14 ++++++++++---- src/SimpleLogger.h | 2 +- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/ConsoleDownloadEngine.cc b/src/ConsoleDownloadEngine.cc index a4f7aff5..8be480a1 100644 --- a/src/ConsoleDownloadEngine.cc +++ b/src/ConsoleDownloadEngine.cc @@ -61,8 +61,9 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long cout << "\r"; if(_requestGroupMan->countRequestGroup() > 0) { RequestGroupHandle firstRequestGroup = _requestGroupMan->getRequestGroup(0); - cout << "["; - cout << Util::abbrevSize(firstRequestGroup->getDownloadLength()) + cout << "[" + << "#" << firstRequestGroup->getGID() << " " + << Util::abbrevSize(firstRequestGroup->getDownloadLength()) << "/" << Util::abbrevSize(firstRequestGroup->getTotalLength()); if(firstRequestGroup->getTotalLength() > 0) { @@ -86,6 +87,7 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long FileAllocationEntryHandle entry = _fileAllocationMan->getCurrentFileAllocationEntry(); if(!entry.isNull()) { cout << "[FileAlloc:" + << "#" << entry->getRequestGroup()->getGID() << " " << Util::abbrevSize(entry->getCurrentLength()) << "/" << Util::abbrevSize(entry->getTotalLength()) @@ -104,6 +106,7 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long CheckIntegrityEntryHandle entry = _checkIntegrityMan->getFirstCheckIntegrityEntry(); if(!entry.isNull()) { cout << "[Checksum:" + << "#" << entry->getRequestGroup()->getGID() << " " << Util::abbrevSize(entry->getCurrentLength()) << "/" << Util::abbrevSize(entry->getTotalLength()) diff --git a/src/RequestGroup.h b/src/RequestGroup.h index b4c7df21..930b1d07 100644 --- a/src/RequestGroup.h +++ b/src/RequestGroup.h @@ -50,6 +50,7 @@ class DownloadEngine; class RequestGroup { private: + int32_t _gid; int64_t _hintTotalLength; string _hintFilename; string _ufilename; @@ -76,6 +77,7 @@ public: bool isTorrent; RequestGroup(const Strings& uris, const Option* option): + _gid(0), _hintTotalLength(0), _uris(uris), _segmentMan(0), @@ -89,6 +91,7 @@ public: isTorrent(false) {} RequestGroup(const string& uri, const Option* option): + _gid(0), _hintTotalLength(0), _segmentMan(0), _segmentManFactory(new DefaultSegmentManFactory(option)), @@ -275,6 +278,16 @@ public: } void setUserDefinedFilename(const string& filename); + + void setGID(int32_t gid) + { + _gid = gid; + } + + int32_t getGID() const + { + return _gid; + } }; typedef SharedHandle RequestGroupHandle; diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc index 06861a12..735e1792 100644 --- a/src/RequestGroupMan.cc +++ b/src/RequestGroupMan.cc @@ -74,6 +74,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) _requestGroups.push_back(groupToAdd); groupToAdd->initSegmentMan(); + groupToAdd->setGID(++_gidCounter); Commands commands = groupToAdd->createNextCommand(e, 1); count += commands.size(); e->addCommand(commands); @@ -83,12 +84,13 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e) } } -Commands RequestGroupMan::getInitialCommands(DownloadEngine* e) const +Commands RequestGroupMan::getInitialCommands(DownloadEngine* e) { Commands commands; for(RequestGroups::const_iterator itr = _requestGroups.begin(); itr != _requestGroups.end(); ++itr) { (*itr)->initSegmentMan(); + (*itr)->setGID(++_gidCounter); commands.push_back((*itr)->createNextCommand(e, 1).front()); } return commands; diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h index 3d2058b2..a78de75e 100644 --- a/src/RequestGroupMan.h +++ b/src/RequestGroupMan.h @@ -47,11 +47,13 @@ private: RequestGroups _reservedGroups; const Logger* _logger; int32_t _maxSimultaneousDownloads; + int32_t _gidCounter; public: RequestGroupMan(const RequestGroups& requestGroups = RequestGroups(), int32_t maxSimultaneousDownloads = 1): _requestGroups(requestGroups), _logger(LogFactory::getInstance()), - _maxSimultaneousDownloads(maxSimultaneousDownloads) {} + _maxSimultaneousDownloads(maxSimultaneousDownloads), + _gidCounter(0) {} bool downloadFinished() { @@ -102,7 +104,7 @@ public: return totalLength; } - Commands getInitialCommands(DownloadEngine* e) const; + Commands getInitialCommands(DownloadEngine* e); void removeStoppedGroup(); diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc index 634a6d6a..53d7e6de 100644 --- a/src/SimpleLogger.cc +++ b/src/SimpleLogger.cc @@ -84,7 +84,7 @@ void SimpleLogger::writeHeader(FILE* file, string date, string level) const { fprintf(file, "%s - %s - ", date.c_str(), level.c_str()); } -void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e) const +void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e, bool printHeader) const { string levelStr; switch(level) { @@ -108,10 +108,16 @@ void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap, char datestr[26]; ctime_r(&now, datestr); datestr[strlen(datestr)-1] = '\0'; - writeHeader(file, datestr, levelStr); + // TODO a quick hack not to print header in console + if(printHeader) { + writeHeader(file, datestr, levelStr); + } vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), ap); for(Exception* nestedEx = e; nestedEx; nestedEx = nestedEx->getCause()) { - writeHeader(file, datestr, levelStr); + // TODO a quick hack not to print header in console + if(printHeader) { + writeHeader(file, datestr, levelStr); + } fprintf(file, "exception: %s\n", Util::replace(nestedEx->getMsg(), "\r", "").c_str()); } fflush(file); @@ -121,7 +127,7 @@ void SimpleLogger::writeFile(int level, const char* msg, va_list ap, Exception* writeLog(file, level, msg, ap, e); if(stdoutField&level) { fprintf(stdout, "\n"); - writeLog(stdout, level, msg, ap, e); + writeLog(stdout, level, msg, ap, e, false); } } diff --git a/src/SimpleLogger.h b/src/SimpleLogger.h index 93ffea42..ec780d83 100644 --- a/src/SimpleLogger.h +++ b/src/SimpleLogger.h @@ -41,7 +41,7 @@ class SimpleLogger:public Logger { private: void writeFile(int level, const char* msg, va_list ap, Exception* e = 0) const; void writeHeader(FILE* file, string date, string level) const; - void writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e = 0) const; + void writeLog(FILE* file, int level, const char* msg, va_list ap, Exception* e = 0, bool printHeader = false) const; FILE* file; int stdoutField; public: