timer.h revision 9663:ace9a2ac3683
1/*
2    libparted - a library for manipulating disk partitions
3    Copyright (C) 2001, 2002, 2007 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * \addtogroup PedTimer
21 * @{
22 */
23
24/** \file timer.h */
25
26#ifndef PED_TIMER_H_INCLUDED
27#define PED_TIMER_H_INCLUDED
28
29#include <time.h>
30
31typedef struct _PedTimer PedTimer;
32
33typedef void PedTimerHandler (PedTimer* timer, void* context);
34
35/*
36 * Structure keeping track of progress and time
37 */
38struct _PedTimer {
39	float			frac;		/**< fraction of operation done */
40	time_t			start;		/**< time of start of op */
41	time_t			now;		/**< time of last update (now!) */
42	time_t			predicted_end;	/**< expected finish time */
43	const char*		state_name;	/**< eg: "copying data" */
44	PedTimerHandler*	handler;	/**< who to notify on updates */
45	void*			context;	/**< context to pass to handler */
46};
47
48extern PedTimer* ped_timer_new (PedTimerHandler* handler, void* context);
49extern void ped_timer_destroy (PedTimer* timer);
50
51/* a nested timer automatically notifies it's parent.  You should only
52 * create one when you are going to use it (not before)
53 */
54extern PedTimer* ped_timer_new_nested (PedTimer* parent, float nest_frac);
55extern void ped_timer_destroy_nested (PedTimer* timer);
56
57extern void ped_timer_touch (PedTimer* timer);
58extern void ped_timer_reset (PedTimer* timer);
59extern void ped_timer_update (PedTimer* timer, float new_frac);
60extern void ped_timer_set_state_name (PedTimer* timer, const char* state_name);
61
62#endif /* PED_TIMER_H_INCLUDED */
63
64
65/** @} */
66