source: trunk/libtransmission/history.h @ 12013

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

(trunk libT) #4051 "Use composition for the tr_history fields in tr_peer" -- fixed.

If we use composition on these objects we can save a handful of pointers per peer. This isn't a big deal, but it's an easy/safe change to do.

  • Property svn:keywords set to Date Rev Author Id
File size: 2.1 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: history.h 12013 2011-02-23 06:01:16Z jordan $
11 */
12
13#ifndef __TRANSMISSION__
14 #error only libtransmission should #include this header.
15#endif
16
17#ifndef TR_RECENT_HISTORY_H
18#define TR_RECENT_HISTORY_H
19
20/**
21 * A generic short-term memory object that remembers how many times
22 * something happened over the last N seconds.
23 *
24 * For example, it could count how many are bytes transferred
25 * to estimate the speed over the last N seconds.
26 */
27
28struct tr_history_slice
29{
30    unsigned int n;
31    time_t date;
32};
33typedef struct tr_recentHistory
34{
35    /* these are PRIVATE IMPLEMENTATION details included for composition only.
36     * Don't access these directly! */
37    int newest;
38    int sliceCount;
39    unsigned int precision;
40    struct tr_history_slice * slices;
41}
42tr_recentHistory;
43
44/**
45 * @brief construct a new tr_recentHistory object
46 * @param seconds how many seconds of history this object should remember
47 * @param precision how precise the history should be, in seconds
48 *        For a precision of 10 seconds and a history of 2 minutes, makes 12 bins.
49 */
50void tr_historyConstruct( tr_recentHistory *, unsigned int seconds, unsigned int precision );
51
52/** @brief destruct an existing tr_recentHistory object. */
53void tr_historyDestruct( tr_recentHistory * );
54
55/**
56 * @brief add a counter to the recent history object.
57 * @param when the current time in sec, such as from tr_time()
58 * @param n how many items to add to the history's counter
59 */
60void tr_historyAdd( tr_recentHistory *, time_t when, unsigned int n );
61
62/**
63 * @brief count how many events have occurred in the last N seconds.
64 * @param when the current time in sec, such as from tr_time()
65 * @param seconds how many seconds to count back through.
66 */
67unsigned int tr_historyGet( const tr_recentHistory *, time_t when, unsigned int seconds );
68
69#endif
Note: See TracBrowser for help on using the repository browser.