source: trunk/libtransmission/completion.h

Last change on this file was 14724, checked in by jordan, 5 years ago

use '#pragma once' instead of #ifndef..#define..#endif guards

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