kget
btcache.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "btcache.h"
00011
00012 #include <diskio/chunk.h>
00013
00014 #include <KDebug>
00015 #include <QDataStream>
00016
00017 using namespace bt;
00018
00019 BTCache::BTCache(Torrent & tor,const QString & tmpdir,const QString & datadir)
00020 : Cache(tor, tmpdir, datadir),
00021 QObject(0)
00022 {
00023 }
00024
00025 BTCache::~BTCache()
00026 {
00027 }
00028
00029 void BTCache::load(Chunk* c)
00030 {
00031 c->setData(0, Chunk::MMAPPED);
00032 }
00033
00034 void BTCache::save(Chunk* c)
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 KIO::fileoffset_t off = c->getIndex() * tor.getChunkSize();
00050 kDebug(5001) << "Fileoffset is: " + QString::number(off);
00051 QByteArray data;
00052 QDataStream s(&data, QIODevice::WriteOnly | QIODevice::Unbuffered);
00053 s << c->getData();
00054 emit dataArrived(off, data);
00055
00056 c->clear();
00057 c->setStatus(Chunk::ON_DISK);
00058
00059 }
00060
00061 bool BTCache::prep(Chunk* c)
00062 {
00063 c->setData(0, Chunk::MMAPPED);
00064 return true;
00065 }
00066
00067 void BTCache::deleteDataFiles()
00068 {
00069 }
00070
00071 Cache* BTCacheFactory::create(Torrent & tor,const QString & tmpdir,const QString & datadir)
00072 {
00073 BTCache *newcache = new BTCache(tor, tmpdir, datadir);
00074 emit cacheAdded(newcache);
00075 return newcache;
00076 }
00077
00078 #include "btcache.moc"