Enable more fine grained progress events

At the moment, the progress reporting will jump straight from about 0%
at the start of the download to 100% at the end of the download, without
any updates in between. This is improved by updating after every packet.
This commit is contained in:
Jef Driesen 2017-06-20 21:36:47 +02:00
parent 06259fed19
commit 7ee210f83f

View File

@ -61,7 +61,7 @@ static dc_status_t
uwatec_g2_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
static dc_status_t
receive_data (uwatec_g2_device_t *device, unsigned char *data, unsigned int size)
receive_data (uwatec_g2_device_t *device, dc_event_progress_t *progress, unsigned char *data, unsigned int size)
{
while (size) {
unsigned char buf[PACKET_SIZE];
@ -88,6 +88,13 @@ receive_data (uwatec_g2_device_t *device, unsigned char *data, unsigned int size
ERROR (device->base.context, "receive result buffer too small");
return DC_STATUS_PROTOCOL;
}
// Update and emit a progress event.
if (progress) {
progress->current += len;
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
}
memcpy(data, buf + 1, len);
size -= len;
data += len;
@ -118,7 +125,7 @@ uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], u
return status;
}
status = receive_data (device, answer, asize);
status = receive_data (device, NULL, answer, asize);
if (status != DC_STATUS_SUCCESS) {
ERROR (device->base.context, "Failed to receive the answer.");
return status;
@ -358,16 +365,12 @@ uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
return DC_STATUS_PROTOCOL;
}
rc = receive_data (device, data, length);
rc = receive_data (device, &progress, data, length);
if (rc != DC_STATUS_SUCCESS) {
ERROR (abstract->context, "Failed to receive the answer.");
return rc;
}
// Update and emit a progress event.
progress.current += length;
device_event_emit (&device->base, DC_EVENT_PROGRESS, &progress);
return DC_STATUS_SUCCESS;
}