• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

bt::ChunkManager

bt::ChunkManager Class Reference

#include <chunkmanager.h>

Inheritance diagram for bt::ChunkManager:

Inheritance graph
[legend]

List of all members.


Detailed Description

Author:
Joris Guisson

Manages all Chunk's and the cache file, where all the chunk's are stored. It also manages a separate index file, where the position of each piece in the cache file is stored.

The chunks are stored in the cache file in the correct order. Eliminating the need for a file reconstruction algorithm for single files.

Definition at line 60 of file chunkmanager.h.


Signals

void corrupted (Uint32 chunk)
void excluded (Uint32 from, Uint32 to)
void included (Uint32 from, Uint32 to)
void updateStats ()

Public Member Functions

Uint64 bytesExcluded () const
Uint64 bytesLeft () const
Uint64 bytesLeftToDownload () const
void changeDataDir (const QString &data_dir)
void changeOutputPath (const QString &output_path)
void checkMemoryUsage ()
 ChunkManager (Torrent &tor, const QString &tmpdir, const QString &datadir, bool custom_output_name, CacheFactory *fac)
Uint32 chunksDownloaded () const
Uint32 chunksExcluded () const
Uint32 chunksLeft () const
bool completed () const
void createFiles (bool check_priority=false)
void dataChecked (const BitSet &ok_chunks)
void debugPrintMemUsage ()
void deleteDataFiles ()
Uint64 diskUsage ()
void dndMissingFiles ()
void exclude (Uint32 from, Uint32 to)
const BitSet & getBitSet () const
Chunk * getChunk (unsigned int i)
QString getDataDir () const
const BitSet & getExcludedBitSet () const
Uint32 getNumChunks () const
const BitSet & getOnlySeedBitSet () const
QString getOutputPath () const
const Torrent & getTorrent () const
Chunk * grabChunk (unsigned int i)
bool hasExistingFiles () const
bool hasMissingFiles (QStringList &sl)
bool haveAllChunks () const
void include (Uint32 from, Uint32 to)
void loadIndexFile ()
void markExistingFilesAsDownloaded ()
KJob * moveDataFiles (const QMap< TorrentFileInterface *, QString > &files)
KJob * moveDataFiles (const QString &ndir)
void moveDataFilesFinished (const QMap< TorrentFileInterface *, QString > &files, KJob *job)
void moveDataFilesFinished (KJob *job)
Uint32 onlySeedChunks () const
void preallocateDiskSpace (PreallocationThread *prealloc)
bool prepareChunk (Chunk *c, bool always=false)
Uint32 previewChunkRangeSize () const
Uint32 previewChunkRangeSize (const TorrentFile &tf) const
void prioritise (Uint32 from, Uint32 to, Priority priority)
void recreateMissingFiles ()
void releaseChunk (unsigned int i)
void resetChunk (unsigned int i)
void saveChunk (unsigned int i, bool update_index=true)
void start ()
void stop ()
virtual ~ChunkManager ()

Static Public Member Functions

static void setMaxChunkSizeForDataCheck (Uint32 mcs)
static void setPreviewSizes (Uint32 audio, Uint32 video)
static void setUploadDataCheckingEnabled (bool on)

Constructor & Destructor Documentation

bt::ChunkManager::ChunkManager ( Torrent &  tor,
const QString &  tmpdir,
const QString &  datadir,
bool  custom_output_name,
CacheFactory *  fac 
)

Definition at line 48 of file chunkmanager.cpp.

bt::ChunkManager::~ChunkManager (  )  [virtual]

Definition at line 130 of file chunkmanager.cpp.


Member Function Documentation

Uint64 bt::ChunkManager::bytesExcluded (  )  const

Calculates the number of bytes which have been excluded.

Returns:
The number of bytes excluded

Definition at line 530 of file chunkmanager.cpp.

Uint64 bt::ChunkManager::bytesLeft (  )  const

Calculates the number of bytes left for the tracker.

Does include excluded chunks (this should be used for the tracker).

Returns:
The number of bytes to download + the number of bytes excluded

Definition at line 471 of file chunkmanager.cpp.

Uint64 bt::ChunkManager::bytesLeftToDownload (  )  const

Calculates the number of bytes left to download.

Definition at line 489 of file chunkmanager.cpp.

void bt::ChunkManager::changeDataDir ( const QString &  data_dir  ) 

Change the data dir.

Parameters:
data_dir 

Definition at line 146 of file chunkmanager.cpp.

void bt::ChunkManager::changeOutputPath ( const QString &  output_path  ) 

Definition at line 154 of file chunkmanager.cpp.

void bt::ChunkManager::checkMemoryUsage (  ) 

Remove obsolete chunks.

Definition at line 386 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::chunksDownloaded (  )  const

Get the number of downloaded chunks.

Returns:

Definition at line 562 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::chunksExcluded (  )  const

Get the number of chunks which have been excluded.

Returns:
The number of excluded chunks

Definition at line 557 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::chunksLeft (  )  const

Calculates the number of chunks left to download.

Does not include excluded chunks.

Returns:
The number of chunks to download

Definition at line 507 of file chunkmanager.cpp.

bool bt::ChunkManager::completed (  )  const

Are all not deselected chunks downloaded.

Definition at line 466 of file chunkmanager.cpp.

void bt::ChunkManager::corrupted ( Uint32  chunk  )  [signal]

A corrupted chunk has been found during uploading.

Parameters:
chunk The chunk

void bt::ChunkManager::createFiles ( bool  check_priority = false  ) 

Create the cache file, and index files.

Parameters:
check_priority Check if priority of chunk matches that of files
Exceptions:
Error When it can be created

Definition at line 235 of file chunkmanager.cpp.

void bt::ChunkManager::dataChecked ( const BitSet &  ok_chunks  ) 

Data has been checked, and these chunks are OK.

The ChunkManager will update it's internal structures

Parameters:
ok_chunks The ok_chunks

Definition at line 1029 of file chunkmanager.cpp.

void bt::ChunkManager::debugPrintMemUsage (  ) 

Print memory usage to log file.

Definition at line 567 of file chunkmanager.cpp.

void bt::ChunkManager::deleteDataFiles (  ) 

Delete all data files.

Definition at line 1225 of file chunkmanager.cpp.

Uint64 bt::ChunkManager::diskUsage (  ) 

Get the current disk usage of all the files in this torrent.

Definition at line 1230 of file chunkmanager.cpp.

void bt::ChunkManager::dndMissingFiles (  ) 

Set missing files as do not download.

Definition at line 1203 of file chunkmanager.cpp.

void bt::ChunkManager::exclude ( Uint32  from,
Uint32  to 
)

Make sure that a range will not be downloaded.

Parameters:
from First chunk in range
to Last chunk in range

Definition at line 604 of file chunkmanager.cpp.

void bt::ChunkManager::excluded ( Uint32  from,
Uint32  to 
) [signal]

Emitted when a range of chunks has been excluded.

Parameters:
from First chunk in range
to Last chunk in range

const BitSet& bt::ChunkManager::getBitSet (  )  const [inline]

Get a BitSet of the status of all Chunks.

Definition at line 268 of file chunkmanager.h.

Chunk * bt::ChunkManager::getChunk ( unsigned int  i  ) 

Get's the i'th Chunk.

Parameters:
i The Chunk's index
Returns:
The Chunk, or 0 when i is out of bounds

Definition at line 268 of file chunkmanager.cpp.

QString bt::ChunkManager::getDataDir (  )  const

Get the data dir.

Definition at line 141 of file chunkmanager.cpp.

const BitSet& bt::ChunkManager::getExcludedBitSet (  )  const [inline]

Get the excluded bitset.

Definition at line 273 of file chunkmanager.h.

Uint32 bt::ChunkManager::getNumChunks (  )  const [inline]

Get the number of chunks into the file.

Definition at line 281 of file chunkmanager.h.

const BitSet& bt::ChunkManager::getOnlySeedBitSet (  )  const [inline]

Get the only seed bitset.

Definition at line 278 of file chunkmanager.h.

QString bt::ChunkManager::getOutputPath (  )  const

Get the actual output path.

Definition at line 1019 of file chunkmanager.cpp.

const Torrent& bt::ChunkManager::getTorrent (  )  const [inline]

Get the torrent.

Definition at line 88 of file chunkmanager.h.

Chunk * bt::ChunkManager::grabChunk ( unsigned int  i  ) 

Get's the i'th Chunk.

Makes sure that the Chunk's data is in memory. If the Chunk hasn't been downloaded yet 0 is returned. Whenever the Chunk needs to be uploaded, call this function. This changes the status to MMAPPED or BUFFERED.

Parameters:
i The Chunk's index
Returns:
The Chunk, or 0 when i is out of bounds

Definition at line 302 of file chunkmanager.cpp.

bool bt::ChunkManager::hasExistingFiles (  )  const

Test if the torrent has existing files, only works the first time a torrent is loaded.

Definition at line 1082 of file chunkmanager.cpp.

bool bt::ChunkManager::hasMissingFiles ( QStringList &  sl  ) 

Test all files and see if they are not missing.

If so put them in a list

Definition at line 263 of file chunkmanager.cpp.

bool bt::ChunkManager::haveAllChunks (  )  const

Check if we have all chunks, this is not the same as chunksLeft() == 0, it does not look at excluded chunks.

Returns:
true if all chunks have been downloaded

Definition at line 525 of file chunkmanager.cpp.

void bt::ChunkManager::include ( Uint32  from,
Uint32  to 
)

Make sure that a range will be downloaded.

Does the opposite of exclude.

Parameters:
from First chunk in range
to Last chunk in range

Definition at line 625 of file chunkmanager.cpp.

void bt::ChunkManager::included ( Uint32  from,
Uint32  to 
) [signal]

Emitted when a range of chunks has been included back.

Parameters:
from First chunk in range
to Last chunk in range

void bt::ChunkManager::loadIndexFile (  ) 

Loads the index file.

Exceptions:
Error When it can be loaded

Definition at line 179 of file chunkmanager.cpp.

void bt::ChunkManager::markExistingFilesAsDownloaded (  ) 

Mark all existing files as downloaded.

Definition at line 1100 of file chunkmanager.cpp.

KJob * bt::ChunkManager::moveDataFiles ( const QMap< TorrentFileInterface *, QString > &  files  ) 

Move some data files to a new location.

Parameters:
files Map of files and their new location

Definition at line 169 of file chunkmanager.cpp.

KJob * bt::ChunkManager::moveDataFiles ( const QString &  ndir  ) 

Move the data files of the torrent.

Parameters:
ndir The new directory

Definition at line 159 of file chunkmanager.cpp.

void bt::ChunkManager::moveDataFilesFinished ( const QMap< TorrentFileInterface *, QString > &  files,
KJob *  job 
)

A move of data files with the map has finished.

Parameters:
files Map of files and their new location
job The job doing the move

Definition at line 174 of file chunkmanager.cpp.

void bt::ChunkManager::moveDataFilesFinished ( KJob *  job  ) 

A move of data files has finished.

Parameters:
job The job doing the move

Definition at line 164 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::onlySeedChunks (  )  const

Get the number of only seed chunks.

Definition at line 461 of file chunkmanager.cpp.

void bt::ChunkManager::preallocateDiskSpace ( PreallocationThread *  prealloc  ) 

Preallocate diskspace for all files.

Parameters:
prealloc The thread doing the preallocation

Definition at line 1024 of file chunkmanager.cpp.

bool bt::ChunkManager::prepareChunk ( Chunk *  c,
bool  always = false 
)

Prepare a chunk for downloading.

Parameters:
c The Chunk
always Always do this, even if the chunk is not NOT_DOWNLOADED
Returns:
true if ok, false if the chunk is not NOT_DOWNLOADED

Definition at line 1011 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::previewChunkRangeSize (  )  const

Get the size in chunks of the preview range for a single file torrent.

Definition at line 1257 of file chunkmanager.cpp.

Uint32 bt::ChunkManager::previewChunkRangeSize ( const TorrentFile &  tf  )  const

Get the size in chunks of the preview range of a file of the torrent.

Definition at line 1235 of file chunkmanager.cpp.

void bt::ChunkManager::prioritise ( Uint32  from,
Uint32  to,
Priority  priority 
)

Make sure that a range will get priority over other chunks.

Parameters:
from First chunk in range
to Last chunk in range

Definition at line 572 of file chunkmanager.cpp.

void bt::ChunkManager::recreateMissingFiles (  ) 

Recreates missing files.

Definition at line 1174 of file chunkmanager.cpp.

void bt::ChunkManager::releaseChunk ( unsigned int  i  ) 

The upload is done, and the Chunk is no longer needed.

The Chunk's data might be cleared, if we are using up to much memory.

Parameters:
i The Chunk's index

Definition at line 354 of file chunkmanager.cpp.

void bt::ChunkManager::resetChunk ( unsigned int  i  ) 

Reset a chunk as if it were never downloaded.

Parameters:
i The chunk

Definition at line 370 of file chunkmanager.cpp.

void bt::ChunkManager::saveChunk ( unsigned int  i,
bool  update_index = true 
)

Save the i'th Chunk to the cache_file.

Also changes the Chunk's status to ON_DISK. The Chunk's data is immediately cleared.

Parameters:
i The Chunk's index
update_index Update the index or not

Definition at line 412 of file chunkmanager.cpp.

static void bt::ChunkManager::setMaxChunkSizeForDataCheck ( Uint32  mcs  )  [inline, static]

Set the maximum chunk size for a data check, 0 means there is no limit.

Definition at line 335 of file chunkmanager.h.

void bt::ChunkManager::setPreviewSizes ( Uint32  audio,
Uint32  video 
) [static]

Set the preview sizes for audio and video files.

Definition at line 1292 of file chunkmanager.cpp.

static void bt::ChunkManager::setUploadDataCheckingEnabled ( bool  on  )  [inline, static]

Enabled or disable data checking during upload.

Definition at line 338 of file chunkmanager.h.

void bt::ChunkManager::start (  ) 

Open the necessary files when the download gets started.

Definition at line 276 of file chunkmanager.cpp.

void bt::ChunkManager::stop (  ) 

Closes files when the download gets stopped.

Definition at line 281 of file chunkmanager.cpp.

void bt::ChunkManager::updateStats (  )  [signal]

Emitted when chunks get excluded or included, so that the statistics can be updated.


The documentation for this class was generated from the following files:
  • chunkmanager.h
  • chunkmanager.cpp

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal