source: trunk/libtransmission/completion.h @ 14169

Last change on this file since 14169 was 14169, checked in by jordan, 8 years ago

add inline wrapper functions to tr_torrent to decouple the rest of the code from tr_completion

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