Set GID to RequestGroup.

Print GID in console readout.
Hide the part of log header when writing it to console
pull/1/head
Tatsuhiro Tsujikawa 2007-06-10 15:22:36 +00:00
parent 0db7f62553
commit cdbfde719e
6 changed files with 36 additions and 10 deletions

View File

@ -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())

View File

@ -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<RequestGroup> RequestGroupHandle;

View File

@ -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;

View File

@ -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();

View File

@ -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);
}
}

View File

@ -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: