2010-03-08 04:29:58 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2010-03-08 04:29:58 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2010-03-08 04:29:58 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
2010-10-01 13:33:39 +00:00
|
|
|
* $Id$
|
2010-03-08 04:29:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TRANSMISSION__
|
|
|
|
#error only libtransmission should #include this header.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef TR_RECENT_HISTORY_H
|
|
|
|
#define TR_RECENT_HISTORY_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic short-term memory object that remembers how many times
|
|
|
|
* something happened over the last N seconds.
|
2010-12-12 16:43:19 +00:00
|
|
|
*
|
2010-03-08 04:29:58 +00:00
|
|
|
* For example, it could count how many are bytes transferred
|
|
|
|
* to estimate the speed over the last N seconds.
|
|
|
|
*/
|
2011-02-23 06:01:16 +00:00
|
|
|
|
|
|
|
struct tr_history_slice
|
|
|
|
{
|
|
|
|
unsigned int n;
|
|
|
|
time_t date;
|
|
|
|
};
|
|
|
|
typedef struct tr_recentHistory
|
|
|
|
{
|
|
|
|
/* these are PRIVATE IMPLEMENTATION details included for composition only.
|
|
|
|
* Don't access these directly! */
|
|
|
|
int newest;
|
|
|
|
int sliceCount;
|
|
|
|
unsigned int precision;
|
|
|
|
struct tr_history_slice * slices;
|
|
|
|
}
|
|
|
|
tr_recentHistory;
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-23 06:01:16 +00:00
|
|
|
* @brief construct a new tr_recentHistory object
|
2010-03-08 04:29:58 +00:00
|
|
|
* @param seconds how many seconds of history this object should remember
|
2010-11-16 15:17:34 +00:00
|
|
|
* @param precision how precise the history should be, in seconds
|
|
|
|
* For a precision of 10 seconds and a history of 2 minutes, makes 12 bins.
|
2010-03-08 04:29:58 +00:00
|
|
|
*/
|
2011-02-23 06:01:16 +00:00
|
|
|
void tr_historyConstruct( tr_recentHistory *, unsigned int seconds, unsigned int precision );
|
2010-03-08 04:29:58 +00:00
|
|
|
|
2011-02-23 06:01:16 +00:00
|
|
|
/** @brief destruct an existing tr_recentHistory object. */
|
|
|
|
void tr_historyDestruct( tr_recentHistory * );
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief add a counter to the recent history object.
|
2010-11-16 15:17:34 +00:00
|
|
|
* @param when the current time in sec, such as from tr_time()
|
2010-03-08 04:29:58 +00:00
|
|
|
* @param n how many items to add to the history's counter
|
|
|
|
*/
|
2010-11-16 15:17:34 +00:00
|
|
|
void tr_historyAdd( tr_recentHistory *, time_t when, unsigned int n );
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief count how many events have occurred in the last N seconds.
|
2010-11-16 15:17:34 +00:00
|
|
|
* @param when the current time in sec, such as from tr_time()
|
2010-03-08 04:29:58 +00:00
|
|
|
* @param seconds how many seconds to count back through.
|
|
|
|
*/
|
2010-11-16 15:17:34 +00:00
|
|
|
unsigned int tr_historyGet( const tr_recentHistory *, time_t when, unsigned int seconds );
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
#endif
|