2010-03-08 04:29:58 +00:00
|
|
|
/*
|
2014-01-18 20:56:57 +00:00
|
|
|
* This file Copyright (C) 2010-2014 Mnemosyne LLC
|
2010-03-08 04:29:58 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-03-08 04:29:58 +00:00
|
|
|
*
|
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
|
|
|
|
2011-04-06 23:27:11 +00:00
|
|
|
enum
|
2011-02-23 06:01:16 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
TR_RECENT_HISTORY_PERIOD_SEC = 60
|
2011-02-23 06:01:16 +00:00
|
|
|
};
|
2011-04-06 23:27:11 +00:00
|
|
|
|
|
|
|
|
2011-02-23 06:01:16 +00:00
|
|
|
typedef struct tr_recentHistory
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
/* these are PRIVATE IMPLEMENTATION details included for composition only.
|
|
|
|
* Don't access these directly! */
|
2011-04-06 23:27:11 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
int newest;
|
2011-04-06 23:27:11 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
struct {
|
|
|
|
unsigned int n;
|
|
|
|
time_t date;
|
|
|
|
} slices[TR_RECENT_HISTORY_PERIOD_SEC];
|
2011-02-23 06:01:16 +00:00
|
|
|
}
|
|
|
|
tr_recentHistory;
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief add a counter to the recent history object.
|
2012-12-05 17:29:46 +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
|
|
|
|
*/
|
2012-12-05 17:29:46 +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.
|
2012-12-05 17:29:46 +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.
|
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
unsigned int tr_historyGet (const tr_recentHistory *, time_t when, unsigned int seconds);
|
2010-03-08 04:29:58 +00:00
|
|
|
|
|
|
|
#endif
|