libktorrent  2.2.0
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
bt::Cache Class Referenceabstract

Manages the temporary data. More...

#include <cache.h>

Inheritance diagram for bt::Cache:
Inheritance graph
[legend]

Public Member Functions

 Cache (Torrent &tor, const QString &tmpdir, const QString &datadir)
 
virtual void changeOutputPath (const QString &outputpath)=0
 
virtual void changeTmpDir (const QString &ndir)
 
void checkMemoryUsage ()
 
void clearPieces (Chunk *c)
 
virtual void close ()=0
 
virtual void create ()=0
 
virtual JobdeleteDataFiles ()=0
 
virtual Uint64 diskUsage ()=0
 
virtual void downloadStatusChanged (TorrentFile *, bool)
 Does nothing, can be overridden to be alerted of download status changes of a TorrentFile.
 
QString getDataDir () const
 Get the datadir.
 
virtual bool getMountPoints (QSet< QString > &mps)=0
 
virtual QString getOutputPath () const =0
 
bool hasExistingFiles () const
 See if the download has existing files.
 
virtual bool hasMissingFiles (QStringList &sl)=0
 
bool isStorageMounted (QStringList &missing)
 Is the storage mounted ?
 
virtual void loadFileMap ()=0
 
void loadMountPoints ()
 
virtual PieceData::Ptr loadPiece (Chunk *c, Uint32 off, Uint32 length)=0
 
virtual JobmoveDataFiles (const QMap< TorrentFileInterface *, QString > &files)
 
virtual JobmoveDataFiles (const QString &ndir)=0
 
virtual void moveDataFilesFinished (const QMap< TorrentFileInterface *, QString > &files, Job *job)
 
virtual void moveDataFilesFinished (Job *job)=0
 
virtual void open ()=0
 
virtual PieceData::Ptr preparePiece (Chunk *c, Uint32 off, Uint32 length)=0
 
virtual void preparePreallocation (PreallocationThread *prealloc)=0
 
virtual void saveFileMap ()=0
 
virtual void savePiece (PieceData::Ptr piece)=0
 

Static Public Member Functions

static bool mappedModeAllowed ()
 
static bool preallocateFully ()
 
static bool preallocationEnabled ()
 
static void setPreallocateFully (bool on)
 
static void setPreallocationEnabled (bool on)
 

Protected Types

typedef QMultiMap< Chunk *, PieceData::Ptr > PieceCache
 

Protected Member Functions

void cleanupPieceCache ()
 
void clearPieceCache ()
 
PieceData::Ptr findPiece (Chunk *c, Uint32 off, Uint32 len, bool read_only)
 
void insertPiece (Chunk *c, PieceData::Ptr p)
 
void saveMountPoints (const QSet< QString > &mp)
 

Protected Attributes

QString datadir
 
Uint32 mmap_failures
 
QSet< QString > mount_points
 
PieceCache piece_cache
 
bool preexisting_files
 
QString tmpdir
 
Torrenttor
 

Detailed Description

Author
Joris Guisson Interface for a class which manages downloaded data. Subclasses should implement the load and save methods.

Definition at line 49 of file cache.h.

Member Function Documentation

◆ changeOutputPath()

virtual void bt::Cache::changeOutputPath ( const QString &  outputpath)
pure virtual

Changes output path. All data files should already been moved. This just modifies the datadir variable.

Parameters
outputpathNew output path

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ changeTmpDir()

virtual void bt::Cache::changeTmpDir ( const QString &  ndir)
virtual

Changes the tmp dir. All data files should already been moved. This just modifies the tmpdir variable.

Parameters
ndirThe new tmpdir

Reimplemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ checkMemoryUsage()

void bt::Cache::checkMemoryUsage ( )

Check memory usage and free all PieceData objects which are no longer needed.

◆ clearPieces()

void bt::Cache::clearPieces ( Chunk c)

Clear all pieces of a chunk

Parameters
cThe chunk

◆ close()

virtual void bt::Cache::close ( )
pure virtual

Close the cache file(s).

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ create()

virtual void bt::Cache::create ( )
pure virtual

Create all the data files to store the data.

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ deleteDataFiles()

virtual Job* bt::Cache::deleteDataFiles ( )
pure virtual

Delete all data files, in case of multi file torrents empty directories should also be deleted.

Returns
The job doing the delete

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ diskUsage()

virtual Uint64 bt::Cache::diskUsage ( )
pure virtual

Get the number of bytes all the files of this torrent are currently using on disk.

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ getMountPoints()

virtual bool bt::Cache::getMountPoints ( QSet< QString > &  mps)
pure virtual

Determine the mount points of all the files in this torrent

Returns
bool True if we can, false if not

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ getOutputPath()

virtual QString bt::Cache::getOutputPath ( ) const
pure virtual

Get the actual output path.

Returns
The output path

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ hasMissingFiles()

virtual bool bt::Cache::hasMissingFiles ( QStringList &  sl)
pure virtual

Test all files and see if they are not missing. If so put them in a list

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ loadFileMap()

virtual void bt::Cache::loadFileMap ( )
pure virtual

Load the file map of a torrent. If it doesn't exist, it needs to be created.

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ loadMountPoints()

void bt::Cache::loadMountPoints ( )

Load the mount points of this torrent

◆ loadPiece()

virtual PieceData::Ptr bt::Cache::loadPiece ( Chunk c,
Uint32  off,
Uint32  length 
)
pure virtual

Load a piece into memory. If something goes wrong, an Error should be thrown.

Parameters
cThe Chunk
offThe offset of the piece
lengthThe length of the piece
Returns
Pointer to the data

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ mappedModeAllowed()

static bool bt::Cache::mappedModeAllowed ( )
static

See if we are allowed to use mmap, when loading chunks. This will return false if we are close to system limits.

◆ moveDataFiles() [1/2]

virtual Job* bt::Cache::moveDataFiles ( const QMap< TorrentFileInterface *, QString > &  files)
virtual

Move some files to a new location

Parameters
filesMap of files to move and their new location
Returns
Job The job doing the move

Reimplemented in bt::MultiFileCache.

◆ moveDataFiles() [2/2]

virtual Job* bt::Cache::moveDataFiles ( const QString &  ndir)
pure virtual

Move the data files to a new directory.

Parameters
ndirThe directory
Returns
The job doing the move

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ moveDataFilesFinished() [1/2]

virtual void bt::Cache::moveDataFilesFinished ( const QMap< TorrentFileInterface *, QString > &  files,
Job job 
)
virtual

The job doing moveDataFiles (with the map parameter) has finished

Parameters
filesThe files map with all the moves
jobThe job doing the move

Reimplemented in bt::MultiFileCache.

◆ moveDataFilesFinished() [2/2]

virtual void bt::Cache::moveDataFilesFinished ( Job job)
pure virtual

A move of a bunch of data files has finished

Parameters
jobThe job doing the move

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ open()

virtual void bt::Cache::open ( )
pure virtual

Open the cache file(s)

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ preallocateFully()

static bool bt::Cache::preallocateFully ( )
inlinestatic

Check if full diskspace preallocation is enabled.

Returns
true if it is

Definition at line 221 of file cache.h.

◆ preallocationEnabled()

static bool bt::Cache::preallocationEnabled ( )
inlinestatic

Check if diskspace preallocation is enabled

Returns
true if it is

Definition at line 209 of file cache.h.

◆ preparePiece()

virtual PieceData::Ptr bt::Cache::preparePiece ( Chunk c,
Uint32  off,
Uint32  length 
)
pure virtual

Prepare a piece for writing. If something goes wrong, an Error should be thrown.

Parameters
cThe Chunk
offThe offset of the piece
lengthThe length of the piece
Returns
Pointer to the data

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ preparePreallocation()

virtual void bt::Cache::preparePreallocation ( PreallocationThread prealloc)
pure virtual

Prepare disksapce preallocation

Parameters
preallocThe thread going to do the preallocation

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ saveFileMap()

virtual void bt::Cache::saveFileMap ( )
pure virtual

Save the file map of a torrent

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ savePiece()

virtual void bt::Cache::savePiece ( PieceData::Ptr  piece)
pure virtual

Save a piece to disk, will only actually save in buffered mode

Parameters
pieceThe piece

Implemented in bt::MultiFileCache, and bt::SingleFileCache.

◆ setPreallocateFully()

static void bt::Cache::setPreallocateFully ( bool  on)
inlinestatic

Enable or disable full diskspace preallocation

Parameters
on

Definition at line 215 of file cache.h.

◆ setPreallocationEnabled()

static void bt::Cache::setPreallocationEnabled ( bool  on)
inlinestatic

Enable or disable diskspace preallocation

Parameters
on

Definition at line 203 of file cache.h.


The documentation for this class was generated from the following file: