david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[job] Allow job_progress() to return an ongoing job status code, if known

Some background jobs have a meaningful ongoing status code (e.g. the
current link status for a job waiting for a network link to come up).
Allow this to be exposed via the job_progress() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-11-01 15:05:16 +00:00
parent a3346e3587
commit 5674a3c087
3 changed files with 20 additions and 9 deletions

View File

@ -131,9 +131,10 @@ static int downloader_ensure_size ( struct downloader *downloader,
*
* @v downloader Downloader
* @v progress Progress report to fill in
* @ret ongoing_rc Ongoing job status code (if known)
*/
static void downloader_progress ( struct downloader *downloader,
struct job_progress *progress ) {
static int downloader_progress ( struct downloader *downloader,
struct job_progress *progress ) {
/* This is not entirely accurate, since downloaded data may
* arrive out of order (e.g. with multicast protocols), but
@ -141,6 +142,8 @@ static void downloader_progress ( struct downloader *downloader,
*/
progress->completed = downloader->pos;
progress->total = downloader->image->len;
return 0;
}
/****************************************************************************

View File

@ -34,22 +34,30 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
* @v intf Object interface
* @v progress Progress data to fill in
* @ret ongoing_rc Ongoing job status code (if known)
*/
void job_progress ( struct interface *intf, struct job_progress *progress ) {
int job_progress ( struct interface *intf, struct job_progress *progress ) {
struct interface *dest;
job_progress_TYPE ( void * ) *op =
intf_get_dest_op ( intf, job_progress, &dest );
void *object = intf_object ( dest );
int ongoing_rc;
DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " job_progress\n",
INTF_INTF_DBG ( intf, dest ) );
/* Initialise progress to zero */
memset ( progress, 0, sizeof ( *progress ) );
if ( op ) {
op ( object, progress );
ongoing_rc = op ( object, progress );
} else {
/* Default is to mark progress as zero */
memset ( progress, 0, sizeof ( *progress ) );
/* Default is to leave progress as zero and have no
* known return status code.
*/
ongoing_rc = 0;
}
intf_put ( dest );
return ongoing_rc;
}

View File

@ -30,9 +30,9 @@ struct job_progress {
unsigned long total;
};
extern void job_progress ( struct interface *intf,
struct job_progress *progress );
extern int job_progress ( struct interface *intf,
struct job_progress *progress );
#define job_progress_TYPE( object_type ) \
typeof ( void ( object_type, struct job_progress *progress ) )
typeof ( int ( object_type, struct job_progress *progress ) )
#endif /* _IPXE_JOB_H */