source: trunk/libtransmission/completion.h @ 13310

Last change on this file since 13310 was 13310, checked in by jordan, 9 years ago

(trunk libT) #4888: when scraping magnet links, don't send a left=0 argument to the tracker.

  • 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 13310 2012-05-20 14:14:59Z 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 bool tr_cpHasAll( const tr_completion * cp )
93{
94    return tr_bitfieldHasAll( &cp->blockBitfield );
95}
96
97static inline bool tr_cpHasNone( const tr_completion * cp )
98{
99    return tr_bitfieldHasNone( &cp->blockBitfield );
100}
101
102/**
103***  Pieces
104**/
105
106void    tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i );
107
108void    tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i );
109
110size_t  tr_cpMissingBlocksInPiece( const tr_completion *, tr_piece_index_t );
111
112size_t  tr_cpMissingBytesInPiece ( const tr_completion *, tr_piece_index_t );
113
114static inline bool
115tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t i )
116{
117    return tr_cpMissingBlocksInPiece( cp, i ) == 0;
118}
119
120/**
121***  Blocks
122**/
123
124void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
125
126static inline bool
127tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
128{
129    return tr_bitfieldHas( &cp->blockBitfield, i );
130}
131
132/***
133****  Misc
134***/
135
136bool  tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
137
138void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
139
140static inline void
141tr_cpInvalidateDND( tr_completion * cp )
142{
143    cp->sizeWhenDoneIsDirty = true;
144}
145
146
147#endif
Note: See TracBrowser for help on using the repository browser.