From ba1bd5d688a3ad05d94c00610c885013c971ed01 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 16 Feb 2010 14:57:37 +0000 Subject: [PATCH] Use the userdata parameter to pass the device data back to the caller. --- examples/universal.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/universal.c b/examples/universal.c index 38cfa9c..391c48f 100644 --- a/examples/universal.c +++ b/examples/universal.c @@ -37,6 +37,12 @@ #include #include +typedef struct device_data_t { + device_type_t backend; + device_devinfo_t devinfo; + device_clock_t clock; +} device_data_t; + typedef struct dive_data_t { unsigned int number; } dive_data_t; @@ -153,6 +159,8 @@ event_cb (device_t *device, device_event_t event, const void *data, void *userda const device_devinfo_t *devinfo = (device_devinfo_t *) data; const device_clock_t *clock = (device_clock_t *) data; + device_data_t *devdata = (device_data_t *) userdata; + switch (event) { case DEVICE_EVENT_WAITING: message ("Event: waiting for user action\n"); @@ -163,12 +171,14 @@ event_cb (device_t *device, device_event_t event, const void *data, void *userda progress->current, progress->maximum); break; case DEVICE_EVENT_DEVINFO: + devdata->devinfo = *devinfo; message ("Event: model=%u (0x%08x), firmware=%u (0x%08x), serial=%u (0x%08x)\n", devinfo->model, devinfo->model, devinfo->firmware, devinfo->firmware, devinfo->serial, devinfo->serial); break; case DEVICE_EVENT_CLOCK: + devdata->clock = *clock; message ("Event: systime=%u, devtime=%u\n", clock->systime, clock->devtime); break; @@ -256,6 +266,10 @@ dowork (device_type_t backend, const char *devname, const char *filename, int me { device_status_t rc = DEVICE_STATUS_SUCCESS; + // Initialize the device data. + device_data_t devdata = {0}; + devdata.backend = backend; + // Open the device. message ("Opening the device (%s, %s).\n", lookup_name (backend), devname ? devname : "null"); @@ -327,7 +341,7 @@ dowork (device_type_t backend, const char *devname, const char *filename, int me // Register the event handler. message ("Registering the event handler.\n"); int events = DEVICE_EVENT_WAITING | DEVICE_EVENT_PROGRESS | DEVICE_EVENT_DEVINFO | DEVICE_EVENT_CLOCK; - rc = device_set_events (device, events, event_cb, NULL); + rc = device_set_events (device, events, event_cb, &devdata); if (rc != DEVICE_STATUS_SUCCESS) { WARNING ("Error registering the event handler."); device_close (device);