From d532be187afa1b6fac8935f243be918dccc231d9 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 27 Aug 2019 12:19:32 -0700 Subject: [PATCH] Deepblu Cosmiq+: stop downloading once we've seen the dives already .. and also support cancellation of dive downloading in the middle. The Cosmiq+ doesn't remember all that many dives, but BLE is slow and there's no point in downloading more than necessary. I'll look at fingerprinting next, so that we can avoid downloading the profile data if we have already seen the header. That's a further small optimization. Signed-off-by: Linus Torvalds --- src/deepblu.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/deepblu.c b/src/deepblu.c index eff630e..fd3b938 100644 --- a/src/deepblu.c +++ b/src/deepblu.c @@ -431,8 +431,10 @@ deepblu_download_dive(deepblu_device_t *device, unsigned char nr, dc_dive_callba if (status != DC_STATUS_SUCCESS) return status; - if (callback) - callback(profile, profile_len+256, header, header_len, userdata); + if (callback) { + if (!callback(profile, profile_len+256, header, header_len, userdata)) + return DC_STATUS_DONE; + } return DC_STATUS_SUCCESS; } @@ -459,9 +461,21 @@ deepblu_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void device_event_emit(abstract, DC_EVENT_PROGRESS, &progress); for (i = 1; i <= nrdives; i++) { + if (device_is_cancelled(abstract)) { + dc_status_set_error(&status, DC_STATUS_CANCELLED); + break; + } + status = deepblu_download_dive(device, i, callback, userdata); - if (status != DC_STATUS_SUCCESS) + switch (status) { + case DC_STATUS_DONE: + i = nrdives; + break; + case DC_STATUS_SUCCESS: + break; + default: return status; + } progress.current = i; device_event_emit(abstract, DC_EVENT_PROGRESS, &progress); }