Allow to abort a transfer by returning FALSE from the callback.
This commit is contained in:
parent
4f63295802
commit
16b14e55ef
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user