mirror of https://github.com/aria2/aria2
				
				
				
			2010-06-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs. * src/AutoSaveCommand.cc * src/BtStopDownloadCommand.cc * src/DHTAutoSaveCommand.cc * src/DHTBucketRefreshCommand.cc * src/DHTPeerAnnounceCommand.cc * src/DHTTokenUpdateCommand.cc * src/HaveEraseCommand.cc * src/TimeBasedCommand.h * src/TimedHaltCommand.ccpull/1/head
							parent
							
								
									43460a347f
								
							
						
					
					
						commit
						b357fd39fc
					
				
							
								
								
									
										13
									
								
								ChangeLog
								
								
								
								
							
							
						
						
									
										13
									
								
								ChangeLog
								
								
								
								
							| 
						 | 
				
			
			@ -1,3 +1,16 @@
 | 
			
		|||
2010-06-09  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
			
		||||
 | 
			
		||||
	Made protected member variable private. Added accessor funcs.
 | 
			
		||||
	* src/AutoSaveCommand.cc
 | 
			
		||||
	* src/BtStopDownloadCommand.cc
 | 
			
		||||
	* src/DHTAutoSaveCommand.cc
 | 
			
		||||
	* src/DHTBucketRefreshCommand.cc
 | 
			
		||||
	* src/DHTPeerAnnounceCommand.cc
 | 
			
		||||
	* src/DHTTokenUpdateCommand.cc
 | 
			
		||||
	* src/HaveEraseCommand.cc
 | 
			
		||||
	* src/TimeBasedCommand.h
 | 
			
		||||
	* src/TimedHaltCommand.cc
 | 
			
		||||
 | 
			
		||||
2010-06-09  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 | 
			
		||||
 | 
			
		||||
	Made protected member variable private. Added accessor funcs.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,14 +49,15 @@ AutoSaveCommand::~AutoSaveCommand() {}
 | 
			
		|||
 | 
			
		||||
void AutoSaveCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  if(_e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested()) {
 | 
			
		||||
    _exit = true;
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AutoSaveCommand::process()
 | 
			
		||||
{
 | 
			
		||||
  _e->getRequestGroupMan()->save();
 | 
			
		||||
  getDownloadEngine()->getRequestGroupMan()->save();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace aria2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -57,14 +57,14 @@ BtStopDownloadCommand::BtStopDownloadCommand
 | 
			
		|||
void BtStopDownloadCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  if(_btRuntime->isHalt() || _pieceStorage->downloadFinished()) {
 | 
			
		||||
    _exit = true;
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
  if(_checkPoint.difference(global::wallclock) >= _timeout) {
 | 
			
		||||
    getLogger()->notice("GID#%s Stop downloading torrent due to"
 | 
			
		||||
                        " --bt-stop-timeout option.",
 | 
			
		||||
                        util::itos(_requestGroup->getGID()).c_str());
 | 
			
		||||
    _requestGroup->setHaltRequested(true);
 | 
			
		||||
    _exit = true;
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,16 +61,18 @@
 | 
			
		|||
 | 
			
		||||
namespace aria2 {
 | 
			
		||||
 | 
			
		||||
DHTAutoSaveCommand::DHTAutoSaveCommand(cuid_t cuid, DownloadEngine* e, time_t interval):
 | 
			
		||||
DHTAutoSaveCommand::DHTAutoSaveCommand
 | 
			
		||||
(cuid_t cuid, DownloadEngine* e, time_t interval):
 | 
			
		||||
  TimeBasedCommand(cuid, e, interval) {}
 | 
			
		||||
 | 
			
		||||
DHTAutoSaveCommand::~DHTAutoSaveCommand() {}
 | 
			
		||||
 | 
			
		||||
void DHTAutoSaveCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  if(_e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested()) {
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    save();
 | 
			
		||||
    _exit = true;
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -81,7 +83,8 @@ void DHTAutoSaveCommand::process()
 | 
			
		|||
 | 
			
		||||
void DHTAutoSaveCommand::save()
 | 
			
		||||
{
 | 
			
		||||
  std::string dhtFile = _e->getOption()->get(PREF_DHT_FILE_PATH);
 | 
			
		||||
  std::string dhtFile =
 | 
			
		||||
    getDownloadEngine()->getOption()->get(PREF_DHT_FILE_PATH);
 | 
			
		||||
  getLogger()->info("Saving DHT routing table to %s.", dhtFile.c_str());
 | 
			
		||||
 | 
			
		||||
  std::string tempFile = dhtFile;
 | 
			
		||||
| 
						 | 
				
			
			@ -142,7 +145,8 @@ void DHTAutoSaveCommand::setLocalNode(const SharedHandle<DHTNode>& localNode)
 | 
			
		|||
  _localNode = localNode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTAutoSaveCommand::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
 | 
			
		||||
void DHTAutoSaveCommand::setRoutingTable
 | 
			
		||||
(const SharedHandle<DHTRoutingTable>& routingTable)
 | 
			
		||||
{
 | 
			
		||||
  _routingTable = routingTable;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,10 @@ DHTBucketRefreshCommand::~DHTBucketRefreshCommand() {}
 | 
			
		|||
 | 
			
		||||
void DHTBucketRefreshCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  _exit = _e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested();
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTBucketRefreshCommand::process()
 | 
			
		||||
| 
						 | 
				
			
			@ -62,17 +65,20 @@ void DHTBucketRefreshCommand::process()
 | 
			
		|||
  _taskQueue->addPeriodicTask1(_taskFactory->createBucketRefreshTask());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTBucketRefreshCommand::setRoutingTable(const SharedHandle<DHTRoutingTable>& routingTable)
 | 
			
		||||
void DHTBucketRefreshCommand::setRoutingTable
 | 
			
		||||
(const SharedHandle<DHTRoutingTable>& routingTable)
 | 
			
		||||
{
 | 
			
		||||
  _routingTable = routingTable;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTBucketRefreshCommand::setTaskQueue(const SharedHandle<DHTTaskQueue>& taskQueue)
 | 
			
		||||
void DHTBucketRefreshCommand::setTaskQueue
 | 
			
		||||
(const SharedHandle<DHTTaskQueue>& taskQueue)
 | 
			
		||||
{
 | 
			
		||||
  _taskQueue = taskQueue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTBucketRefreshCommand::setTaskFactory(const SharedHandle<DHTTaskFactory>& taskFactory)
 | 
			
		||||
void DHTBucketRefreshCommand::setTaskFactory
 | 
			
		||||
(const SharedHandle<DHTTaskFactory>& taskFactory)
 | 
			
		||||
{
 | 
			
		||||
  _taskFactory = taskFactory;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,10 @@ DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}
 | 
			
		|||
 | 
			
		||||
void DHTPeerAnnounceCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  _exit = _e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested();
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTPeerAnnounceCommand::process()
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +69,8 @@ void DHTPeerAnnounceCommand::process()
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTPeerAnnounceCommand::setPeerAnnounceStorage(const SharedHandle<DHTPeerAnnounceStorage>& storage)
 | 
			
		||||
void DHTPeerAnnounceCommand::setPeerAnnounceStorage
 | 
			
		||||
(const SharedHandle<DHTPeerAnnounceStorage>& storage)
 | 
			
		||||
{
 | 
			
		||||
  _peerAnnounceStorage = storage;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,7 +55,10 @@ DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}
 | 
			
		|||
 | 
			
		||||
void DHTTokenUpdateCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  _exit = _e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested();
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DHTTokenUpdateCommand::process()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,17 +51,20 @@ HaveEraseCommand::~HaveEraseCommand() {}
 | 
			
		|||
 | 
			
		||||
void HaveEraseCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  if(_e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested()) {
 | 
			
		||||
    _exit = true;
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HaveEraseCommand::process()
 | 
			
		||||
{
 | 
			
		||||
  size_t numLoop = _e->getRequestGroupMan()->countRequestGroup();
 | 
			
		||||
  size_t numLoop =
 | 
			
		||||
    getDownloadEngine()->getRequestGroupMan()->countRequestGroup();
 | 
			
		||||
  for(size_t i = 0; i < numLoop; ++i) {
 | 
			
		||||
    PieceStorageHandle ps =
 | 
			
		||||
      _e->getRequestGroupMan()->getRequestGroup(i)->getPieceStorage();
 | 
			
		||||
      getDownloadEngine()->getRequestGroupMan()->getRequestGroup(i)->
 | 
			
		||||
      getPieceStorage();
 | 
			
		||||
    if(!ps.isNull()) {
 | 
			
		||||
      ps->removeAdvertisedPiece(5);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,7 @@ class DownloadEngine;
 | 
			
		|||
 | 
			
		||||
class TimeBasedCommand : public Command
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
private:
 | 
			
		||||
  DownloadEngine* _e;
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			@ -59,8 +59,23 @@ protected:
 | 
			
		|||
  time_t _interval; // unit: sec
 | 
			
		||||
 | 
			
		||||
  bool _routineCommand;
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
  Timer _checkPoint;
 | 
			
		||||
protected:
 | 
			
		||||
  DownloadEngine* getDownloadEngine() const
 | 
			
		||||
  {
 | 
			
		||||
    return _e;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void enableExit()
 | 
			
		||||
  {
 | 
			
		||||
    _exit = true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  time_t getInterval() const
 | 
			
		||||
  {
 | 
			
		||||
    return _interval;
 | 
			
		||||
  }
 | 
			
		||||
public:
 | 
			
		||||
  /**
 | 
			
		||||
   * preProcess() is called each time when excute() is called.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,22 +54,23 @@ TimedHaltCommand::~TimedHaltCommand() {}
 | 
			
		|||
 | 
			
		||||
void TimedHaltCommand::preProcess()
 | 
			
		||||
{
 | 
			
		||||
  if(_e->getRequestGroupMan()->downloadFinished() || _e->isHaltRequested()) {
 | 
			
		||||
    _exit = true;
 | 
			
		||||
  if(getDownloadEngine()->getRequestGroupMan()->downloadFinished() ||
 | 
			
		||||
     getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimedHaltCommand::process()
 | 
			
		||||
{
 | 
			
		||||
  if(!_e->isHaltRequested()) {
 | 
			
		||||
    getLogger()->notice(MSG_TIME_HAS_PASSED, _interval);
 | 
			
		||||
  if(!getDownloadEngine()->isHaltRequested()) {
 | 
			
		||||
    getLogger()->notice(MSG_TIME_HAS_PASSED, getInterval());
 | 
			
		||||
    if(_forceHalt) {
 | 
			
		||||
      getLogger()->notice("This is emergency shutdown.");
 | 
			
		||||
      _e->requestForceHalt();
 | 
			
		||||
      getDownloadEngine()->requestForceHalt();
 | 
			
		||||
    } else {
 | 
			
		||||
      _e->requestHalt();
 | 
			
		||||
      getDownloadEngine()->requestHalt();
 | 
			
		||||
    }
 | 
			
		||||
    _exit = true;
 | 
			
		||||
    enableExit();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue