[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/ktorrent/libbtcore
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2009-07-18 8:45:43
Message-ID: 1247906743.647778.8942.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 998621 by guisson:

Preallocation is now done via job system

 M  +2 -0      CMakeLists.txt  
 M  +1 -0      datachecker/datacheckerjob.h  
 A             diskio/preallocationjob.cpp   torrent/jobqueue.cpp#998620 [License: GPL (v2+)]
 A             diskio/preallocationjob.h   datachecker/datacheckerjob.h#998620 [License: GPL (v2+)]
 M  +7 -0      torrent/job.cpp  
 M  +4 -0      torrent/job.h  
 M  +17 -5     torrent/jobqueue.cpp  
 M  +6 -0      torrent/jobqueue.h  
 M  +13 -29    torrent/torrentcontrol.cpp  
 M  +3 -2      torrent/torrentcontrol.h  
 M  +2 -1      torrent/torrentstats.h  


--- trunk/extragear/network/ktorrent/libbtcore/CMakeLists.txt #998620:998621
@@ -157,6 +157,7 @@
 	diskio/singlefilecache.cpp
 	diskio/multifilecache.cpp
 	diskio/preallocationthread.cpp
+	diskio/preallocationjob.cpp
 	diskio/movedatafilesjob.cpp
 	diskio/deletedatafilesjob.cpp
 	diskio/piecedata.cpp
@@ -310,6 +311,7 @@
 	./diskio/cachefile.h
 	./diskio/singlefilecache.h
 	./diskio/preallocationthread.h
+	./diskio/preallocationjob.h
 	./diskio/movedatafilesjob.h
 	./diskio/deletedatafilesjob.h
 	./diskio/chunkmanager.h
--- trunk/extragear/network/ktorrent/libbtcore/datachecker/datacheckerjob.h #998620:998621
@@ -37,6 +37,7 @@
 		
 		virtual void start();
 		virtual void kill(bool quietly = true);
+		virtual TorrentStatus torrentStatus() const {return CHECKING_DATA;}
 		
 	private slots:
 		void finished();
--- trunk/extragear/network/ktorrent/libbtcore/torrent/job.cpp #998620:998621
@@ -43,5 +43,12 @@
 			emitResult();
 		}
 	}
+	
+	
+	TorrentStatus Job::torrentStatus() const
+	{
+		return INVALID_STATUS;
+	}
+
 }
 
--- trunk/extragear/network/ktorrent/libbtcore/torrent/job.h #998620:998621
@@ -23,6 +23,7 @@
 
 #include <kio/job.h>
 #include <btcore_export.h>
+#include "torrentstats.h"
 
 namespace bt 
 {
@@ -41,6 +42,9 @@
 		virtual void start();
 		virtual void kill(bool quietly=true);
 		
+		/// Return the status of the torrent during the job (default implementation returns INVALID_STATUS)
+		virtual TorrentStatus torrentStatus() const;
+		
 		TorrentControl* torrent() {return tc;}
 	private:
 		TorrentControl* tc;
--- trunk/extragear/network/ktorrent/libbtcore/torrent/jobqueue.cpp #998620:998621
@@ -33,11 +33,7 @@
 	
 	JobQueue::~JobQueue()
 	{
-		foreach (Job* j,queue)
-		{
-			j->kill(true);
-			delete j;
-		}
+		killAll();
 	}
 	
 	void JobQueue::enqueue(Job* job)
@@ -51,6 +47,11 @@
 	{
 		return queue.count() > 0;
 	}
+	
+	Job* JobQueue::currentJob()
+	{
+		return queue.isEmpty() ? 0 : queue.front();
+	}
 
 	void JobQueue::startNextJob()
 	{
@@ -74,5 +75,16 @@
 		queue.pop_front();
 		startNextJob();
 	}
+	
+	
+	void JobQueue::killAll()
+	{
+		if (queue.isEmpty())
+			return;
+		
+		queue.front()->kill();
+		qDeleteAll(queue);
+	}
+
 }
 
--- trunk/extragear/network/ktorrent/libbtcore/torrent/jobqueue.h #998620:998621
@@ -48,6 +48,12 @@
 		/// Enqueue a job
 		void enqueue(Job* job);
 		
+		/// Get the current job
+		Job* currentJob();
+		
+		/// Kill all jobs
+		void killAll();
+		
 	private slots:
 		void jobDone(KJob* job);
 		
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.cpp #998620:998621
@@ -64,6 +64,7 @@
 #include "timeestimator.h"
 #include "jobqueue.h"
 #include <datachecker/datacheckerjob.h>
+#include <diskio/preallocationjob.h>
 
 
 namespace bt
@@ -95,7 +96,6 @@
 		istats.diskspace_warning_emitted = false;
 		istats.dht_on = false;
 		updateStats();
-		prealloc_thread = 0;
 		
 		m_eta = new TimeEstimator(this);
 		// by default no torrent limits
@@ -135,7 +135,7 @@
 	void TorrentControl::update()
 	{
 		UpdateCurrentTime();
-		if (moving_files || job_queue->runningJobs()|| prealloc_thread)
+		if (moving_files || job_queue->runningJobs())
 			return;
 		
 		if (istats.io_error)
@@ -351,12 +351,9 @@
 			if (Cache::preallocationEnabled() && !cman->haveAllChunks())
 			{
 				Out(SYS_GEN|LOG_NOTICE) << "Pre-allocating diskspace" << endl;
-				prealloc_thread = new PreallocationThread(cman);
-				connect(prealloc_thread,SIGNAL(finished()),this,SLOT(preallocThreadDone()),Qt::QueuedConnection);
 				stats.running = true;
-				stats.status = ALLOCATING_DISKSPACE;
-				prealloc_thread->start();
-				statusChanged(this);
+				job_queue->enqueue(new PreallocationJob(cman,this));
+				updateStatus();
 				return;
 			}
 			else
@@ -408,17 +405,9 @@
 		istats.running_time_ul += istats.time_started_ul.secsTo(now);
 		istats.time_started_ul = istats.time_started_dl = now;
 		
-		// stop preallocation thread if necesarry
-		if (prealloc_thread)
-		{
-			disconnect(prealloc_thread,SIGNAL(finished()),this,SLOT(preallocThreadDone()));
-			prealloc_thread->stop();
-			prealloc_thread->wait();
-			if (prealloc_thread->errorHappened() || prealloc_thread->isNotFinished())
-				saveStats(); // save stats, so that we will start preallocating the next time
-			prealloc_thread->deleteLater();
-			prealloc_thread = 0;
-		}
+		// stop preallocation
+		if (job_queue->currentJob() && job_queue->currentJob()->torrentStatus() == ALLOCATING_DISKSPACE)
+			job_queue->currentJob()->kill(false);
 	
 		if (stats.running)
 		{
@@ -912,6 +901,8 @@
 		TorrentStatus old = stats.status;
 		if (stats.stopped_by_error)
 			stats.status = ERROR;
+		else if (job_queue->currentJob() && job_queue->currentJob()->torrentStatus() != INVALID_STATUS)
+			stats.status = job_queue->currentJob()->torrentStatus();
 		else if (stats.queued)
 			stats.status = QUEUED;
 		else if (stats.completed && (overMaxRatio() || overMaxSeedTime()))
@@ -1697,25 +1688,18 @@
 		return pman;
 	}
 	
-	void TorrentControl::preallocThreadDone()
+	void TorrentControl::preallocFinished(const QString & error,bool completed)
 	{
-		if (!prealloc_thread)
-			return;
-		
-		// thread done
-		if (prealloc_thread->errorHappened())
+		if (!error.isEmpty() || !completed)
 		{
 			// upon error just call onIOError and return
-			onIOError(prealloc_thread->errorMessage());
-			prealloc_thread->deleteLater();
-			prealloc_thread = 0;
+			if (!error.isEmpty())
+				onIOError(error);
 			prealloc = true; // still need to do preallocation
 		}
 		else
 		{
 			// continue the startup of the torrent
-			prealloc_thread->deleteLater();
-			prealloc_thread = 0;
 			prealloc = false;
 			stats.status = NOT_STARTED;
 			saveStats();
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.h #998620:998621
@@ -333,6 +333,7 @@
 		/// Called when a data check is finished by DataCheckerJob
 		void afterDataCheck(DataCheckerListener* lst,const BitSet & result,const QString & error);
 		void beforeDataCheck();
+		void preallocFinished(const QString & error,bool completed);
 		
 	private slots:
 		void onNewPeer(Peer* p);
@@ -344,7 +345,6 @@
 		void corrupted(Uint32 chunk);
 		void moveDataFilesFinished(KJob* j);
 		void downloaded(Uint32 chunk);
-		void preallocThreadDone();
 		void moveToCompletedDir();
 		
 	private:	
@@ -400,7 +400,7 @@
 		QString error_msg;
 		
 		bool prealloc;
-		PreallocationThread* prealloc_thread;
+		
 		TimeStamp last_diskspace_check;
 		bool moving_files;
 		
@@ -438,6 +438,7 @@
 		static Uint32 num_corrupted_for_recheck;
 		
 		friend class DataCheckerJob;
+		friend class PreallocationJob;
 	};
 	
 	
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentstats.h #998620:998621
@@ -40,7 +40,8 @@
 		ERROR,
 		QUEUED,
 		CHECKING_DATA,
-		NO_SPACE_LEFT
+		NO_SPACE_LEFT,
+		INVALID_STATUS
 	};
 
 	struct BTCORE_EXPORT TorrentStats
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic