2009-01-07 06:53:29 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2012-12-05 17:29:46 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2 (b)
|
2009-08-10 20:04:08 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2009-01-07 06:53:29 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
2009-01-07 06:53:29 +00:00
|
|
|
* $Id$
|
|
|
|
*/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-11-24 20:17:36 +00:00
|
|
|
#ifndef __TRANSMISSION__
|
2009-01-07 06:53:29 +00:00
|
|
|
#error only libtransmission should #include this header.
|
2008-11-24 20:17:36 +00:00
|
|
|
#endif
|
|
|
|
|
2010-01-14 14:20:49 +00:00
|
|
|
#ifndef TR_COMPLETION_H
|
|
|
|
#define TR_COMPLETION_H
|
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#include "transmission.h"
|
2011-03-28 16:31:05 +00:00
|
|
|
#include "bitfield.h"
|
2012-12-05 17:29:46 +00:00
|
|
|
#include "utils.h" /* tr_getRatio () */
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
typedef struct tr_completion
|
|
|
|
{
|
2011-03-28 16:31:05 +00:00
|
|
|
tr_torrent * tor;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-03-28 16:31:05 +00:00
|
|
|
tr_bitfield blockBitfield;
|
2011-02-15 16:04:56 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/* number of bytes we'll have when done downloading. [0..info.totalSize]
|
|
|
|
DON'T access this directly; it's a lazy field.
|
2012-12-05 17:29:46 +00:00
|
|
|
use tr_cpSizeWhenDone () instead! */
|
2011-03-28 16:31:05 +00:00
|
|
|
uint64_t sizeWhenDoneLazy;
|
|
|
|
|
|
|
|
/* whether or not sizeWhenDone needs to be recalculated */
|
|
|
|
bool sizeWhenDoneIsDirty;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/* number of bytes we'll have when done downloading. [0..info.totalSize]
|
|
|
|
DON'T access this directly; it's a lazy field.
|
2012-12-05 17:29:46 +00:00
|
|
|
use tr_cpHaveValid () instead! */
|
2011-03-28 16:31:05 +00:00
|
|
|
uint64_t haveValidLazy;
|
|
|
|
|
|
|
|
/* whether or not haveValidLazy needs to be recalculated */
|
|
|
|
bool haveValidIsDirty;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/* number of bytes we want or have now. [0..sizeWhenDone] */
|
2011-03-28 16:31:05 +00:00
|
|
|
uint64_t sizeNow;
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
tr_completion;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/**
|
|
|
|
*** Life Cycle
|
|
|
|
**/
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpConstruct (tr_completion *, tr_torrent *);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpBlockInit (tr_completion * cp, const tr_bitfield * blocks);
|
2011-03-29 01:17:18 +00:00
|
|
|
|
|
|
|
static inline void
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_cpDestruct (tr_completion * cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_bitfieldDestruct (&cp->blockBitfield);
|
2011-03-29 01:17:18 +00:00
|
|
|
}
|
2009-01-02 17:01:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*** General
|
|
|
|
**/
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
double tr_cpPercentComplete (const tr_completion * cp);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
double tr_cpPercentDone (const tr_completion * cp);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_completeness tr_cpGetStatus (const tr_completion *);
|
2011-02-15 16:04:56 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint64_t tr_cpHaveValid (const tr_completion *);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint64_t tr_cpSizeWhenDone (const tr_completion *);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
uint64_t tr_cpLeftUntilDone (const tr_completion *);
|
2011-09-26 06:18:48 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpGetAmountDone (const tr_completion * completion,
|
2011-03-28 16:31:05 +00:00
|
|
|
float * tab,
|
2012-12-05 17:29:46 +00:00
|
|
|
int tabCount);
|
2009-01-02 17:01:55 +00:00
|
|
|
|
2011-03-29 01:17:18 +00:00
|
|
|
|
|
|
|
static inline uint64_t
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_cpHaveTotal (const tr_completion * cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
|
|
|
return cp->sizeNow;
|
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_cpHasAll (const tr_completion * cp)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_bitfieldHasAll (&cp->blockBitfield);
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
static inline bool tr_cpHasNone (const tr_completion * cp)
|
2009-01-02 17:01:55 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_bitfieldHasNone (&cp->blockBitfield);
|
2009-01-02 17:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-28 16:31:05 +00:00
|
|
|
*** Pieces
|
2009-01-02 17:01:55 +00:00
|
|
|
**/
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpPieceAdd (tr_completion * cp, tr_piece_index_t i);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpPieceRem (tr_completion * cp, tr_piece_index_t i);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
size_t tr_cpMissingBlocksInPiece (const tr_completion *, tr_piece_index_t);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
size_t tr_cpMissingBytesInPiece (const tr_completion *, tr_piece_index_t);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_cpPieceIsComplete (const tr_completion * cp, tr_piece_index_t i)
|
2011-02-23 03:54:04 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_cpMissingBlocksInPiece (cp, i) == 0;
|
2011-02-23 03:54:04 +00:00
|
|
|
}
|
2009-01-02 17:01:55 +00:00
|
|
|
|
|
|
|
/**
|
2011-03-28 16:31:05 +00:00
|
|
|
*** Blocks
|
2009-01-02 17:01:55 +00:00
|
|
|
**/
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_cpBlockAdd (tr_completion * cp, tr_block_index_t i);
|
2011-03-29 01:17:18 +00:00
|
|
|
|
2011-03-22 15:19:54 +00:00
|
|
|
static inline bool
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_cpBlockIsComplete (const tr_completion * cp, tr_block_index_t i)
|
2009-04-11 03:24:36 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return tr_bitfieldHas (&cp->blockBitfield, i);
|
2009-04-11 03:24:36 +00:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:01:55 +00:00
|
|
|
/***
|
2011-03-28 16:31:05 +00:00
|
|
|
**** Misc
|
2009-01-02 17:01:55 +00:00
|
|
|
***/
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
bool tr_cpFileIsComplete (const tr_completion * cp, tr_file_index_t);
|
2011-03-28 16:31:05 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
void* tr_cpCreatePieceBitfield (const tr_completion * cp, size_t * byte_count);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2011-03-29 01:17:18 +00:00
|
|
|
static inline void
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_cpInvalidateDND (tr_completion * cp)
|
2011-03-29 01:17:18 +00:00
|
|
|
{
|
|
|
|
cp->sizeWhenDoneIsDirty = true;
|
|
|
|
}
|
|
|
|
|
2007-07-30 18:04:10 +00:00
|
|
|
|
2007-06-18 03:40:41 +00:00
|
|
|
#endif
|