jigdo API
Progress Class Reference
Keep track of statistics: How many % of download done, average speed, ETA. More...
#include <progress.hh>
Public Member Functions | |
Progress () | |
~Progress () | |
void | setCurrentSize (uint64 x) |
Set amount of data fetched so far. | |
uint64 | currentSize () const |
Read amount of data fetched so far. | |
void | setDataSize (uint64 x) |
Set total amount of data - default is 0 (unknown). | |
uint64 | dataSize () const |
Read total amount of data - default is 0 (unknown). | |
void | tick (const GTimeVal &now, int millisecs) |
Call this at regular intervals: At least every SPEED_TICK_INTERVAL milliseconds, but can also be more often, preferably in such a way that every nth call happens every SPEED_TICK_INTERVAL milliseconds. | |
void | setAutoTick (bool enable) |
Register/unregister a callback function with glib which automatically calls tick() every SPEED_TICK_INTERVAL milliseconds. | |
bool | autoTick () |
Is autotick enabled for this object? | |
int | speed (const GTimeVal &now) const |
Return estimated bytes/sec for (roughly) last few secs (-1 for unknown). | |
int | timeLeft (const GTimeVal &now) const |
Return estimated remaining time in seconds (-1 for unknown). | |
void | appendProgress (string *s) const |
Convenience method: Create long progress string like "50%, 50kB of 100kB (3333 of 6666 bytes)". | |
void | appendSpeed (string *s, int speed, int timeLeft) const |
Convenience method: Create long string with speed and estimated time of arrival like "00:01:59 remaining, 100kB/sec". | |
void | reset () |
Reset internal state of "time left" calculation. | |
ostream & | put (ostream &s) const |
Static Public Member Functions | |
static void | appendSize (string *s, uint64 size) |
Append to s something like "9999B", "9999kB", "9999MB", "99.9MB". | |
static void | appendSizes (string *s, uint64 size, uint64 total) |
Append "50kB" if size not known, else "50kB of 10MB". | |
Static Public Attributes | |
static const int | SPEED_TICK_INTERVAL = 3000 |
Detailed Description
Keep track of statistics: How many % of download done, average speed, ETA.Constructor & Destructor Documentation
Progress::Progress | ( | ) | [inline] |
References reset().
Progress::~Progress | ( | ) | [inline] |
References setAutoTick().
Member Function Documentation
void Progress::setCurrentSize | ( | uint64 | x | ) | [inline] |
uint64 Progress::currentSize | ( | ) | const [inline] |
Read amount of data fetched so far.
Referenced by GtkSingleUrl::on_closeButton_clicked(), GtkSingleUrl::on_restartButton_clicked(), GtkSingleUrl::on_startButton_clicked(), GtkSingleUrl::percentDone(), reset(), Job::SingleUrl::resumePossible(), and GtkSingleUrl::stop().
void Progress::setDataSize | ( | uint64 | x | ) | [inline] |
Set total amount of data - default is 0 (unknown).
Referenced by Job::CachedUrl::CachedUrl(), and Job::SingleUrl::run().
uint64 Progress::dataSize | ( | ) | const [inline] |
Read total amount of data - default is 0 (unknown).
Referenced by GtkSingleUrl::percentDone(), Job::SingleUrl::resumePossible(), and Job::CachedUrl::run().
void Progress::tick | ( | const GTimeVal & | now, | |
int | millisecs | |||
) |
Call this at regular intervals: At least every SPEED_TICK_INTERVAL milliseconds, but can also be more often, preferably in such a way that every nth call happens every SPEED_TICK_INTERVAL milliseconds.
- Parameters:
-
now Current time: {GTimeVal now;g_get_current_time(&now);} Use same "now" value for related calls to timeLeft(), tick() etc. millisecs Number of milliseconds elapsed since last call to this function (approximate)
References SPEED_TICK_INTERVAL.
void Progress::setAutoTick | ( | bool | enable | ) |
Register/unregister a callback function with glib which automatically calls tick() every SPEED_TICK_INTERVAL milliseconds.
This only registers one function which traverses the list of all Progress objects with autoTick==true. ~Progress automatically unregisters the autotick callback if necessary.
- Parameters:
-
enable true to call tick() automatically, false to stop calling it.
References autoTick(), debug, next, Paranoid, prev, and SPEED_TICK_INTERVAL.
Referenced by Job::SingleUrl::pause(), and ~Progress().
bool Progress::autoTick | ( | ) | [inline] |
int Progress::speed | ( | const GTimeVal & | now | ) | const |
Return estimated bytes/sec for (roughly) last few secs (-1 for unknown).
References debug.
Referenced by GtkSingleUrl::on_restartButton_clicked(), and timeLeft().
int Progress::timeLeft | ( | const GTimeVal & | now | ) | const |
void Progress::appendSize | ( | string * | s, | |
uint64 | size | |||
) | [static] |
Append to s something like "9999B", "9999kB", "9999MB", "99.9MB".
Referenced by appendProgress(), appendSizes(), and appendSpeed().
void Progress::appendSizes | ( | string * | s, | |
uint64 | size, | |||
uint64 | total | |||
) | [static] |
void Progress::appendProgress | ( | string * | s | ) | const |
Convenience method: Create long progress string like "50%, 50kB of 100kB (3333 of 6666 bytes)".
References _, append(), and appendSize().
void Progress::appendSpeed | ( | string * | s, | |
int | speed, | |||
int | timeLeft | |||
) | const |
Convenience method: Create long string with speed and estimated time of arrival like "00:01:59 remaining, 100kB/sec".
References _, appendSize(), buf, and BUF_LEN.
void Progress::reset | ( | ) |
Reset internal state of "time left" calculation.
Does not touch currentSize or dataSize. Use this e.g. when continuing a download after it has been paused. Also records the current time to signify the start of the download, so don't wait too long between calling this and actually (re)starting the download. Important: Use setCurrentSize(0);reset(); and not the other way round, or the speed calculation will go belly up.
References currentSize(), and SPEED_TICK_INTERVAL.
Referenced by Job::SingleUrl::cont(), Progress(), and Job::SingleUrl::run().
ostream & Progress::put | ( | ostream & | s | ) | const |
Member Data Documentation
const int Progress::SPEED_TICK_INTERVAL = 3000 [static] |
Referenced by reset(), setAutoTick(), and tick().
The documentation for this class was generated from the following files:
- util/progress.hh
- util/progress.cc
Generated on Tue Sep 23 14:27:43 2008 for jigdo by
