job: Move progress fields to Job

BlockJob has fields .offset and .len, which are actually misnomers today
because they are no longer tied to block device sizes, but just progress
counters. As such they make a lot of sense in generic Jobs.

This patch moves the fields to Job and renames them to .progress_current
and .progress_total to describe their function better.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Kevin Wolf
2018-05-04 12:17:20 +02:00
parent 2e1795b581
commit 30a5c887bf
9 changed files with 62 additions and 55 deletions

View File

@ -114,6 +114,16 @@ typedef struct Job {
/** True if this job should automatically dismiss itself */
bool auto_dismiss;
/**
* Current progress. The unit is arbitrary as long as the ratio between
* progress_current and progress_total represents the estimated percentage
* of work already done.
*/
int64_t progress_current;
/** Estimated progress_current value at the completion of the job */
int64_t progress_total;
/** ret code passed to job_completed. */
int ret;
@ -304,6 +314,24 @@ void job_ref(Job *job);
*/
void job_unref(Job *job);
/**
* @job: The job that has made progress
* @done: How much progress the job made since the last call
*
* Updates the progress counter of the job.
*/
void job_progress_update(Job *job, uint64_t done);
/**
* @job: The job whose expected progress end value is set
* @remaining: Missing progress (on top of the current progress counter value)
* until the new expected end value is reached
*
* Sets the expected end value of the progress counter of a job so that a
* completion percentage can be calculated when the progress is updated.
*/
void job_progress_set_remaining(Job *job, uint64_t remaining);
/** To be called when a cancelled job is finalised. */
void job_event_cancelled(Job *job);