1 /* This file is part of the KDE project
2
3 Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9 */
10 #include "btcache.h"
11
12 #include <diskio/chunk.h>
13
14 #include <QDataStream>
15
16 using namespace bt;
17 //TODO: Support buffered mode?
BTCache(Torrent & tor,const QString & tmpdir,const QString & datadir)18 BTCache::BTCache(Torrent & tor,const QString & tmpdir,const QString & datadir)
19 : Cache(tor, tmpdir, datadir),
20 QObject(nullptr)
21 {
22 }
23
~BTCache()24 BTCache::~BTCache()
25 {
26 }
27
load(Chunk * c)28 void BTCache::load(Chunk* c)
29 {
30 c->setData(0, Chunk::MMAPPED);
31 }
32
save(Chunk * c)33 void BTCache::save(Chunk* c)
34 {
35 /*if (c->getStatus() == Chunk::MMAPPED)
36 {
37 KIO::fileoffset_t off = c->getIndex() * tor.getChunkSize();
38 qCDebug(KGET_DEBUG) << "Fileoffset is: " + QString::number(off);
39 QByteArray data;
40 QDataStream s(&data, QIODevice::WriteOnly | QIODevice::Unbuffered);
41 s << c->getData();
42 emit dataArrived(off, data);
43 c->clear();
44 c->setStatus(Chunk::ON_DISK);
45 }
46 else if (c->getStatus() == Chunk::BUFFERED)
47 {*/
48 KIO::fileoffset_t off = c->getIndex() * tor.getChunkSize();
49 qCDebug(KGET_DEBUG) << "Fileoffset is: " + QString::number(off);
50 QByteArray data;
51 QDataStream s(&data, QIODevice::WriteOnly | QIODevice::Unbuffered);
52 s << c->getData();
53 emit dataArrived(off, data);
54 //fd->write(c->getData(),c->getSize(),off);//Send a signal here that the signal has arrived
55 c->clear();
56 c->setStatus(Chunk::ON_DISK);
57 //}
58 }
59
prep(Chunk * c)60 bool BTCache::prep(Chunk* c)
61 {
62 c->setData(0, Chunk::MMAPPED);
63 return true;
64 }
65
deleteDataFiles()66 void BTCache::deleteDataFiles()
67 {
68 }
69
create(Torrent & tor,const QString & tmpdir,const QString & datadir)70 Cache* BTCacheFactory::create(Torrent & tor,const QString & tmpdir,const QString & datadir)
71 {
72 BTCache *newcache = new BTCache(tor, tmpdir, datadir);
73 emit cacheAdded(newcache);
74 return newcache;
75 }
76
77
78