timer.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/*
libparted - a library for manipulating disk partitions
Copyright (C) 2001, 2007 Free Software Foundation, Inc.
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file timer.c */
/**
* \addtogroup PedTimer
*
* \brief A PedTimer keeps track of the progress of a single (possibly
* compound) operation.
*
* The user of libparted constructs a PedTimer, and passes it to libparted
* functions that are likely to be expensive operations
* (like ped_file_system_resize). Use of timers is optional... you may
* pass NULL instead.
*
* When you create a PedTimer, you must specify a timer handler function.
* This will be called when there's an update on how work is progressing.
*
* Timers may be nested. When a timer is constructed, you can choose
* to assign it a parent, along with an estimate of what proportion of
* the total (parent's) time will be used in the nested operation. In
* this case, the nested timer's handler is internal to libparted,
* and simply updates the parent's progress, and calls its handler.
*
* @{
*/
#include <config.h>
#define PED_TIMER_START_DELAY 2
typedef struct {
float nest_frac;
float start_frac;
/**
* \brief Creates a timer.
*
* Context will be passed in the \p context
* argument to the \p handler, when it is invoked.
*
* \return a new PedTimer
*/
{
if (!timer)
return NULL;
return timer;
}
/**
* \brief Destroys a \p timer.
*/
void
{
if (!timer)
return;
}
/* This function is used by ped_timer_new_nested() as the timer->handler
* function.
*/
static void
{
}
/**
* \brief Creates a new nested timer.
*
* This function creates a "nested" timer that describes the progress
* of a subtask. \p parent is the parent timer, and \p nested_frac is
* the estimated proportion (between 0 and 1) of the time that will be
* spent doing the nested timer's operation. The timer should only be
* constructed immediately prior to starting the nested operation.
* (It will be inaccurate, otherwise).
* Updates to the progress of the subtask are propagated
* back through to the parent task's timer.
*
* \return nested timer
*/
{
if (!parent)
return NULL;
if (!context)
return NULL;
}
/**
* \brief Destroys a nested \p timer.
*/
void
{
if (!timer)
return;
}
/**
* \internal
*
* \brief This function calls the update handler, making sure that it has
* the latest time.
*
* First it updates \p timer->now and recomputes \p timer->predicted_end,
* and then calls the handler.
*/
void
{
if (!timer)
return;
}
/**
* \internal
*
* \brief This function sets the \p timer into a "start of task" position.
*
* It resets the \p timer, by setting \p timer->start and \p timer->now
* to the current time.
*/
void
{
if (!timer)
return;
}
/**
* \internal
*
* \brief This function tells a \p timer what fraction \p frac of the task
* has been completed.
*
* Sets the new \p timer->frac, and calls ped_timer_touch().
*/
void
{
if (!timer)
return;
if (frac)
}
/**
* \internal
*
* \brief This function changes the description of the current task that the
* \p timer describes.
*
* Sets a new name - \p state_name - for the current "phase" of the operation,
* and calls ped_timer_touch().
*/
void
{
if (!timer)
return;
}
/** @} */