Просмотр исходного кода

Set GID to RequestGroup.
Print GID in console readout.
Hide the part of log header when writing it to console

Tatsuhiro Tsujikawa 18 лет назад
Родитель
Сommit
cdbfde719e
6 измененных файлов с 36 добавлено и 10 удалено
  1. 5 2
      src/ConsoleDownloadEngine.cc
  2. 13 0
      src/RequestGroup.h
  3. 3 1
      src/RequestGroupMan.cc
  4. 4 2
      src/RequestGroupMan.h
  5. 10 4
      src/SimpleLogger.cc
  6. 1 1
      src/SimpleLogger.h

+ 5 - 2
src/ConsoleDownloadEngine.cc

@@ -61,8 +61,9 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
   cout << "\r";
   cout << "\r";
   if(_requestGroupMan->countRequestGroup() > 0) {
   if(_requestGroupMan->countRequestGroup() > 0) {
     RequestGroupHandle firstRequestGroup = _requestGroupMan->getRequestGroup(0);
     RequestGroupHandle firstRequestGroup = _requestGroupMan->getRequestGroup(0);
-    cout << "[";
-    cout << Util::abbrevSize(firstRequestGroup->getDownloadLength())
+    cout << "["
+	 << "#" << firstRequestGroup->getGID() << " "
+	 << Util::abbrevSize(firstRequestGroup->getDownloadLength())
 	 << "/"
 	 << "/"
 	 << Util::abbrevSize(firstRequestGroup->getTotalLength());
 	 << Util::abbrevSize(firstRequestGroup->getTotalLength());
     if(firstRequestGroup->getTotalLength() > 0) {
     if(firstRequestGroup->getTotalLength() > 0) {
@@ -86,6 +87,7 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
     FileAllocationEntryHandle entry = _fileAllocationMan->getCurrentFileAllocationEntry();
     FileAllocationEntryHandle entry = _fileAllocationMan->getCurrentFileAllocationEntry();
     if(!entry.isNull()) {
     if(!entry.isNull()) {
       cout << "[FileAlloc:"
       cout << "[FileAlloc:"
+	   << "#" << entry->getRequestGroup()->getGID() << " "
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << "/"
 	   << "/"
 	   << Util::abbrevSize(entry->getTotalLength())
 	   << Util::abbrevSize(entry->getTotalLength())
@@ -104,6 +106,7 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
     CheckIntegrityEntryHandle entry = _checkIntegrityMan->getFirstCheckIntegrityEntry();
     CheckIntegrityEntryHandle entry = _checkIntegrityMan->getFirstCheckIntegrityEntry();
     if(!entry.isNull()) {
     if(!entry.isNull()) {
       cout << "[Checksum:"
       cout << "[Checksum:"
+	   << "#" << entry->getRequestGroup()->getGID() << " "
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << "/"
 	   << "/"
 	   << Util::abbrevSize(entry->getTotalLength())
 	   << Util::abbrevSize(entry->getTotalLength())

+ 13 - 0
src/RequestGroup.h

@@ -50,6 +50,7 @@ class DownloadEngine;
 
 
 class RequestGroup {
 class RequestGroup {
 private:
 private:
+  int32_t _gid;
   int64_t _hintTotalLength;
   int64_t _hintTotalLength;
   string _hintFilename;
   string _hintFilename;
   string _ufilename;
   string _ufilename;
@@ -76,6 +77,7 @@ public:
   bool isTorrent;
   bool isTorrent;
 
 
   RequestGroup(const Strings& uris, const Option* option):
   RequestGroup(const Strings& uris, const Option* option):
+    _gid(0),
     _hintTotalLength(0),
     _hintTotalLength(0),
     _uris(uris),
     _uris(uris),
     _segmentMan(0),
     _segmentMan(0),
@@ -89,6 +91,7 @@ public:
     isTorrent(false) {}
     isTorrent(false) {}
 
 
   RequestGroup(const string& uri, const Option* option):
   RequestGroup(const string& uri, const Option* option):
+    _gid(0),
     _hintTotalLength(0),
     _hintTotalLength(0),
     _segmentMan(0),
     _segmentMan(0),
     _segmentManFactory(new DefaultSegmentManFactory(option)),
     _segmentManFactory(new DefaultSegmentManFactory(option)),
@@ -275,6 +278,16 @@ public:
   }
   }
 
 
   void setUserDefinedFilename(const string& filename);
   void setUserDefinedFilename(const string& filename);
+
+  void setGID(int32_t gid)
+  {
+    _gid = gid;
+  }
+
+  int32_t getGID() const
+  {
+    return _gid;
+  }
 };
 };
 
 
 typedef SharedHandle<RequestGroup> RequestGroupHandle;
 typedef SharedHandle<RequestGroup> RequestGroupHandle;

+ 3 - 1
src/RequestGroupMan.cc

@@ -74,6 +74,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
     
     
     _requestGroups.push_back(groupToAdd);
     _requestGroups.push_back(groupToAdd);
     groupToAdd->initSegmentMan();
     groupToAdd->initSegmentMan();
+    groupToAdd->setGID(++_gidCounter);
     Commands commands = groupToAdd->createNextCommand(e, 1);
     Commands commands = groupToAdd->createNextCommand(e, 1);
     count += commands.size();
     count += commands.size();
     e->addCommand(commands);
     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;
   Commands commands;
   for(RequestGroups::const_iterator itr = _requestGroups.begin();
   for(RequestGroups::const_iterator itr = _requestGroups.begin();
 	itr != _requestGroups.end(); ++itr) {
 	itr != _requestGroups.end(); ++itr) {
     (*itr)->initSegmentMan();
     (*itr)->initSegmentMan();
+    (*itr)->setGID(++_gidCounter);
     commands.push_back((*itr)->createNextCommand(e, 1).front());
     commands.push_back((*itr)->createNextCommand(e, 1).front());
   }
   }
   return commands;
   return commands;

+ 4 - 2
src/RequestGroupMan.h

@@ -47,11 +47,13 @@ private:
   RequestGroups _reservedGroups;
   RequestGroups _reservedGroups;
   const Logger* _logger;
   const Logger* _logger;
   int32_t _maxSimultaneousDownloads;
   int32_t _maxSimultaneousDownloads;
+  int32_t _gidCounter;
 public:
 public:
   RequestGroupMan(const RequestGroups& requestGroups = RequestGroups(), int32_t maxSimultaneousDownloads = 1):
   RequestGroupMan(const RequestGroups& requestGroups = RequestGroups(), int32_t maxSimultaneousDownloads = 1):
     _requestGroups(requestGroups),
     _requestGroups(requestGroups),
     _logger(LogFactory::getInstance()),
     _logger(LogFactory::getInstance()),
-    _maxSimultaneousDownloads(maxSimultaneousDownloads) {}
+    _maxSimultaneousDownloads(maxSimultaneousDownloads),
+    _gidCounter(0) {}
 
 
   bool downloadFinished()
   bool downloadFinished()
   {
   {
@@ -102,7 +104,7 @@ public:
     return totalLength;
     return totalLength;
   }
   }
 
 
-  Commands getInitialCommands(DownloadEngine* e) const;
+  Commands getInitialCommands(DownloadEngine* e);
 
 
   void removeStoppedGroup();
   void removeStoppedGroup();
 
 

+ 10 - 4
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());
   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;
   string levelStr;
   switch(level) {
   switch(level) {
@@ -108,10 +108,16 @@ void SimpleLogger::writeLog(FILE* file, int level, const char* msg, va_list ap,
   char datestr[26];
   char datestr[26];
   ctime_r(&now, datestr);
   ctime_r(&now, datestr);
   datestr[strlen(datestr)-1] = '\0';
   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);
   vfprintf(file, string(Util::replace(msg, "\r", "")+"\n").c_str(), ap);
   for(Exception* nestedEx = e; nestedEx; nestedEx = nestedEx->getCause()) {
   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());
     fprintf(file, "exception: %s\n", Util::replace(nestedEx->getMsg(), "\r", "").c_str());
   }
   }
   fflush(file);
   fflush(file);
@@ -121,7 +127,7 @@ void SimpleLogger::writeFile(int level, const char* msg, va_list ap, Exception*
   writeLog(file, level, msg, ap, e);
   writeLog(file, level, msg, ap, e);
   if(stdoutField&level) {
   if(stdoutField&level) {
     fprintf(stdout, "\n");
     fprintf(stdout, "\n");
-    writeLog(stdout, level, msg, ap, e);
+    writeLog(stdout, level, msg, ap, e, false);
   }
   }
 }
 }
 
 

+ 1 - 1
src/SimpleLogger.h

@@ -41,7 +41,7 @@ class SimpleLogger:public Logger {
 private:
 private:
   void writeFile(int level, const char* msg, va_list ap, Exception* e = 0) const;
   void writeFile(int level, const char* msg, va_list ap, Exception* e = 0) const;
   void writeHeader(FILE* file, string date, string level) 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;
   FILE* file;
   int stdoutField;
   int stdoutField;
 public:
 public: