Browse Source

[job] Report progress of downloader jobs via job_progress()

tags/v0.9.8
Michael Brown 15 years ago
parent
commit
c9c411286a
1 changed files with 21 additions and 2 deletions
  1. 21
    2
      src/core/downloader.c

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

126
  * @v job		Downloader job control interface
126
  * @v job		Downloader job control interface
127
  */
127
  */
128
 static void downloader_job_kill ( struct job_interface *job ) {
128
 static void downloader_job_kill ( struct job_interface *job ) {
129
-	struct downloader *downloader = 
129
+	struct downloader *downloader =
130
 		container_of ( job, struct downloader, job );
130
 		container_of ( job, struct downloader, job );
131
 
131
 
132
 	/* Terminate download */
132
 	/* Terminate download */
133
 	downloader_finished ( downloader, -ECANCELED );
133
 	downloader_finished ( downloader, -ECANCELED );
134
 }
134
 }
135
 
135
 
136
+/**
137
+ * Report progress of download job
138
+ *
139
+ * @v job		Downloader job control interface
140
+ * @v progress		Progress report to fill in
141
+ */
142
+static void downloader_job_progress ( struct job_interface *job,
143
+				      struct job_progress *progress ) {
144
+	struct downloader *downloader =
145
+		container_of ( job, struct downloader, job );
146
+
147
+	/* This is not entirely accurate, since downloaded data may
148
+	 * arrive out of order (e.g. with multicast protocols), but
149
+	 * it's a reasonable first approximation.
150
+	 */
151
+	progress->completed = downloader->pos;
152
+	progress->total = downloader->image->len;
153
+}
154
+
136
 /** Downloader job control interface operations */
155
 /** Downloader job control interface operations */
137
 static struct job_interface_operations downloader_job_operations = {
156
 static struct job_interface_operations downloader_job_operations = {
138
 	.done		= ignore_job_done,
157
 	.done		= ignore_job_done,
139
 	.kill		= downloader_job_kill,
158
 	.kill		= downloader_job_kill,
140
-	.progress	= ignore_job_progress,
159
+	.progress	= downloader_job_progress,
141
 };
160
 };
142
 
161
 
143
 /****************************************************************************
162
 /****************************************************************************

Loading…
Cancel
Save