1 #ifndef EL__NETWORK_PROGRESS_H
2 #define EL__NETWORK_PROGRESS_H
3 
4 #include "main/timer.h" /* timer_id_T */
5 #include "util/time.h"
6 
7 #define CURRENT_SPD_SEC 	50	/* number of seconds */
8 
9 struct progress {
10 	timeval_T elapsed;
11 	timeval_T last_time;
12 	timeval_T dis_b;
13 	timeval_T estimated_time;
14 
15 	int average_speed;	/* bytes/second */
16 	int current_speed;	/* bytes/second */
17 
18 	unsigned int valid:1;
19 	off_t size;
20 	off_t loaded, last_loaded;
21 	off_t cur_loaded;
22 
23 	/* This is offset where the download was resumed possibly */
24 	/* progress->start == -1 means normal session, not download
25 	 *            ==  0 means download
26 	 *             >  0 means resume
27 	 * --witekfl */
28 	off_t start;
29 	/* This is absolute position in the stream
30 	 * (relative_position = pos - start) (maybe our fictional
31 	 * relative_position is equiv to loaded, but I'd rather not rely on it
32 	 * --pasky). */
33 	off_t pos;
34 	/* If this is non-zero, it indicates that we should seek in the
35 	 * stream to the value inside before the next write (and zero this
36 	 * counter then, obviously). */
37 	off_t seek;
38 
39 	timer_id_T timer;
40 	void (*timer_func)(void *);
41 	void *timer_func_data;
42 
43 	int data_in_secs[CURRENT_SPD_SEC];
44 };
45 
46 struct progress *init_progress(off_t start);
47 void done_progress(struct progress *progress);
48 void update_progress(struct progress *progress, off_t loaded, off_t size, off_t pos);
49 void start_update_progress(struct progress *progress, void (*timer_func)(void *), void *timer_func_data);
50 
51 int has_progress(struct progress *progress);
52 
53 #endif
54