]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Update for new libdivecomputer interfaces
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 27 Aug 2012 22:06:58 +0000 (15:06 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 27 Aug 2012 22:06:58 +0000 (15:06 -0700)
For this you need to get the current libdivecomputer tree, reconfigure,
build and install it first.  But this cleans up some of the silly error
handling too, and has just a single "dc_device_close()" call etc, rather
than duplicating that (and the new dc_context_free()).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
libdivecomputer.c
libdivecomputer.h

index e362d1d2ba9ad13f018c5007fb3443acd879b6ea..d96d2769f7391afb3bccebb64df1de5fd21a33e5 100644 (file)
@@ -305,13 +305,6 @@ static dc_status_t import_device_data(dc_device_t *device, device_data_t *device
        return dc_device_foreach(device, dive_cb, devicedata);
 }
 
-static dc_status_t device_open(const char *devname,
-       dc_descriptor_t *descriptor,
-       dc_device_t **device)
-{
-       return dc_device_open(device, descriptor, devname);
-}
-
 
 static void event_cb(dc_device_t *device, dc_event_type_t event, const void *data, void *userdata)
 {
@@ -351,42 +344,53 @@ cancel_cb(void *userdata)
        return import_thread_cancelled;
 }
 
-static const char *do_libdivecomputer_import(device_data_t *data)
+static const char *do_device_import(device_data_t *data)
 {
-       dc_device_t *device = NULL;
        dc_status_t rc;
-
-       import_dive_number = 0;
-       rc = device_open(data->devname, data->descriptor, &device);
-       if (rc != DC_STATUS_SUCCESS)
-               return "Unable to open %s %s (%s)";
-       data->device = device;
+       dc_device_t *device = data->device;
 
        // Register the event handler.
        int events = DC_EVENT_WAITING | DC_EVENT_PROGRESS | DC_EVENT_DEVINFO | DC_EVENT_CLOCK;
        rc = dc_device_set_events(device, events, event_cb, data);
-       if (rc != DC_STATUS_SUCCESS) {
-               dc_device_close(device);
+       if (rc != DC_STATUS_SUCCESS)
                return "Error registering the event handler.";
-       }
 
        // Register the cancellation handler.
        rc = dc_device_set_cancel(device, cancel_cb, data);
-       if (rc != DC_STATUS_SUCCESS) {
-               dc_device_close(device);
+       if (rc != DC_STATUS_SUCCESS)
                return "Error registering the cancellation handler.";
-       }
 
        rc = import_device_data(device, data);
-       if (rc != DC_STATUS_SUCCESS) {
-               dc_device_close(device);
+       if (rc != DC_STATUS_SUCCESS)
                return "Dive data import error";
-       }
 
-       dc_device_close(device);
+       /* All good */
        return NULL;
 }
 
+static const char *do_libdivecomputer_import(device_data_t *data)
+{
+       dc_status_t rc;
+       const char *err;
+
+       import_dive_number = 0;
+       data->device = NULL;
+       data->context = NULL;
+
+       rc = dc_context_new(&data->context);
+       if (rc != DC_STATUS_SUCCESS)
+               return "Unable to create libdivecomputer context";
+
+       err = "Unable to open %s %s (%s)";
+       rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
+       if (rc == DC_STATUS_SUCCESS) {
+               err = do_device_import(data);
+               dc_device_close(data->device);
+       }
+       dc_context_free(data->context);
+       return err;
+}
+
 static void *pthread_wrapper(void *_data)
 {
        device_data_t *data = _data;
index 8d77a25beba9230e51e20be293960d9f28f048d3..6b54e9c2a77eb2945934e58affe8787d5028a94c 100644 (file)
@@ -15,6 +15,7 @@ typedef struct device_data_t {
        dc_descriptor_t *descriptor;
        const char *vendor, *product, *devname;
        dc_device_t *device;
+       dc_context_t *context;
        progressbar_t progress;
        int preexisting;
 } device_data_t;