source: trunk/libtransmission/completion.h @ 12918

Last change on this file since 12918 was 12918, checked in by jordan, 10 years ago

(trunk libT) add several more tr_completion assertions to smoke out the (sizeWhenDone() < sizeNow()) error reported in the forums

  • Property svn:keywords set to Date Rev Author Id
File size: 3.6 KB
Line 
1/*
2 * This file Copyright (C) Mnemosyne LLC
3 *
4 * This file is licensed by the GPL version 2. Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id: completion.h 12918 2011-09-26 06:18:48Z jordan $
11 */
12
13#ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_COMPLETION_H
18#define TR_COMPLETION_H
19
20#include "transmission.h"
21#include "bitfield.h"
22#include "utils.h" /* tr_getRatio() */
23
24typedef struct tr_completion
25{
26    tr_torrent * tor;
27
28    tr_bitfield blockBitfield;
29
30    /* number of bytes we'll have when done downloading. [0..info.totalSize]
31       DON'T access this directly; it's a lazy field.
32       use tr_cpSizeWhenDone() instead! */
33    uint64_t sizeWhenDoneLazy;
34
35    /* whether or not sizeWhenDone needs to be recalculated */
36    bool sizeWhenDoneIsDirty;
37
38    /* number of bytes we'll have when done downloading. [0..info.totalSize]
39       DON'T access this directly; it's a lazy field.
40       use tr_cpHaveValid() instead! */
41    uint64_t haveValidLazy;
42
43    /* whether or not haveValidLazy needs to be recalculated */
44    bool haveValidIsDirty;
45
46    /* number of bytes we want or have now. [0..sizeWhenDone] */
47    uint64_t sizeNow;
48}
49tr_completion;
50
51/**
52*** Life Cycle
53**/
54
55void  tr_cpConstruct( tr_completion *, tr_torrent * );
56
57void  tr_cpBlockInit( tr_completion * cp, const tr_bitfield * blocks );
58
59static inline void
60tr_cpDestruct( tr_completion * cp )
61{
62    tr_bitfieldDestruct( &cp->blockBitfield );
63}
64
65/**
66*** General
67**/
68
69double            tr_cpPercentComplete( const tr_completion * cp );
70
71double            tr_cpPercentDone( const tr_completion * cp );
72
73tr_completeness   tr_cpGetStatus( const tr_completion * );
74
75uint64_t          tr_cpHaveValid( const tr_completion * );
76
77uint64_t          tr_cpSizeWhenDone( const tr_completion * );
78
79uint64_t          tr_cpLeftUntilDone( const tr_completion * );
80
81void              tr_cpGetAmountDone( const   tr_completion * completion,
82                                      float                 * tab,
83                                      int                     tabCount );
84
85
86static inline uint64_t
87tr_cpHaveTotal( const tr_completion * cp )
88{
89    return cp->sizeNow;
90}
91
92static inline uint64_t
93tr_cpLeftUntilComplete( const tr_completion * cp )
94{
95    return tr_torrentInfo(cp->tor)->totalSize - cp->sizeNow;
96}
97
98static inline bool tr_cpHasAll( const tr_completion * cp )
99{
100    return tr_bitfieldHasAll( &cp->blockBitfield );
101}
102
103static inline bool tr_cpHasNone( const tr_completion * cp )
104{
105    return tr_bitfieldHasNone( &cp->blockBitfield );
106}
107
108/**
109***  Pieces
110**/
111
112void    tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
113
114void    tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
115
116size_t  tr_cpMissingBlocksInPiece( const tr_completion *, tr_piece_index_t );
117
118size_t  tr_cpMissingBytesInPiece ( const tr_completion *, tr_piece_index_t );
119
120static inline bool
121tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t i )
122{
123    return tr_cpMissingBlocksInPiece( cp, i ) == 0;
124}
125
126/**
127***  Blocks
128**/
129
130void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
131
132static inline bool
133tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
134{
135    return tr_bitfieldHas( &cp->blockBitfield, i );
136}
137
138/***
139****  Misc
140***/
141
142bool  tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
143
144void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
145
146static inline void
147tr_cpInvalidateDND( tr_completion * cp )
148{
149    cp->sizeWhenDoneIsDirty = true;
150}
151
152
153#endif
Note: See TracBrowser for help on using the repository browser.