Browse Source

[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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
5674a3c087
3 changed files with 20 additions and 9 deletions
  1. 5
    2
      src/core/downloader.c
  2. 12
    4
      src/core/job.c
  3. 3
    3
      src/include/ipxe/job.h

+ 5
- 2
src/core/downloader.c View File

131
  *
131
  *
132
  * @v downloader	Downloader
132
  * @v downloader	Downloader
133
  * @v progress		Progress report to fill in
133
  * @v progress		Progress report to fill in
134
+ * @ret ongoing_rc	Ongoing job status code (if known)
134
  */
135
  */
135
-static void downloader_progress ( struct downloader *downloader,
136
-				  struct job_progress *progress ) {
136
+static int downloader_progress ( struct downloader *downloader,
137
+				 struct job_progress *progress ) {
137
 
138
 
138
 	/* This is not entirely accurate, since downloaded data may
139
 	/* This is not entirely accurate, since downloaded data may
139
 	 * arrive out of order (e.g. with multicast protocols), but
140
 	 * arrive out of order (e.g. with multicast protocols), but
141
 	 */
142
 	 */
142
 	progress->completed = downloader->pos;
143
 	progress->completed = downloader->pos;
143
 	progress->total = downloader->image->len;
144
 	progress->total = downloader->image->len;
145
+
146
+	return 0;
144
 }
147
 }
145
 
148
 
146
 /****************************************************************************
149
 /****************************************************************************

+ 12
- 4
src/core/job.c View File

34
  *
34
  *
35
  * @v intf		Object interface
35
  * @v intf		Object interface
36
  * @v progress		Progress data to fill in
36
  * @v progress		Progress data to fill in
37
+ * @ret ongoing_rc	Ongoing job status code (if known)
37
  */
38
  */
38
-void job_progress ( struct interface *intf, struct job_progress *progress ) {
39
+int job_progress ( struct interface *intf, struct job_progress *progress ) {
39
 	struct interface *dest;
40
 	struct interface *dest;
40
 	job_progress_TYPE ( void * ) *op =
41
 	job_progress_TYPE ( void * ) *op =
41
 		intf_get_dest_op ( intf, job_progress, &dest );
42
 		intf_get_dest_op ( intf, job_progress, &dest );
42
 	void *object = intf_object ( dest );
43
 	void *object = intf_object ( dest );
44
+	int ongoing_rc;
43
 
45
 
44
 	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " job_progress\n",
46
 	DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " job_progress\n",
45
 	       INTF_INTF_DBG ( intf, dest ) );
47
 	       INTF_INTF_DBG ( intf, dest ) );
46
 
48
 
49
+	/* Initialise progress to zero */
50
+	memset ( progress, 0, sizeof ( *progress ) );
51
+
47
 	if ( op ) {
52
 	if ( op ) {
48
-		op ( object, progress );
53
+		ongoing_rc = op ( object, progress );
49
 	} else {
54
 	} else {
50
-		/* Default is to mark progress as zero */
51
-		memset ( progress, 0, sizeof ( *progress ) );
55
+		/* Default is to leave progress as zero and have no
56
+		 * known return status code.
57
+		 */
58
+		ongoing_rc = 0;
52
 	}
59
 	}
53
 
60
 
54
 	intf_put ( dest );
61
 	intf_put ( dest );
62
+	return ongoing_rc;
55
 }
63
 }

+ 3
- 3
src/include/ipxe/job.h View File

30
 	unsigned long total;
30
 	unsigned long total;
31
 };
31
 };
32
 
32
 
33
-extern void job_progress ( struct interface *intf,
34
-			   struct job_progress *progress );
33
+extern int job_progress ( struct interface *intf,
34
+			  struct job_progress *progress );
35
 #define job_progress_TYPE( object_type ) \
35
 #define job_progress_TYPE( object_type ) \
36
-	typeof ( void ( object_type, struct job_progress *progress ) )
36
+	typeof ( int ( object_type, struct job_progress *progress ) )
37
 
37
 
38
 #endif /* _IPXE_JOB_H */
38
 #endif /* _IPXE_JOB_H */

Loading…
Cancel
Save