Add a dc_device_open convenience function.
With the introduction of the device descriptors, the new dc_device_open() convenience function can take care of the mapping from a particular model to the corresponding backend internally, without needing any device specific knowledge in the application. An application can simply query the list of supported devices, and the library will automatically do the right thing.
This commit is contained in:
parent
79eade6e06
commit
df9897fb3c
@ -23,6 +23,7 @@
|
||||
#define DC_DEVICE_H
|
||||
|
||||
#include "common.h"
|
||||
#include "descriptor.h"
|
||||
#include "buffer.h"
|
||||
#include "datetime.h"
|
||||
|
||||
@ -61,6 +62,9 @@ typedef void (*dc_event_callback_t) (dc_device_t *device, dc_event_type_t event,
|
||||
|
||||
typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata);
|
||||
|
||||
dc_status_t
|
||||
dc_device_open (dc_device_t **out, dc_descriptor_t *descriptor, const char *name);
|
||||
|
||||
dc_family_t
|
||||
dc_device_get_type (dc_device_t *device);
|
||||
|
||||
|
||||
97
src/device.c
97
src/device.c
@ -22,6 +22,16 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libdivecomputer/suunto.h>
|
||||
#include <libdivecomputer/reefnet.h>
|
||||
#include <libdivecomputer/uwatec.h>
|
||||
#include <libdivecomputer/oceanic.h>
|
||||
#include <libdivecomputer/mares.h>
|
||||
#include <libdivecomputer/hw.h>
|
||||
#include <libdivecomputer/cressi.h>
|
||||
#include <libdivecomputer/zeagle.h>
|
||||
#include <libdivecomputer/atomics.h>
|
||||
|
||||
#include "device-private.h"
|
||||
|
||||
|
||||
@ -38,6 +48,93 @@ device_init (dc_device_t *device, const device_backend_t *backend)
|
||||
device->cancel_userdata = NULL;
|
||||
}
|
||||
|
||||
dc_status_t
|
||||
dc_device_open (dc_device_t **out, dc_descriptor_t *descriptor, const char *name)
|
||||
{
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
dc_device_t *device = NULL;
|
||||
|
||||
if (out == NULL || descriptor == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
switch (dc_descriptor_get_type (descriptor)) {
|
||||
case DC_FAMILY_SUUNTO_SOLUTION:
|
||||
rc = suunto_solution_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_SUUNTO_EON:
|
||||
rc = suunto_eon_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_SUUNTO_VYPER:
|
||||
rc = suunto_vyper_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_SUUNTO_VYPER2:
|
||||
rc = suunto_vyper2_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_SUUNTO_D9:
|
||||
rc = suunto_d9_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_UWATEC_ALADIN:
|
||||
rc = uwatec_aladin_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_UWATEC_MEMOMOUSE:
|
||||
rc = uwatec_memomouse_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_UWATEC_SMART:
|
||||
rc = uwatec_smart_device_open (&device);
|
||||
break;
|
||||
case DC_FAMILY_REEFNET_SENSUS:
|
||||
rc = reefnet_sensus_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_REEFNET_SENSUSPRO:
|
||||
rc = reefnet_sensuspro_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_REEFNET_SENSUSULTRA:
|
||||
rc = reefnet_sensusultra_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_OCEANIC_VTPRO:
|
||||
rc = oceanic_vtpro_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_OCEANIC_VEO250:
|
||||
rc = oceanic_veo250_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_OCEANIC_ATOM2:
|
||||
rc = oceanic_atom2_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_MARES_NEMO:
|
||||
rc = mares_nemo_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_MARES_PUCK:
|
||||
rc = mares_puck_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_MARES_DARWIN:
|
||||
rc = mares_darwin_device_open (&device, name, dc_descriptor_get_model (descriptor));
|
||||
break;
|
||||
case DC_FAMILY_MARES_ICONHD:
|
||||
rc = mares_iconhd_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_HW_OSTC:
|
||||
rc = hw_ostc_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_HW_FROG:
|
||||
rc = hw_frog_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_CRESSI_EDY:
|
||||
rc = cressi_edy_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_ZEAGLE_N2ITION3:
|
||||
rc = zeagle_n2ition3_device_open (&device, name);
|
||||
break;
|
||||
case DC_FAMILY_ATOMICS_COBALT:
|
||||
rc = atomics_cobalt_device_open (&device);
|
||||
break;
|
||||
default:
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
}
|
||||
|
||||
*out = device;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
dc_family_t
|
||||
dc_device_get_type (dc_device_t *device)
|
||||
|
||||
@ -57,6 +57,7 @@ cressi_edy_parser_create
|
||||
atomics_cobalt_parser_create
|
||||
atomics_cobalt_parser_set_calibration
|
||||
|
||||
dc_device_open
|
||||
dc_device_close
|
||||
dc_device_dump
|
||||
dc_device_foreach
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user