[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:15
Message-ID: 1247906715.259660.8843.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 998620 by guisson:
Started implementing job system, first included is the datachecker
M +6 -0 CMakeLists.txt
A datachecker/datacheckerjob.cpp [License: GPL (v2+)]
A datachecker/datacheckerjob.h [License: GPL (v2+)]
A torrent/job.cpp [License: GPL (v2+)]
A torrent/job.h [License: GPL (v2+)]
A torrent/jobqueue.cpp [License: GPL (v2+)]
A torrent/jobqueue.h [License: GPL (v2+)]
M +27 -45 torrent/torrentcontrol.cpp
M +10 -2 torrent/torrentcontrol.h
--- trunk/extragear/network/ktorrent/libbtcore/CMakeLists.txt #998619:998620
@@ -131,6 +131,8 @@
torrent/torrentcontrol.cpp
torrent/torrentcreator.cpp
torrent/torrentstats.cpp
+ torrent/jobqueue.cpp
+ torrent/job.cpp
dht/announcetask.cpp
dht/dht.cpp
@@ -173,6 +175,7 @@
datachecker/singledatachecker.cpp
datachecker/datacheckerlistener.cpp
datachecker/multidatachecker.cpp
+ datachecker/datacheckerjob.cpp
migrate/cachemigrate.cpp
migrate/ccmigrate.cpp
@@ -330,6 +333,8 @@
./torrent/statsfile.h
./torrent/globals.h
./torrent/stats.h
+ ./torrent/job.h
+ ./torrent/jobqueue.h
)
set (tracker_HDR
@@ -346,6 +351,7 @@
./datachecker/singledatachecker.h
./datachecker/datacheckerlistener.h
./datachecker/multidatachecker.h
+ ./datachecker/datacheckerjob.h
)
set (dht_HDR
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.cpp \
#998619:998620 @@ -35,6 +35,8 @@
#include <interfaces/trackerslist.h>
#include <interfaces/monitorinterface.h>
#include <interfaces/cachefactory.h>
+#include <interfaces/queuemanagerinterface.h>
+#include <interfaces/chunkselectorinterface.h>
#include <datachecker/singledatachecker.h>
#include <datachecker/multidatachecker.h>
#include <datachecker/datacheckerlistener.h>
@@ -42,31 +44,28 @@
#include <migrate/ccmigrate.h>
#include <migrate/cachemigrate.h>
#include <dht/dhtbase.h>
-
#include <download/downloader.h>
#include <download/webseed.h>
-#include "uploader.h"
-#include "peersourcemanager.h"
#include <diskio/cache.h>
#include <diskio/chunkmanager.h>
-#include "torrent.h"
+#include <diskio/preallocationthread.h>
+#include <peer/peer.h>
#include <peer/peermanager.h>
-
+#include <peer/packetwriter.h>
+#include <net/socketmonitor.h>
#include "torrentfile.h"
-
-#include <peer/peer.h>
+#include "torrent.h"
#include "choker.h"
-
#include "globals.h"
#include "server.h"
-#include <peer/packetwriter.h>
-#include <interfaces/queuemanagerinterface.h>
-#include <interfaces/chunkselectorinterface.h>
+#include "uploader.h"
+#include "peersourcemanager.h"
#include "statsfile.h"
-#include <diskio/preallocationthread.h>
#include "timeestimator.h"
-#include <net/socketmonitor.h>
+#include "jobqueue.h"
+#include <datachecker/datacheckerjob.h>
+
namespace bt
{
@@ -81,6 +80,7 @@
TorrentControl::TorrentControl()
: tor(0),psman(0),cman(0),pman(0),downloader(0),uploader(0),choke(0),tmon(0),prealloc(false)
{
+ job_queue = new JobQueue(this);
custom_selector_factory = 0;
cache_factory = 0;
istats.session_bytes_uploaded = 0;
@@ -96,7 +96,6 @@
istats.dht_on = false;
updateStats();
prealloc_thread = 0;
- dcheck_thread = 0;
m_eta = new TimeEstimator(this);
// by default no torrent limits
@@ -136,7 +135,7 @@
void TorrentControl::update()
{
UpdateCurrentTime();
- if (moving_files || dcheck_thread || prealloc_thread)
+ if (moving_files || job_queue->runningJobs()|| prealloc_thread)
return;
if (istats.io_error)
@@ -913,8 +912,6 @@
TorrentStatus old = stats.status;
if (stats.stopped_by_error)
stats.status = ERROR;
- else if (dcheck_thread)
- stats.status = CHECKING_DATA;
else if (stats.queued)
stats.status = QUEUED;
else if (stats.completed && (overMaxRatio() || overMaxSeedTime()))
@@ -1317,46 +1314,33 @@
void TorrentControl::startDataCheck(bt::DataCheckerListener* lst)
{
- if (stats.status == ALLOCATING_DISKSPACE)
- return;
-
- DataChecker* dc = 0;
+ job_queue->enqueue(new DataCheckerJob(lst,this));
+ }
+
+ void TorrentControl::beforeDataCheck()
+ {
stats.status = CHECKING_DATA;
stats.num_corrupted_chunks = 0; // reset the number of corrupted chunks found
- if (stats.multi_file_torrent)
- dc = new MultiDataChecker();
- else
- dc = new SingleDataChecker();
-
- dc->setListener(lst);
-
- dcheck_thread = new \
DataCheckerThread(dc,cman->getBitSet(),stats.output_path,*tor,tordir + "dnd" + \
bt::DirSeparator());
- connect(dcheck_thread,SIGNAL(finished()),this,SLOT(afterDataCheck()),Qt::QueuedConnection);
-
- // dc->check(stats.output_path,*tor,tordir + "dnd" + bt::DirSeparator());
- dcheck_thread->start(QThread::IdlePriority);
statusChanged(this);
}
+
- void TorrentControl::afterDataCheck()
+ void TorrentControl::afterDataCheck(DataCheckerListener* lst,const BitSet & \
result,const QString & error) {
- DataChecker* dc = dcheck_thread->getDataChecker();
- DataCheckerListener* lst = dc->getListener();
-
- bool err = !dcheck_thread->getError().isNull();
+ bool err = !error.isNull();
if (err)
{
// show a queued error message when an error has occurred
- KMessageBox::queuedMessageBox(0,KMessageBox::Error,dcheck_thread->getError());
+ KMessageBox::queuedMessageBox(0,KMessageBox::Error,error);
lst->stop();
}
bool completed = stats.completed;
if (lst && !lst->isStopped())
{
- downloader->dataChecked(dc->getResult());
+ downloader->dataChecked(result);
// update chunk manager
- cman->dataChecked(dc->getResult());
+ cman->dataChecked(result);
if (lst->isAutoImport())
{
downloader->recalcDownloaded();
@@ -1376,8 +1360,6 @@
}
updateStats();
- dcheck_thread->deleteLater();
- dcheck_thread = 0;
Out(SYS_GEN|LOG_NOTICE) << "Data check finished" << endl;
updateStatus();
if (lst)
@@ -1396,9 +1378,9 @@
bool TorrentControl::isCheckingData(bool & finished) const
{
- if (dcheck_thread)
+ if (stats.status == CHECKING_DATA)
{
- finished = !dcheck_thread->isRunning();
+ finished = false;
return true;
}
return false;
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.h \
#998619:998620 @@ -55,6 +55,7 @@
class MonitorInterface;
class ChunkSelectorFactoryInterface;
class CacheFactory;
+ class JobQueue;
/**
* @author Joris Guisson
@@ -328,6 +329,11 @@
*/
static void setNumCorruptedForRecheck(Uint32 m) {num_corrupted_for_recheck = m;}
+ protected:
+ /// Called when a data check is finished by DataCheckerJob
+ void afterDataCheck(DataCheckerListener* lst,const BitSet & result,const QString & \
error); + void beforeDataCheck();
+
private slots:
void onNewPeer(Peer* p);
void onPeerRemoved(Peer* p);
@@ -338,7 +344,6 @@
void corrupted(Uint32 chunk);
void moveDataFilesFinished(KJob* j);
void downloaded(Uint32 chunk);
- void afterDataCheck();
void preallocThreadDone();
void moveToCompletedDir();
@@ -363,10 +368,12 @@
void setUploadProps(Uint32 limit,Uint32 rate);
void setDownloadProps(Uint32 limit,Uint32 rate);
+
signals:
void dataCheckFinished();
private:
+ JobQueue* job_queue;
Torrent* tor;
PeerSourceManager* psman;
ChunkManager* cman;
@@ -394,7 +401,6 @@
bool prealloc;
PreallocationThread* prealloc_thread;
- DataCheckerThread* dcheck_thread;
TimeStamp last_diskspace_check;
bool moving_files;
@@ -430,6 +436,8 @@
static Uint32 min_diskspace;
static bool auto_recheck;
static Uint32 num_corrupted_for_recheck;
+
+ friend class DataCheckerJob;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic