Use the userdata parameter to pass the dive data to the callback.
This commit is contained in:
parent
f6d35fa2c2
commit
ff55a4a82d
@ -37,6 +37,10 @@
|
|||||||
#include <cressi.h>
|
#include <cressi.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
|
||||||
|
typedef struct dive_data_t {
|
||||||
|
unsigned int number;
|
||||||
|
} dive_data_t;
|
||||||
|
|
||||||
typedef struct backend_table_t {
|
typedef struct backend_table_t {
|
||||||
const char *name;
|
const char *name;
|
||||||
device_type_t type;
|
device_type_t type;
|
||||||
@ -176,11 +180,11 @@ event_cb (device_t *device, device_event_t event, const void *data, void *userda
|
|||||||
static int
|
static int
|
||||||
dive_cb (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata)
|
dive_cb (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata)
|
||||||
{
|
{
|
||||||
static unsigned int count = 0;
|
dive_data_t *divedata = (dive_data_t *) userdata;
|
||||||
|
|
||||||
count++;
|
divedata->number++;
|
||||||
|
|
||||||
message ("Dive: number=%u, size=%u, fingerprint=", count, size);
|
message ("Dive: number=%u, size=%u, fingerprint=", divedata->number, size);
|
||||||
for (unsigned int i = 0; i < fsize; ++i)
|
for (unsigned int i = 0; i < fsize; ++i)
|
||||||
message ("%02X", fingerprint[i]);
|
message ("%02X", fingerprint[i]);
|
||||||
message ("\n");
|
message ("\n");
|
||||||
@ -376,9 +380,13 @@ dowork (device_type_t backend, const char *devname, const char *filename, int me
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dives) {
|
if (dives) {
|
||||||
|
// Initialize the dive data.
|
||||||
|
dive_data_t divedata = {0};
|
||||||
|
divedata.number = 0;
|
||||||
|
|
||||||
// Download the dives.
|
// Download the dives.
|
||||||
message ("Downloading the dives.\n");
|
message ("Downloading the dives.\n");
|
||||||
rc = device_foreach (device, dive_cb, NULL);
|
rc = device_foreach (device, dive_cb, &divedata);
|
||||||
if (rc != DEVICE_STATUS_SUCCESS) {
|
if (rc != DEVICE_STATUS_SUCCESS) {
|
||||||
WARNING ("Error downloading the dives.");
|
WARNING ("Error downloading the dives.");
|
||||||
device_close (device);
|
device_close (device);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user