[PATCH] Update to the latest libdivecomputer api.

Jef Driesen jefdriesen at telenet.be
Mon Aug 27 14:24:49 PDT 2012


A library context object is now required before creating any other
library objects. This patch implements just the bare minimum to make
subsurface compile again. None of the new features are used yet.

Signed-off-by: Jef Driesen <jefdriesen at telenet.be>
---
 libdivecomputer.c |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/libdivecomputer.c b/libdivecomputer.c
index e362d1d..a643b4d 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -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)
 {
@@ -353,13 +346,21 @@ cancel_cb(void *userdata)
 
 static const char *do_libdivecomputer_import(device_data_t *data)
 {
+	dc_context_t *context = NULL;
 	dc_device_t *device = NULL;
 	dc_status_t rc;
 
+	rc = dc_context_new (&context);
+	if (rc != DC_STATUS_SUCCESS) {
+		return "Unable to create a context.";
+	}
+
 	import_dive_number = 0;
-	rc = device_open(data->devname, data->descriptor, &device);
-	if (rc != DC_STATUS_SUCCESS)
+	rc = dc_device_open(&device, context, data->descriptor, data->devname);
+	if (rc != DC_STATUS_SUCCESS) {
+		dc_context_free (context);
 		return "Unable to open %s %s (%s)";
+	}
 	data->device = device;
 
 	// Register the event handler.
@@ -367,6 +368,7 @@ static const char *do_libdivecomputer_import(device_data_t *data)
 	rc = dc_device_set_events(device, events, event_cb, data);
 	if (rc != DC_STATUS_SUCCESS) {
 		dc_device_close(device);
+		dc_context_free (context);
 		return "Error registering the event handler.";
 	}
 
@@ -374,16 +376,19 @@ static const char *do_libdivecomputer_import(device_data_t *data)
 	rc = dc_device_set_cancel(device, cancel_cb, data);
 	if (rc != DC_STATUS_SUCCESS) {
 		dc_device_close(device);
+		dc_context_free (context);
 		return "Error registering the cancellation handler.";
 	}
 
 	rc = import_device_data(device, data);
 	if (rc != DC_STATUS_SUCCESS) {
 		dc_device_close(device);
+		dc_context_free (context);
 		return "Dive data import error";
 	}
 
 	dc_device_close(device);
+	dc_context_free (context);
 	return NULL;
 }
 
-- 
1.7.9.5



More information about the subsurface mailing list