summaryrefslogtreecommitdiffstats
path: root/libktorrent/torrent/cache.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 02:37:40 +0000
commit9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0 (patch)
treed088b5210e77d9fa91d954d8550e00e372b47378 /libktorrent/torrent/cache.h
downloadktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.tar.gz
ktorrent-9ad5c7b5e23b4940e7a3ea3ca3a6fb77e6a8fab0.zip
Updated to final KDE3 ktorrent release (2.2.6)
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktorrent@1077377 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'libktorrent/torrent/cache.h')
-rw-r--r--libktorrent/torrent/cache.h165
1 files changed, 165 insertions, 0 deletions
diff --git a/libktorrent/torrent/cache.h b/libktorrent/torrent/cache.h
new file mode 100644
index 0000000..4c373ee
--- /dev/null
+++ b/libktorrent/torrent/cache.h
@@ -0,0 +1,165 @@
+/***************************************************************************
+ * Copyright (C) 2005 by Joris Guisson *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+#ifndef BTCACHE_H
+#define BTCACHE_H
+
+#include <kio/job.h>
+
+class QStringList;
+
+namespace bt
+{
+ class Torrent;
+ class TorrentFile;
+ class Chunk;
+ class PreallocationThread;
+
+
+ /**
+ * @author Joris Guisson
+ * @brief Manages the temporary data
+ *
+ * Interface for a class which manages downloaded data.
+ * Subclasses should implement the load and save methods.
+ */
+ class Cache
+ {
+ protected:
+ Torrent & tor;
+ QString tmpdir;
+ QString datadir;
+ bool preexisting_files;
+ Uint32 mmap_failures;
+ public:
+ Cache(Torrent & tor,const QString & tmpdir,const QString & datadir);
+ virtual ~Cache();
+
+ /// Get the datadir
+ QString getDataDir() const {return datadir;}
+
+ /**
+ * Get the actual output path.
+ * @return The output path
+ */
+ virtual QString getOutputPath() const = 0;
+
+ /**
+ * Changes the tmp dir. All data files should already been moved.
+ * This just modifies the tmpdir variable.
+ * @param ndir The new tmpdir
+ */
+ virtual void changeTmpDir(const QString & ndir);
+
+ /**
+ * Move the data files to a new directory.
+ * @param ndir The directory
+ * @return The KIO::Job doing the move
+ */
+ virtual KIO::Job* moveDataFiles(const QString & ndir) = 0;
+
+ /**
+ * The move data files job is done.
+ * @param job The job that did it
+ */
+ virtual void moveDataFilesCompleted(KIO::Job* job) = 0;
+
+ /**
+ * Changes output path. All data files should already been moved.
+ * This just modifies the datadir variable.
+ * @param outputpath New output path
+ */
+ virtual void changeOutputPath(const QString & outputpath) = 0;
+
+ /**
+ * Load a chunk into memory. If something goes wrong,
+ * an Error should be thrown.
+ * @param c The Chunk
+ */
+ virtual void load(Chunk* c) = 0;
+
+ /**
+ * Save a chunk to disk. If something goes wrong,
+ * an Error should be thrown.
+ * @param c The Chunk
+ */
+ virtual void save(Chunk* c) = 0;
+
+ /**
+ * Prepare a chunk for downloading.
+ * @param c The Chunk
+ * @return true if ok, false otherwise
+ */
+ virtual bool prep(Chunk* c) = 0;
+
+ /**
+ * Create all the data files to store the data.
+ */
+ virtual void create() = 0;
+
+ /**
+ * Close the cache file(s).
+ */
+ virtual void close() = 0;
+
+ /**
+ * Open the cache file(s)
+ */
+ virtual void open() = 0;
+
+ /// Does nothing, can be overridden to be alerted of download status changes of a TorrentFile
+ virtual void downloadStatusChanged(TorrentFile*, bool) {};
+
+ /**
+ * Preallocate diskspace for all files
+ * @param prealloc The thread doing the preallocation
+ */
+ virtual void preallocateDiskSpace(PreallocationThread* prealloc) = 0;
+
+ /// See if the download has existing files
+ bool hasExistingFiles() const {return preexisting_files;}
+
+
+ /**
+ * Test all files and see if they are not missing.
+ * If so put them in a list
+ */
+ virtual bool hasMissingFiles(QStringList & sl) = 0;
+
+ /**
+ * Delete all data files, in case of multi file torrents
+ * empty directories should also be deleted.
+ */
+ virtual void deleteDataFiles() = 0;
+
+ /**
+ * See if we are allowed to use mmap, when loading chunks.
+ * This will return false if we are close to system limits.
+ */
+ static bool mappedModeAllowed();
+
+ /**
+ * Get the number of bytes all the files of this torrent are currently using on disk.
+ * */
+ virtual Uint64 diskUsage() = 0;
+ };
+
+}
+
+#endif