source: trunk/libtransmission/completion.h @ 12248

Last change on this file since 12248 was 12248, checked in by jordan, 11 years ago

(trunk libT) break the mac build and introduce new crashes.

This is partially to address #4145 "Downloads stuck at 100%" by refactoring the bitset, bitfield, and tr_completion; however, the ripple effect is larger than usual so things may get worse in the short term before getting better.

livings124: to fix the mac build, remove bitset.[ch] from xcode

  • Property svn:keywords set to Date Rev Author Id
File size: 3.5 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 12248 2011-03-28 16:31:05Z 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    /* do we have this block? */
29    tr_bitfield blockBitfield;
30
31    /* number of bytes we'll have when done downloading. [0..info.totalSize]
32       DON'T access this directly; it's a lazy field.
33       use tr_cpSizeWhenDone() instead! */
34    uint64_t sizeWhenDoneLazy;
35
36    /* whether or not sizeWhenDone needs to be recalculated */
37    bool sizeWhenDoneIsDirty;
38
39    /* number of bytes we'll have when done downloading. [0..info.totalSize]
40       DON'T access this directly; it's a lazy field.
41       use tr_cpHaveValid() instead! */
42    uint64_t haveValidLazy;
43
44    /* whether or not haveValidLazy needs to be recalculated */
45    bool haveValidIsDirty;
46
47    /* number of bytes we want or have now. [0..sizeWhenDone] */
48    uint64_t sizeNow;
49}
50tr_completion;
51
52/**
53*** Life Cycle
54**/
55
56void              tr_cpConstruct( tr_completion *, tr_torrent * );
57
58void              tr_cpDestruct( tr_completion * );
59
60/**
61*** General
62**/
63
64double            tr_cpPercentComplete( const tr_completion * cp );
65
66double            tr_cpPercentDone( const tr_completion * cp );
67
68tr_completeness   tr_cpGetStatus( const tr_completion * );
69
70uint64_t          tr_cpHaveValid( const tr_completion * );
71
72uint64_t          tr_cpSizeWhenDone( const tr_completion * );
73
74uint64_t          tr_cpLeftUntilComplete( const tr_completion * );
75
76uint64_t          tr_cpLeftUntilDone( const tr_completion * );
77
78void              tr_cpGetAmountDone( const   tr_completion * completion,
79                                      float                 * tab,
80                                      int                     tabCount );
81
82static inline bool tr_cpHasAll( const tr_completion * cp )
83{
84    return tr_bitfieldHasAll( &cp->blockBitfield );
85}
86
87static inline bool tr_cpHasNone( const tr_completion * cp )
88{
89    return tr_bitfieldHasNone( &cp->blockBitfield );
90}
91
92static inline uint64_t tr_cpHaveTotal( const tr_completion * cp )
93{
94    return cp->sizeNow;
95}
96
97/**
98***  Pieces
99**/
100
101void    tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
102
103void    tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
104
105size_t  tr_cpMissingBlocksInPiece( const tr_completion *, tr_piece_index_t );
106
107size_t  tr_cpMissingBytesInPiece ( const tr_completion *, tr_piece_index_t );
108
109static inline bool
110tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t i )
111{
112    return tr_cpMissingBlocksInPiece( cp, i ) == 0;
113}
114
115/**
116***  Blocks
117**/
118
119static inline bool
120tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
121{
122    return tr_bitfieldHas( &cp->blockBitfield, i );
123}
124
125void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
126
127bool  tr_cpBlockInit( tr_completion * cp, const tr_bitfield * blocks );
128
129/***
130****  Misc
131***/
132
133bool  tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
134
135void  tr_cpInvalidateDND( tr_completion * );
136
137void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
138
139
140#endif
Note: See TracBrowser for help on using the repository browser.