diff --git a/src/device.h b/src/device.h index 0b8a25d..88af6f6 100644 --- a/src/device.h +++ b/src/device.h @@ -32,7 +32,7 @@ typedef enum device_status_t { typedef struct device_t device_t; -typedef void (*dive_callback_t) (const unsigned char *data, unsigned int size, void *userdata); +typedef int (*dive_callback_t) (const unsigned char *data, unsigned int size, void *userdata); device_type_t device_get_type (device_t *device); diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 775868b..1679b4b 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -464,8 +464,8 @@ oceanic_atom2_device_foreach (device_t *abstract, dive_callback_t callback, void // Copy the logbook data to the profile. memcpy (profile, current, 8); - if (callback) - callback (profile, profile_len + 8, userdata); + if (callback && !callback (profile, profile_len + 8, userdata)) + return DEVICE_STATUS_SUCCESS; // Advance to the next logbook entry. current -= (OCEANIC_ATOM2_PACKET_SIZE / 2); diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 39af238..5f1140c 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -315,8 +315,8 @@ reefnet_sensuspro_extract_dives (const unsigned char data[], unsigned int size, unsigned int offset = current + 10; // Skip non-sample data. while (offset + 2 <= previous) { if (memcmp (data + offset, footer, sizeof (footer)) == 0) { - if (callback) - callback (data + current, offset + 2 - current, userdata); + if (callback && !callback (data + current, offset + 2 - current, userdata)) + return DEVICE_STATUS_SUCCESS; found = 1; break; diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index 9b55c73..541a5b1 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -639,8 +639,10 @@ reefnet_sensusultra_device_foreach (device_t *abstract, dive_callback_t callback return DEVICE_STATUS_ERROR; } - if (callback) - callback (data + current, offset + 4 - current, userdata); + if (callback && !callback (data + current, offset + 4 - current, userdata)) { + free (data); + return DEVICE_STATUS_SUCCESS; + } // Prepare for the next dive. previous = current; diff --git a/src/suunto_common.c b/src/suunto_common.c index c061ad9..32af80a 100644 --- a/src/suunto_common.c +++ b/src/suunto_common.c @@ -40,8 +40,8 @@ suunto_common_extract_dives (const unsigned char data[], unsigned int begin, uns memcpy (buffer, data + current, len); } - if (callback) - callback (buffer, len, userdata); + if (callback && !callback (buffer, len, userdata)) + return DEVICE_STATUS_SUCCESS; previous = current; } diff --git a/src/suunto_d9.c b/src/suunto_d9.c index 737894c..965b2a6 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -478,8 +478,8 @@ suunto_d9_device_foreach (device_t *abstract, dive_callback_t callback, void *us message ("\"\n"); #endif - if (callback) - callback (data + remaining + 4, size - 4, userdata); + if (callback && !callback (data + remaining + 4, size - 4, userdata)) + return DEVICE_STATUS_SUCCESS; } assert (remaining == 0); assert (available == 0); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 15a92e6..a761c96 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -551,8 +551,8 @@ suunto_vyper_device_foreach (device_t *abstract, dive_callback_t callback, void unsigned int ndives = 0; unsigned int offset = 0; while ((rc = suunto_vyper_device_read_dive (abstract, data + offset, sizeof (data) - offset, (ndives == 0))) > 0) { - if (callback) - callback (data + offset, rc, userdata); + if (callback && !callback (data + offset, rc, userdata)) + return DEVICE_STATUS_SUCCESS; ndives++; offset += rc; diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index b0e7896..19f8da7 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -465,8 +465,8 @@ suunto_vyper2_device_foreach (device_t *abstract, dive_callback_t callback, void message ("\"\n"); #endif - if (callback) - callback (data + remaining + 4, size - 4, userdata); + if (callback && !callback (data + remaining + 4, size - 4, userdata)) + return DEVICE_STATUS_SUCCESS; } assert (remaining == 0); assert (available == 0); diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index b6b420d..46727bb 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -310,8 +310,8 @@ uwatec_aladin_extract_dives (const unsigned char* data, unsigned int size, dive_ profiles = 0; } - if (callback) - callback (buffer, len + 18, userdata); + if (callback && !callback (buffer, len + 18, userdata)) + return DEVICE_STATUS_SUCCESS; } return DEVICE_STATUS_SUCCESS; diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index 82efa39..32a790f 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -477,8 +477,8 @@ uwatec_memomouse_extract_dives (const unsigned char data[], unsigned int size, d // Get the length of the profile data. unsigned int length = data[offset + 16] + (data[offset + 17] << 8); - if (callback) - callback (data + offset, length + 18, userdata); + if (callback && !callback (data + offset, length + 18, userdata)) + return DEVICE_STATUS_SUCCESS; } return DEVICE_STATUS_SUCCESS; diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index db1cf11..71c620b 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -410,8 +410,8 @@ uwatec_smart_extract_dives (const unsigned char data[], unsigned int size, dive_ if (current + len > previous) return DEVICE_STATUS_ERROR; - if (callback) - callback (data + current, len, userdata); + if (callback && !callback (data + current, len, userdata)) + return DEVICE_STATUS_SUCCESS; // Prepare for the next dive. previous = current;