Add a single isinstance function per object type.

Currently, each backend has it's own function to verify whether the
object vtable pointer is the expected one. All these functions can be
removed in favor of a single isintance function in the base class,
which takes the expected vtable pointer as a parameter.

Functions which are called through the vtable, don't need to verify the
vtable pointer, and those checks are removed.
This commit is contained in:
Jef Driesen 2013-01-03 10:24:39 +01:00
parent 007479fc92
commit 6419e189a4
49 changed files with 172 additions and 798 deletions

View File

@ -40,6 +40,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &atomics_cobalt_device_vtable)
#define EXITCODE(rc) (rc == LIBUSB_ERROR_TIMEOUT ? DC_STATUS_TIMEOUT : DC_STATUS_IO)
#define VID 0x0471
@ -76,15 +78,6 @@ static const dc_device_vtable_t atomics_cobalt_device_vtable = {
atomics_cobalt_device_close /* close */
};
static int
device_is_atomics_cobalt (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &atomics_cobalt_device_vtable;
}
dc_status_t
atomics_cobalt_device_open (dc_device_t **out, dc_context_t *context)
@ -156,9 +149,6 @@ atomics_cobalt_device_close (dc_device_t *abstract)
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (! device_is_atomics_cobalt (abstract))
return DC_STATUS_INVALIDARGS;
#ifdef HAVE_LIBUSB
libusb_release_interface(device->handle, 0);
libusb_close (device->handle);
@ -177,9 +167,6 @@ atomics_cobalt_device_set_fingerprint (dc_device_t *abstract, const unsigned cha
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (! device_is_atomics_cobalt (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != sizeof (device->fingerprint))
return DC_STATUS_INVALIDARGS;
@ -197,7 +184,7 @@ atomics_cobalt_device_set_simulation (dc_device_t *abstract, unsigned int simula
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (! device_is_atomics_cobalt (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
device->simulation = simulation;
@ -211,6 +198,9 @@ atomics_cobalt_device_version (dc_device_t *abstract, unsigned char data[], unsi
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_VERSION)
return DC_STATUS_INVALIDARGS;
@ -350,9 +340,6 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
{
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
if (! device_is_atomics_cobalt (abstract))
return DC_STATUS_INVALIDARGS;
// Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = SZ_MEMORY + 2;

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &atomics_cobalt_parser_vtable)
#define SZ_HEADER 228
#define SZ_GASMIX 18
#define SZ_GASSWITCH 6
@ -58,16 +60,6 @@ static const dc_parser_vtable_t atomics_cobalt_parser_vtable = {
};
static int
parser_is_atomics_cobalt (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &atomics_cobalt_parser_vtable;
}
dc_status_t
atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -97,9 +89,6 @@ atomics_cobalt_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
atomics_cobalt_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_atomics_cobalt (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -110,9 +99,6 @@ atomics_cobalt_parser_destroy (dc_parser_t *abstract)
static dc_status_t
atomics_cobalt_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_atomics_cobalt (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}
@ -122,7 +108,7 @@ atomics_cobalt_parser_set_calibration (dc_parser_t *abstract, double atmospheric
{
atomics_cobalt_parser_t *parser = (atomics_cobalt_parser_t*) abstract;
if (! parser_is_atomics_cobalt (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
parser->atmospheric = atmospheric;

View File

@ -32,6 +32,8 @@
#include "array.h"
#include "ringbuffer.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &cressi_edy_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -73,15 +75,6 @@ static const dc_device_vtable_t cressi_edy_device_vtable = {
cressi_edy_device_close /* close */
};
static int
device_is_cressi_edy (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &cressi_edy_device_vtable;
}
static dc_status_t
cressi_edy_transfer (cressi_edy_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, int trailer)
@ -252,9 +245,6 @@ cressi_edy_device_close (dc_device_t *abstract)
{
cressi_edy_device_t *device = (cressi_edy_device_t*) abstract;
if (! device_is_cressi_edy (abstract))
return DC_STATUS_INVALIDARGS;
// Send the quit command.
cressi_edy_quit (device);
@ -276,9 +266,6 @@ cressi_edy_device_read (dc_device_t *abstract, unsigned int address, unsigned ch
{
cressi_edy_device_t *device = (cressi_edy_device_t*) abstract;
if (! device_is_cressi_edy (abstract))
return DC_STATUS_INVALIDARGS;
if ((address % SZ_PAGE != 0) ||
(size % SZ_PACKET != 0))
return DC_STATUS_INVALIDARGS;
@ -326,9 +313,6 @@ cressi_edy_device_set_fingerprint (dc_device_t *abstract, const unsigned char da
static dc_status_t
cressi_edy_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
if (! device_is_cressi_edy (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) {

View File

@ -27,6 +27,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &cressi_edy_parser_vtable)
typedef struct cressi_edy_parser_t cressi_edy_parser_t;
struct cressi_edy_parser_t {
@ -50,16 +52,6 @@ static const dc_parser_vtable_t cressi_edy_parser_vtable = {
};
static int
parser_is_cressi_edy (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &cressi_edy_parser_vtable;
}
dc_status_t
cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -88,9 +80,6 @@ cressi_edy_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
static dc_status_t
cressi_edy_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_cressi_edy (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -101,9 +90,6 @@ cressi_edy_parser_destroy (dc_parser_t *abstract)
static dc_status_t
cressi_edy_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_cressi_edy (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}

View File

@ -32,6 +32,8 @@
#include "array.h"
#include "ringbuffer.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &cressi_leonardo_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -69,15 +71,6 @@ static const dc_device_vtable_t cressi_leonardo_device_vtable = {
cressi_leonardo_device_close /* close */
};
static int
device_is_cressi_leonardo (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &cressi_leonardo_device_vtable;
}
dc_status_t
cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
@ -289,7 +282,7 @@ cressi_leonardo_extract_dives (dc_device_t *abstract, const unsigned char data[]
cressi_leonardo_device_t *device = (cressi_leonardo_device_t *) abstract;
dc_context_t *context = (abstract ? abstract->context : NULL);
if (abstract && !device_is_cressi_leonardo (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -27,6 +27,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_device_isinstance((parser), &cressi_leonardo_parser_vtable)
#define SZ_HEADER 82
typedef struct cressi_leonardo_parser_t cressi_leonardo_parser_t;
@ -51,16 +53,6 @@ static const dc_parser_vtable_t cressi_leonardo_parser_vtable = {
};
static int
parser_is_cressi_leonardo (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &cressi_leonardo_parser_vtable;
}
dc_status_t
cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -86,9 +78,6 @@ cressi_leonardo_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
cressi_leonardo_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_cressi_leonardo (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -99,9 +88,6 @@ cressi_leonardo_parser_destroy (dc_parser_t *abstract)
static dc_status_t
cressi_leonardo_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_cressi_leonardo (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}

View File

@ -70,6 +70,9 @@ struct dc_device_vtable_t {
dc_status_t (*close) (dc_device_t *device);
};
int
dc_device_isinstance (dc_device_t *device, const dc_device_vtable_t *vtable);
void
device_init (dc_device_t *device, dc_context_t *context, const dc_device_vtable_t *vtable);

View File

@ -150,6 +150,17 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
return rc;
}
int
dc_device_isinstance (dc_device_t *device, const dc_device_vtable_t *vtable)
{
if (device == NULL)
return 0;
return device->vtable == vtable;
}
dc_family_t
dc_device_get_type (dc_device_t *device)
{

View File

@ -31,6 +31,8 @@
#include "ringbuffer.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &hw_frog_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -78,16 +80,6 @@ static const dc_device_vtable_t hw_frog_device_vtable = {
};
static int
device_is_hw_frog (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &hw_frog_device_vtable;
}
static dc_status_t
hw_frog_transfer (hw_frog_device_t *device,
dc_event_progress_t *progress,
@ -297,7 +289,7 @@ hw_frog_device_version (dc_device_t *abstract, unsigned char data[], unsigned in
{
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
if (!device_is_hw_frog (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size != SZ_VERSION)
@ -478,7 +470,7 @@ hw_frog_device_clock (dc_device_t *abstract, const dc_datetime_t *datetime)
{
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
if (!device_is_hw_frog (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (datetime == NULL) {
@ -503,7 +495,7 @@ hw_frog_device_display (dc_device_t *abstract, const char *text)
{
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
if (!device_is_hw_frog (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Check the maximum length.
@ -533,7 +525,7 @@ hw_frog_device_customtext (dc_device_t *abstract, const char *text)
{
hw_frog_device_t *device = (hw_frog_device_t *) abstract;
if (!device_is_hw_frog (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Check the maximum length.

View File

@ -30,6 +30,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &hw_ostc_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -70,16 +72,6 @@ static const dc_device_vtable_t hw_ostc_device_vtable = {
};
static int
device_is_hw_ostc (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &hw_ostc_device_vtable;
}
static dc_status_t
hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
{
@ -173,9 +165,6 @@ hw_ostc_device_close (dc_device_t *abstract)
{
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
if (! device_is_hw_ostc (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -211,9 +200,6 @@ hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
if (! device_is_hw_ostc (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
ERROR (abstract->context, "Insufficient buffer space available.");
@ -346,7 +332,7 @@ hw_ostc_device_md2hash (dc_device_t *abstract, unsigned char data[], unsigned in
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MD2HASH) {
@ -375,7 +361,7 @@ hw_ostc_device_clock (dc_device_t *abstract, const dc_datetime_t *datetime)
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (datetime == NULL) {
@ -407,7 +393,7 @@ hw_ostc_device_eeprom_read (dc_device_t *abstract, unsigned int bank, unsigned c
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (bank > 2) {
@ -442,7 +428,7 @@ hw_ostc_device_eeprom_write (dc_device_t *abstract, unsigned int bank, const uns
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (bank > 2) {
@ -477,7 +463,7 @@ hw_ostc_device_reset (dc_device_t *abstract)
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Send the command.
@ -494,7 +480,7 @@ hw_ostc_device_screenshot (dc_device_t *abstract, dc_buffer_t *buffer, hw_ostc_f
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (! device_is_hw_ostc (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer.
@ -629,7 +615,7 @@ hw_ostc_extract_dives (dc_device_t *abstract, const unsigned char data[], unsign
{
hw_ostc_device_t *device = (hw_ostc_device_t *) abstract;
if (abstract && !device_is_hw_ostc (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char header[2] = {0xFA, 0xFA};

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &hw_ostc_parser_vtable)
#define NINFO 6
typedef struct hw_ostc_parser_t hw_ostc_parser_t;
@ -58,16 +60,6 @@ static const dc_parser_vtable_t hw_ostc_parser_vtable = {
};
static int
parser_is_hw_ostc (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &hw_ostc_parser_vtable;
}
dc_status_t
hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int frog)
{
@ -95,9 +87,6 @@ hw_ostc_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int fr
static dc_status_t
hw_ostc_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_hw_ostc (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -108,9 +97,6 @@ hw_ostc_parser_destroy (dc_parser_t *abstract)
static dc_status_t
hw_ostc_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_hw_ostc (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}

View File

@ -31,6 +31,8 @@
#include "mares_common.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &mares_darwin_device_vtable)
#define DARWIN 0
#define DARWINAIR 1
@ -90,14 +92,6 @@ static const mares_darwin_layout_t mares_darwinair_layout = {
3 /* samplesize */
};
static int
device_is_mares_darwin (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_darwin_device_vtable;
}
dc_status_t
mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model)
@ -263,7 +257,7 @@ mares_darwin_extract_dives (dc_device_t *abstract, const unsigned char data[], u
{
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
if (!device_is_mares_darwin (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
assert (device->layout != NULL);

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &mares_darwin_parser_vtable)
#define DARWIN 0
#define DARWINAIR 1
@ -56,16 +58,6 @@ static const dc_parser_vtable_t mares_darwin_parser_vtable = {
};
static int
parser_is_mares_darwin (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_darwin_parser_vtable;
}
dc_status_t
mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -99,9 +91,6 @@ mares_darwin_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i
static dc_status_t
mares_darwin_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_mares_darwin (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);

View File

@ -30,6 +30,8 @@
#include "serial.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &mares_iconhd_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -80,15 +82,6 @@ static const dc_device_vtable_t mares_iconhd_device_vtable = {
mares_iconhd_device_close /* close */
};
static int
device_is_mares_iconhd (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_iconhd_device_vtable;
}
static unsigned int
mares_iconhd_get_model (mares_iconhd_device_t *device, unsigned int model)
@ -323,9 +316,6 @@ mares_iconhd_device_close (dc_device_t *abstract)
{
mares_iconhd_device_t *device = (mares_iconhd_device_t*) abstract;
if (! device_is_mares_iconhd (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -431,7 +421,7 @@ mares_iconhd_extract_dives (dc_device_t *abstract, const unsigned char data[], u
mares_iconhd_device_t *device = (mares_iconhd_device_t *) abstract;
dc_context_t *context = (abstract ? abstract->context : NULL);
if (abstract && !device_is_mares_iconhd (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -27,6 +27,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &mares_iconhd_parser_vtable)
#define ICONHD 0x14
#define ICONHDNET 0x15
@ -53,16 +55,6 @@ static const dc_parser_vtable_t mares_iconhd_parser_vtable = {
};
static int
parser_is_mares_iconhd (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_iconhd_parser_vtable;
}
dc_status_t
mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -91,9 +83,6 @@ mares_iconhd_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i
static dc_status_t
mares_iconhd_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_mares_iconhd (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &mares_nemo_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -84,15 +86,6 @@ static const mares_common_layout_t mares_nemo_apneist_layout = {
0x4000 /* rb_freedives_end */
};
static int
device_is_mares_nemo (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_nemo_device_vtable;
}
dc_status_t
mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -162,9 +155,6 @@ mares_nemo_device_close (dc_device_t *abstract)
{
mares_nemo_device_t *device = (mares_nemo_device_t*) abstract;
if (! device_is_mares_nemo (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -320,7 +310,7 @@ mares_nemo_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
{
mares_nemo_device_t *device = (mares_nemo_device_t*) abstract;
if (abstract && !device_is_mares_nemo (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < PACKETSIZE)

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &mares_nemo_parser_vtable)
#define NEMO 0
#define NEMOWIDE 1
#define NEMOAIR 4
@ -68,16 +70,6 @@ static const dc_parser_vtable_t mares_nemo_parser_vtable = {
};
static int
parser_is_mares_nemo (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_nemo_parser_vtable;
}
dc_status_t
mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -118,9 +110,6 @@ mares_nemo_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
static dc_status_t
mares_nemo_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_mares_nemo (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);

View File

@ -32,6 +32,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &mares_puck_device_vtable)
#define NEMOWIDE 1
#define NEMOAIR 4
#define PUCK 7
@ -82,15 +84,6 @@ static const mares_common_layout_t mares_nemowide_layout = {
0x4000 /* rb_freedives_end */
};
static int
device_is_mares_puck (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &mares_puck_device_vtable;
}
dc_status_t
mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -273,7 +266,7 @@ mares_puck_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
{
mares_puck_device_t *device = (mares_puck_device_t*) abstract;
if (abstract && !device_is_mares_puck (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < PACKETSIZE)

View File

@ -32,6 +32,8 @@
#include "ringbuffer.h"
#include "checksum.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &oceanic_atom2_device_vtable)
#define MAXRETRIES 2
#define EXITCODE(rc) \
@ -240,16 +242,6 @@ static const oceanic_common_layout_t oceanic_veo1_layout = {
};
static int
device_is_oceanic_atom2 (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_atom2_device_vtable;
}
static dc_status_t
oceanic_atom2_send (oceanic_atom2_device_t *device, const unsigned char command[], unsigned int csize, unsigned char ack)
{
@ -441,9 +433,6 @@ oceanic_atom2_device_close (dc_device_t *abstract)
{
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
if (! device_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
// Send the quit command.
oceanic_atom2_quit (device);
@ -465,7 +454,7 @@ oceanic_atom2_device_keepalive (dc_device_t *abstract)
{
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
if (! device_is_oceanic_atom2 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Send the command to the dive computer.
@ -483,7 +472,7 @@ oceanic_atom2_device_version (dc_device_t *abstract, unsigned char data[], unsig
{
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
if (! device_is_oceanic_atom2 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < PAGESIZE)
@ -506,9 +495,6 @@ oceanic_atom2_device_read (dc_device_t *abstract, unsigned int address, unsigned
{
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
if (! device_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
if ((address % PAGESIZE != 0) ||
(size % PAGESIZE != 0))
return DC_STATUS_INVALIDARGS;
@ -542,9 +528,6 @@ oceanic_atom2_device_write (dc_device_t *abstract, unsigned int address, const u
{
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
if (! device_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
if ((address % PAGESIZE != 0) ||
(size % PAGESIZE != 0))
return DC_STATUS_INVALIDARGS;

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &oceanic_atom2_parser_vtable)
#define ATOM1 0x4250
#define EPICA 0x4257
#define VT3 0x4258
@ -81,16 +83,6 @@ static const dc_parser_vtable_t oceanic_atom2_parser_vtable = {
};
static int
parser_is_oceanic_atom2 (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_atom2_parser_vtable;
}
dc_status_t
oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -122,9 +114,6 @@ oceanic_atom2_parser_create (dc_parser_t **out, dc_context_t *context, unsigned
static dc_status_t
oceanic_atom2_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -137,9 +126,6 @@ oceanic_atom2_parser_set_data (dc_parser_t *abstract, const unsigned char *data,
{
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
if (! parser_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -358,9 +344,6 @@ oceanic_atom2_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_
{
oceanic_atom2_parser_t *parser = (oceanic_atom2_parser_t *) abstract;
if (! parser_is_oceanic_atom2 (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -31,6 +31,8 @@
#include "ringbuffer.h"
#include "checksum.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &oceanic_veo250_device_vtable)
#define MAXRETRIES 2
#define MULTIPAGE 4
@ -85,16 +87,6 @@ static const oceanic_common_layout_t oceanic_veo250_layout = {
};
static int
device_is_oceanic_veo250 (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_veo250_device_vtable;
}
static dc_status_t
oceanic_veo250_send (oceanic_veo250_device_t *device, const unsigned char command[], unsigned int csize)
{
@ -322,9 +314,6 @@ oceanic_veo250_device_close (dc_device_t *abstract)
{
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
if (! device_is_oceanic_veo250 (abstract))
return DC_STATUS_INVALIDARGS;
// Switch the device back to surface mode.
oceanic_veo250_quit (device);
@ -346,7 +335,7 @@ oceanic_veo250_device_keepalive (dc_device_t *abstract)
{
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
if (! device_is_oceanic_veo250 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
unsigned char answer[2] = {0};
@ -373,7 +362,7 @@ oceanic_veo250_device_version (dc_device_t *abstract, unsigned char data[], unsi
{
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
if (! device_is_oceanic_veo250 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < PAGESIZE)
@ -404,9 +393,6 @@ oceanic_veo250_device_read (dc_device_t *abstract, unsigned int address, unsigne
{
oceanic_veo250_device_t *device = (oceanic_veo250_device_t*) abstract;
if (! device_is_oceanic_veo250 (abstract))
return DC_STATUS_INVALIDARGS;
if ((address % PAGESIZE != 0) ||
(size % PAGESIZE != 0))
return DC_STATUS_INVALIDARGS;

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &oceanic_veo250_parser_vtable)
typedef struct oceanic_veo250_parser_t oceanic_veo250_parser_t;
struct oceanic_veo250_parser_t {
@ -56,16 +58,6 @@ static const dc_parser_vtable_t oceanic_veo250_parser_vtable = {
};
static int
parser_is_oceanic_veo250 (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_veo250_parser_vtable;
}
dc_status_t
oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -97,9 +89,6 @@ oceanic_veo250_parser_create (dc_parser_t **out, dc_context_t *context, unsigned
static dc_status_t
oceanic_veo250_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_oceanic_veo250 (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -112,9 +101,6 @@ oceanic_veo250_parser_set_data (dc_parser_t *abstract, const unsigned char *data
{
oceanic_veo250_parser_t *parser = (oceanic_veo250_parser_t *) abstract;
if (! parser_is_oceanic_veo250 (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -208,9 +194,6 @@ oceanic_veo250_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, un
static dc_status_t
oceanic_veo250_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{
if (! parser_is_oceanic_veo250 (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -31,6 +31,8 @@
#include "ringbuffer.h"
#include "checksum.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &oceanic_vtpro_device_vtable)
#define MAXRETRIES 2
#define MULTIPAGE 4
@ -98,15 +100,6 @@ static const oceanic_common_layout_t oceanic_wisdom_layout = {
0 /* pt_mode_logbook */
};
static int
device_is_oceanic_vtpro (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_vtpro_device_vtable;
}
static dc_status_t
oceanic_vtpro_send (oceanic_vtpro_device_t *device, const unsigned char command[], unsigned int csize)
@ -364,9 +357,6 @@ oceanic_vtpro_device_close (dc_device_t *abstract)
{
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
if (! device_is_oceanic_vtpro (abstract))
return DC_STATUS_INVALIDARGS;
// Switch the device back to surface mode.
oceanic_vtpro_quit (device);
@ -388,7 +378,7 @@ oceanic_vtpro_device_keepalive (dc_device_t *abstract)
{
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
if (! device_is_oceanic_vtpro (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Send the command to the dive computer.
@ -413,7 +403,7 @@ oceanic_vtpro_device_version (dc_device_t *abstract, unsigned char data[], unsig
{
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
if (! device_is_oceanic_vtpro (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < PAGESIZE)
@ -474,9 +464,6 @@ oceanic_vtpro_device_read (dc_device_t *abstract, unsigned int address, unsigned
{
oceanic_vtpro_device_t *device = (oceanic_vtpro_device_t*) abstract;
if (! device_is_oceanic_vtpro (abstract))
return DC_STATUS_INVALIDARGS;
if ((address % PAGESIZE != 0) ||
(size % PAGESIZE != 0))
return DC_STATUS_INVALIDARGS;

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &oceanic_vtpro_parser_vtable)
typedef struct oceanic_vtpro_parser_t oceanic_vtpro_parser_t;
struct oceanic_vtpro_parser_t {
@ -55,16 +57,6 @@ static const dc_parser_vtable_t oceanic_vtpro_parser_vtable = {
};
static int
parser_is_oceanic_vtpro (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &oceanic_vtpro_parser_vtable;
}
dc_status_t
oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -95,9 +87,6 @@ oceanic_vtpro_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
oceanic_vtpro_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_oceanic_vtpro (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -110,9 +99,6 @@ oceanic_vtpro_parser_set_data (dc_parser_t *abstract, const unsigned char *data,
{
oceanic_vtpro_parser_t *parser = (oceanic_vtpro_parser_t *) abstract;
if (! parser_is_oceanic_vtpro (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -211,9 +197,6 @@ oceanic_vtpro_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, uns
static dc_status_t
oceanic_vtpro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{
if (! parser_is_oceanic_vtpro (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -58,6 +58,9 @@ struct dc_parser_vtable_t {
void
parser_init (dc_parser_t *parser, dc_context_t *context, const dc_parser_vtable_t *vtable);
int
dc_parser_isinstance (dc_parser_t *parser, const dc_parser_vtable_t *vtable);
typedef struct sample_statistics_t {
unsigned int divetime;
double maxdepth;

View File

@ -137,6 +137,16 @@ parser_init (dc_parser_t *parser, dc_context_t *context, const dc_parser_vtable_
}
int
dc_parser_isinstance (dc_parser_t *parser, const dc_parser_vtable_t *vtable)
{
if (parser == NULL)
return 0;
return parser->vtable == vtable;
}
dc_family_t
dc_parser_get_type (dc_parser_t *parser)
{

View File

@ -30,6 +30,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &reefnet_sensus_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -63,15 +65,6 @@ static const dc_device_vtable_t reefnet_sensus_device_vtable = {
reefnet_sensus_device_close /* close */
};
static int
device_is_reefnet_sensus (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensus_device_vtable;
}
static dc_status_t
reefnet_sensus_cancel (reefnet_sensus_device_t *device)
@ -156,9 +149,6 @@ reefnet_sensus_device_close (dc_device_t *abstract)
{
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
if (! device_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
// Safely close the connection if the last handshake was
// successful, but no data transfer was ever initiated.
if (device->waiting)
@ -182,7 +172,7 @@ reefnet_sensus_device_get_handshake (dc_device_t *abstract, unsigned char data[]
{
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
if (! device_is_reefnet_sensus (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_HANDSHAKE) {
@ -201,9 +191,6 @@ reefnet_sensus_device_set_fingerprint (dc_device_t *abstract, const unsigned cha
{
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
if (! device_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -286,9 +273,6 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
if (! device_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
@ -362,9 +346,6 @@ reefnet_sensus_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
reefnet_sensus_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -390,7 +371,7 @@ reefnet_sensus_extract_dives (dc_device_t *abstract, const unsigned char data[],
reefnet_sensus_device_t *device = (reefnet_sensus_device_t*) abstract;
dc_context_t *context = (abstract ? abstract->context : NULL);
if (abstract && !device_is_reefnet_sensus (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Search the entire data stream for start markers.

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &reefnet_sensus_parser_vtable)
#define SAMPLE_DEPTH_ADJUST 13
typedef struct reefnet_sensus_parser_t reefnet_sensus_parser_t;
@ -62,16 +64,6 @@ static const dc_parser_vtable_t reefnet_sensus_parser_vtable = {
};
static int
parser_is_reefnet_sensus (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensus_parser_vtable;
}
dc_status_t
reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
@ -106,9 +98,6 @@ reefnet_sensus_parser_create (dc_parser_t **out, dc_context_t *context, unsigned
static dc_status_t
reefnet_sensus_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -121,9 +110,6 @@ reefnet_sensus_parser_set_data (dc_parser_t *abstract, const unsigned char *data
{
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
if (! parser_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -138,7 +124,7 @@ reefnet_sensus_parser_set_calibration (dc_parser_t *abstract, double atmospheric
{
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
if (! parser_is_reefnet_sensus (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
parser->atmospheric = atmospheric;
@ -239,9 +225,6 @@ reefnet_sensus_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback
{
reefnet_sensus_parser_t *parser = (reefnet_sensus_parser_t*) abstract;
if (! parser_is_reefnet_sensus (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -30,6 +30,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &reefnet_sensuspro_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -62,15 +64,6 @@ static const dc_device_vtable_t reefnet_sensuspro_device_vtable = {
reefnet_sensuspro_device_close /* close */
};
static int
device_is_reefnet_sensuspro (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensuspro_device_vtable;
}
dc_status_t
reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -134,9 +127,6 @@ reefnet_sensuspro_device_close (dc_device_t *abstract)
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (! device_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -155,7 +145,7 @@ reefnet_sensuspro_device_get_handshake (dc_device_t *abstract, unsigned char dat
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (! device_is_reefnet_sensuspro (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_HANDSHAKE) {
@ -174,9 +164,6 @@ reefnet_sensuspro_device_set_fingerprint (dc_device_t *abstract, const unsigned
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (! device_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -274,9 +261,6 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (! device_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
@ -330,9 +314,6 @@ reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
reefnet_sensuspro_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -357,7 +338,7 @@ reefnet_sensuspro_device_write_interval (dc_device_t *abstract, unsigned char in
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (! device_is_reefnet_sensuspro (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (interval < 1 || interval > 127)
@ -385,7 +366,7 @@ reefnet_sensuspro_extract_dives (dc_device_t *abstract, const unsigned char data
{
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
if (abstract && !device_is_reefnet_sensuspro (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &reefnet_sensuspro_parser_vtable)
typedef struct reefnet_sensuspro_parser_t reefnet_sensuspro_parser_t;
struct reefnet_sensuspro_parser_t {
@ -61,16 +63,6 @@ static const dc_parser_vtable_t reefnet_sensuspro_parser_vtable = {
};
static int
parser_is_reefnet_sensuspro (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensuspro_parser_vtable;
}
dc_status_t
reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
@ -105,9 +97,6 @@ reefnet_sensuspro_parser_create (dc_parser_t **out, dc_context_t *context, unsig
static dc_status_t
reefnet_sensuspro_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -120,9 +109,6 @@ reefnet_sensuspro_parser_set_data (dc_parser_t *abstract, const unsigned char *d
{
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
if (! parser_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -137,7 +123,7 @@ reefnet_sensuspro_parser_set_calibration (dc_parser_t *abstract, double atmosphe
{
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
if (! parser_is_reefnet_sensuspro (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
parser->atmospheric = atmospheric;
@ -228,9 +214,6 @@ reefnet_sensuspro_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callb
{
reefnet_sensuspro_parser_t *parser = (reefnet_sensuspro_parser_t*) abstract;
if (! parser_is_reefnet_sensuspro (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};
const unsigned char footer[2] = {0xFF, 0xFF};

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &reefnet_sensusultra_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -71,15 +73,6 @@ static const dc_device_vtable_t reefnet_sensusultra_device_vtable = {
reefnet_sensusultra_device_close /* close */
};
static int
device_is_reefnet_sensusultra (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensusultra_device_vtable;
}
dc_status_t
reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -143,9 +136,6 @@ reefnet_sensusultra_device_close (dc_device_t *abstract)
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -164,7 +154,7 @@ reefnet_sensusultra_device_get_handshake (dc_device_t *abstract, unsigned char d
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_HANDSHAKE) {
@ -183,9 +173,6 @@ reefnet_sensusultra_device_set_fingerprint (dc_device_t *abstract, const unsigne
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -393,9 +380,6 @@ reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
@ -450,7 +434,7 @@ reefnet_sensusultra_device_read_user (dc_device_t *abstract, unsigned char *data
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_USER) {
@ -493,7 +477,7 @@ reefnet_sensusultra_device_write_user (dc_device_t *abstract, const unsigned cha
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_USER) {
@ -541,7 +525,7 @@ reefnet_sensusultra_device_write_parameter (dc_device_t *abstract, reefnet_sensu
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Set the instruction code and validate the new value.
@ -590,7 +574,7 @@ reefnet_sensusultra_device_sense (dc_device_t *abstract, unsigned char *data, un
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_SENSE) {
@ -690,9 +674,6 @@ reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc_dive_callback_t ca
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
if (! device_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY);
if (buffer == NULL) {
ERROR (abstract->context, "Failed to allocate memory.");
@ -777,7 +758,7 @@ reefnet_sensusultra_extract_dives (dc_device_t *abstract, const unsigned char da
{
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t *) abstract;
if (abstract && !device_is_reefnet_sensusultra (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
unsigned int remaining = size;

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &reefnet_sensusultra_parser_vtable)
typedef struct reefnet_sensusultra_parser_t reefnet_sensusultra_parser_t;
struct reefnet_sensusultra_parser_t {
@ -61,16 +63,6 @@ static const dc_parser_vtable_t reefnet_sensusultra_parser_vtable = {
};
static int
parser_is_reefnet_sensusultra (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &reefnet_sensusultra_parser_vtable;
}
dc_status_t
reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
@ -105,9 +97,6 @@ reefnet_sensusultra_parser_create (dc_parser_t **out, dc_context_t *context, uns
static dc_status_t
reefnet_sensusultra_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -120,9 +109,6 @@ reefnet_sensusultra_parser_set_data (dc_parser_t *abstract, const unsigned char
{
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
if (! parser_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -137,7 +123,7 @@ reefnet_sensusultra_parser_set_calibration (dc_parser_t *abstract, double atmosp
{
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
if (! parser_is_reefnet_sensusultra (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
parser->atmospheric = atmospheric;
@ -229,9 +215,6 @@ reefnet_sensusultra_parser_samples_foreach (dc_parser_t *abstract, dc_sample_cal
{
reefnet_sensusultra_parser_t *parser = (reefnet_sensusultra_parser_t*) abstract;
if (! parser_is_reefnet_sensusultra (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char header[4] = {0x00, 0x00, 0x00, 0x00};
const unsigned char footer[4] = {0xFF, 0xFF, 0xFF, 0xFF};

View File

@ -29,6 +29,8 @@
#include "serial.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &shearwater_predator_device_vtable)
#define PREDATOR 2
#define PETREL 3
@ -69,16 +71,6 @@ static const dc_device_vtable_t shearwater_predator_device_vtable = {
};
static int
device_is_shearwater_predator (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &shearwater_predator_device_vtable;
}
static int
shearwater_predator_slip_write (shearwater_predator_device_t *device, const unsigned char data[], unsigned int size)
{
@ -623,7 +615,7 @@ shearwater_predator_extract_petrel (dc_device_t *abstract, const unsigned char d
dc_status_t
shearwater_predator_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
if (abstract && !device_is_shearwater_predator (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &shearwater_predator_parser_vtable)
#define SZ_BLOCK 0x80
#define SZ_SAMPLE 0x10
@ -56,16 +58,6 @@ static const dc_parser_vtable_t shearwater_predator_parser_vtable = {
};
static int
parser_is_shearwater_predator (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &shearwater_predator_parser_vtable;
}
dc_status_t
shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -91,9 +83,6 @@ shearwater_predator_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
shearwater_predator_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_shearwater_predator (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -104,9 +93,6 @@ shearwater_predator_parser_destroy (dc_parser_t *abstract)
static dc_status_t
shearwater_predator_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_shearwater_predator (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), (const dc_device_vtable_t *) &suunto_d9_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -79,15 +81,6 @@ static const suunto_common2_layout_t suunto_d9tx_layout = {
0xEBF0 /* rb_profile_end */
};
static int
device_is_suunto_d9 (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == (const dc_device_vtable_t *) &suunto_d9_device_vtable;
}
static dc_status_t
suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
@ -209,9 +202,6 @@ suunto_d9_device_close (dc_device_t *abstract)
{
suunto_d9_device_t *device = (suunto_d9_device_t*) abstract;
if (! device_is_suunto_d9 (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -301,7 +291,7 @@ suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], u
dc_status_t
suunto_d9_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size)
{
if (! device_is_suunto_d9 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
return suunto_common2_device_version (abstract, data, size);
@ -311,7 +301,7 @@ suunto_d9_device_version (dc_device_t *abstract, unsigned char data[], unsigned
dc_status_t
suunto_d9_device_reset_maxdepth (dc_device_t *abstract)
{
if (! device_is_suunto_d9 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
return suunto_common2_device_reset_maxdepth (abstract);

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &suunto_d9_parser_vtable)
#define MAXPARAMS 3
#define D9 0x0E
@ -82,16 +84,6 @@ static const dc_parser_vtable_t suunto_d9_parser_vtable = {
};
static int
parser_is_suunto_d9 (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_d9_parser_vtable;
}
dc_status_t
suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model)
{
@ -120,9 +112,6 @@ suunto_d9_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int
static dc_status_t
suunto_d9_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_suunto_d9 (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -133,9 +122,6 @@ suunto_d9_parser_destroy (dc_parser_t *abstract)
static dc_status_t
suunto_d9_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_suunto_d9 (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}
@ -276,9 +262,6 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca
{
suunto_d9_parser_t *parser = (suunto_d9_parser_t*) abstract;
if (! parser_is_suunto_d9 (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &suunto_eon_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -66,16 +68,6 @@ static const suunto_common_layout_t suunto_eon_layout = {
};
static int
device_is_suunto_eon (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_eon_device_vtable;
}
dc_status_t
suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
@ -139,9 +131,6 @@ suunto_eon_device_close (dc_device_t *abstract)
{
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
if (! device_is_suunto_eon (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -160,9 +149,6 @@ suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
if (! device_is_suunto_eon (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
@ -248,7 +234,7 @@ suunto_eon_device_write_name (dc_device_t *abstract, unsigned char data[], unsig
{
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
if (! device_is_suunto_eon (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size > 20)
@ -272,7 +258,7 @@ suunto_eon_device_write_interval (dc_device_t *abstract, unsigned char interval)
{
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
if (! device_is_suunto_eon (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Send the command.
@ -292,7 +278,7 @@ suunto_eon_extract_dives (dc_device_t *abstract, const unsigned char data[], uns
{
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
if (abstract && !device_is_suunto_eon (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -28,6 +28,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &suunto_eon_parser_vtable)
typedef struct suunto_eon_parser_t suunto_eon_parser_t;
struct suunto_eon_parser_t {
@ -55,16 +57,6 @@ static const dc_parser_vtable_t suunto_eon_parser_vtable = {
};
static int
parser_is_suunto_eon (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_eon_parser_vtable;
}
dc_status_t
suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder)
{
@ -96,9 +88,6 @@ suunto_eon_parser_create (dc_parser_t **out, dc_context_t *context, int spyder)
static dc_status_t
suunto_eon_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_suunto_eon (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -111,9 +100,6 @@ suunto_eon_parser_set_data (dc_parser_t *abstract, const unsigned char *data, un
{
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
if (! parser_is_suunto_eon (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -225,9 +211,6 @@ suunto_eon_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t c
{
suunto_eon_parser_t *parser = (suunto_eon_parser_t *) abstract;
if (! parser_is_suunto_eon (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -30,6 +30,8 @@
#include "serial.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &suunto_solution_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -59,15 +61,6 @@ static const dc_device_vtable_t suunto_solution_device_vtable = {
suunto_solution_device_close /* close */
};
static int
device_is_suunto_solution (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_solution_device_vtable;
}
dc_status_t
suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -132,9 +125,6 @@ suunto_solution_device_close (dc_device_t *abstract)
{
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
if (! device_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -153,9 +143,6 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
if (! device_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) {
@ -261,9 +248,6 @@ suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
suunto_solution_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -298,7 +282,7 @@ suunto_solution_device_foreach (dc_device_t *abstract, dc_dive_callback_t callba
dc_status_t
suunto_solution_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
if (abstract && !device_is_suunto_solution (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -27,6 +27,8 @@
#include "context-private.h"
#include "parser-private.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &suunto_solution_parser_vtable)
typedef struct suunto_solution_parser_t suunto_solution_parser_t;
struct suunto_solution_parser_t {
@ -52,16 +54,6 @@ static const dc_parser_vtable_t suunto_solution_parser_vtable = {
};
static int
parser_is_suunto_solution (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_solution_parser_vtable;
}
dc_status_t
suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -92,9 +84,6 @@ suunto_solution_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
suunto_solution_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -107,9 +96,6 @@ suunto_solution_parser_set_data (dc_parser_t *abstract, const unsigned char *dat
{
suunto_solution_parser_t *parser = (suunto_solution_parser_t *) abstract;
if (! parser_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -188,9 +174,6 @@ suunto_solution_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, u
static dc_status_t
suunto_solution_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{
if (! parser_is_suunto_solution (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -32,6 +32,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &suunto_vyper_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -86,16 +88,6 @@ static const suunto_common_layout_t suunto_spyder_layout = {
};
static int
device_is_suunto_vyper (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_vyper_device_vtable;
}
dc_status_t
suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *name)
{
@ -165,9 +157,6 @@ suunto_vyper_device_close (dc_device_t *abstract)
{
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
if (! device_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -266,9 +255,6 @@ suunto_vyper_device_read (dc_device_t *abstract, unsigned int address, unsigned
{
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
if (! device_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
unsigned int nbytes = 0;
while (nbytes < size) {
// Calculate the package size.
@ -302,9 +288,6 @@ suunto_vyper_device_write (dc_device_t *abstract, unsigned int address, const un
{
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
if (! device_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
unsigned int nbytes = 0;
while (nbytes < size) {
// Calculate the package size.
@ -460,7 +443,7 @@ suunto_vyper_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init, dc
dc_status_t
suunto_vyper_device_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int init)
{
if (! device_is_suunto_vyper (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
return suunto_vyper_read_dive (abstract, buffer, init, NULL);
@ -470,9 +453,6 @@ suunto_vyper_device_read_dive (dc_device_t *abstract, dc_buffer_t *buffer, int i
static dc_status_t
suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
if (! device_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) {
@ -490,9 +470,6 @@ suunto_vyper_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback,
{
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
if (! device_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
// Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = SZ_MEMORY;
@ -581,7 +558,7 @@ suunto_vyper_extract_dives (dc_device_t *abstract, const unsigned char data[], u
{
suunto_common_device_t *device = (suunto_common_device_t*) abstract;
if (abstract && !device_is_suunto_vyper (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -30,6 +30,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), (const dc_device_vtable_t *) &suunto_vyper2_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -74,15 +76,6 @@ static const suunto_common2_layout_t suunto_helo2_layout = {
0x7FFE /* rb_profile_end */
};
static int
device_is_suunto_vyper2 (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == (const dc_device_vtable_t *) &suunto_vyper2_device_vtable;
}
dc_status_t
suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -172,9 +165,6 @@ suunto_vyper2_device_close (dc_device_t *abstract)
{
suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract;
if (! device_is_suunto_vyper2 (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -251,7 +241,7 @@ suunto_vyper2_device_packet (dc_device_t *abstract, const unsigned char command[
dc_status_t
suunto_vyper2_device_version (dc_device_t *abstract, unsigned char data[], unsigned int size)
{
if (! device_is_suunto_vyper2 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
return suunto_common2_device_version (abstract, data, size);
@ -261,7 +251,7 @@ suunto_vyper2_device_version (dc_device_t *abstract, unsigned char data[], unsig
dc_status_t
suunto_vyper2_device_reset_maxdepth (dc_device_t *abstract)
{
if (! device_is_suunto_vyper2 (abstract))
if (!ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
return suunto_common2_device_reset_maxdepth (abstract);

View File

@ -27,6 +27,8 @@
#include "context-private.h"
#include "parser-private.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &suunto_vyper_parser_vtable)
typedef struct suunto_vyper_parser_t suunto_vyper_parser_t;
struct suunto_vyper_parser_t {
@ -53,16 +55,6 @@ static const dc_parser_vtable_t suunto_vyper_parser_vtable = {
};
static int
parser_is_suunto_vyper (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &suunto_vyper_parser_vtable;
}
dc_status_t
suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context)
{
@ -93,9 +85,6 @@ suunto_vyper_parser_create (dc_parser_t **out, dc_context_t *context)
static dc_status_t
suunto_vyper_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -108,9 +97,6 @@ suunto_vyper_parser_set_data (dc_parser_t *abstract, const unsigned char *data,
{
suunto_vyper_parser_t *parser = (suunto_vyper_parser_t *) abstract;
if (! parser_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
// Reset the cache.
parser->cached = 0;
parser->divetime = 0;
@ -209,9 +195,6 @@ suunto_vyper_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsi
static dc_status_t
suunto_vyper_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{
if (! parser_is_suunto_vyper (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_aladin_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -68,15 +70,6 @@ static const dc_device_vtable_t uwatec_aladin_device_vtable = {
uwatec_aladin_device_close /* close */
};
static int
device_is_uwatec_aladin (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &uwatec_aladin_device_vtable;
}
dc_status_t
uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -145,9 +138,6 @@ uwatec_aladin_device_close (dc_device_t *abstract)
{
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
if (! device_is_uwatec_aladin (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -166,9 +156,6 @@ uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char
{
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
if (! device_is_uwatec_aladin (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -186,9 +173,6 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
if (! device_is_uwatec_aladin (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// pre-allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_reserve (buffer, SZ_MEMORY)) {
@ -269,9 +253,6 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
uwatec_aladin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_uwatec_aladin (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (SZ_MEMORY);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -304,7 +285,7 @@ uwatec_aladin_extract_dives (dc_device_t *abstract, const unsigned char* data, u
{
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
if (abstract && !device_is_uwatec_aladin (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
if (size < SZ_MEMORY)

View File

@ -31,6 +31,8 @@
#include "checksum.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_memomouse_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -64,15 +66,6 @@ static const dc_device_vtable_t uwatec_memomouse_device_vtable = {
uwatec_memomouse_device_close /* close */
};
static int
device_is_uwatec_memomouse (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &uwatec_memomouse_device_vtable;
}
dc_status_t
uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const char *name)
@ -144,9 +137,6 @@ uwatec_memomouse_device_close (dc_device_t *abstract)
{
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract;
if (! device_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -165,9 +155,6 @@ uwatec_memomouse_device_set_fingerprint (dc_device_t *abstract, const unsigned c
{
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract;
if (! device_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -452,9 +439,6 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract;
if (! device_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
ERROR (abstract->context, "Insufficient buffer space available.");
@ -487,9 +471,6 @@ uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
uwatec_memomouse_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (0);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -512,7 +493,7 @@ uwatec_memomouse_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb
dc_status_t
uwatec_memomouse_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
if (abstract && !device_is_uwatec_memomouse (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
// Parse the data stream to find the total number of dives.

View File

@ -27,6 +27,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &uwatec_memomouse_parser_vtable)
typedef struct uwatec_memomouse_parser_t uwatec_memomouse_parser_t;
struct uwatec_memomouse_parser_t {
@ -51,16 +53,6 @@ static const dc_parser_vtable_t uwatec_memomouse_parser_vtable = {
};
static int
parser_is_uwatec_memomouse (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &uwatec_memomouse_parser_vtable;
}
dc_status_t
uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int devtime, dc_ticks_t systime)
{
@ -90,9 +82,6 @@ uwatec_memomouse_parser_create (dc_parser_t **out, dc_context_t *context, unsign
static dc_status_t
uwatec_memomouse_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -103,9 +92,6 @@ uwatec_memomouse_parser_destroy (dc_parser_t *abstract)
static dc_status_t
uwatec_memomouse_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}
@ -193,9 +179,6 @@ uwatec_memomouse_parser_get_field (dc_parser_t *abstract, dc_field_type_t type,
static dc_status_t
uwatec_memomouse_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t callback, void *userdata)
{
if (! parser_is_uwatec_memomouse (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -29,6 +29,8 @@
#include "irda.h"
#include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_smart_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -58,15 +60,6 @@ static const dc_device_vtable_t uwatec_smart_device_vtable = {
uwatec_smart_device_close /* close */
};
static int
device_is_uwatec_smart (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &uwatec_smart_device_vtable;
}
static void
uwatec_smart_discovery (unsigned int address, const char *name, unsigned int charset, unsigned int hints, void *userdata)
@ -219,9 +212,6 @@ uwatec_smart_device_close (dc_device_t *abstract)
{
uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract;
if (! device_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (irda_socket_close (device->socket) == -1) {
free (device);
@ -240,9 +230,6 @@ uwatec_smart_device_set_fingerprint (dc_device_t *abstract, const unsigned char
{
uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract;
if (! device_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
if (size && size != 4)
return DC_STATUS_INVALIDARGS;
@ -261,9 +248,6 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
if (! device_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer.
if (!dc_buffer_clear (buffer)) {
ERROR (abstract->context, "Insufficient buffer space available.");
@ -403,9 +387,6 @@ uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
static dc_status_t
uwatec_smart_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata)
{
if (! device_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
dc_buffer_t *buffer = dc_buffer_new (0);
if (buffer == NULL)
return DC_STATUS_NOMEMORY;
@ -428,7 +409,7 @@ uwatec_smart_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback,
dc_status_t
uwatec_smart_extract_dives (dc_device_t *abstract, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata)
{
if (abstract && !device_is_uwatec_smart (abstract))
if (abstract && !ISINSTANCE (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char header[4] = {0xa5, 0xa5, 0x5a, 0x5a};

View File

@ -29,6 +29,8 @@
#include "parser-private.h"
#include "array.h"
#define ISINSTANCE(parser) dc_parser_isinstance((parser), &uwatec_smart_parser_vtable)
#define NBITS 8
#define NELEMENTS(x) ( sizeof(x) / sizeof((x)[0]) )
@ -66,16 +68,6 @@ static const dc_parser_vtable_t uwatec_smart_parser_vtable = {
};
static int
parser_is_uwatec_smart (dc_parser_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &uwatec_smart_parser_vtable;
}
dc_status_t
uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model, unsigned int devtime, dc_ticks_t systime)
{
@ -106,9 +98,6 @@ uwatec_smart_parser_create (dc_parser_t **out, dc_context_t *context, unsigned i
static dc_status_t
uwatec_smart_parser_destroy (dc_parser_t *abstract)
{
if (! parser_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
// Free memory.
free (abstract);
@ -119,9 +108,6 @@ uwatec_smart_parser_destroy (dc_parser_t *abstract)
static dc_status_t
uwatec_smart_parser_set_data (dc_parser_t *abstract, const unsigned char *data, unsigned int size)
{
if (! parser_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
return DC_STATUS_SUCCESS;
}
@ -451,9 +437,6 @@ uwatec_smart_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t
{
uwatec_smart_parser_t *parser = (uwatec_smart_parser_t*) abstract;
if (! parser_is_uwatec_smart (abstract))
return DC_STATUS_INVALIDARGS;
const unsigned char *data = abstract->data;
unsigned int size = abstract->size;

View File

@ -32,6 +32,8 @@
#include "array.h"
#include "ringbuffer.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &zeagle_n2ition3_device_vtable)
#define EXITCODE(rc) \
( \
rc == -1 ? DC_STATUS_IO : DC_STATUS_TIMEOUT \
@ -69,15 +71,6 @@ static const dc_device_vtable_t zeagle_n2ition3_device_vtable = {
zeagle_n2ition3_device_close /* close */
};
static int
device_is_zeagle_n2ition3 (dc_device_t *abstract)
{
if (abstract == NULL)
return 0;
return abstract->vtable == &zeagle_n2ition3_device_vtable;
}
static dc_status_t
zeagle_n2ition3_packet (zeagle_n2ition3_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize)
@ -199,9 +192,6 @@ zeagle_n2ition3_device_close (dc_device_t *abstract)
{
zeagle_n2ition3_device_t *device = (zeagle_n2ition3_device_t*) abstract;
if (! device_is_zeagle_n2ition3 (abstract))
return DC_STATUS_INVALIDARGS;
// Close the device.
if (serial_close (device->port) == -1) {
free (device);
@ -237,9 +227,6 @@ zeagle_n2ition3_device_read (dc_device_t *abstract, unsigned int address, unsign
{
zeagle_n2ition3_device_t *device = (zeagle_n2ition3_device_t*) abstract;
if (! device_is_zeagle_n2ition3 (abstract))
return DC_STATUS_INVALIDARGS;
unsigned int nbytes = 0;
while (nbytes < size) {
// Calculate the package size.
@ -273,9 +260,6 @@ zeagle_n2ition3_device_read (dc_device_t *abstract, unsigned int address, unsign
static dc_status_t
zeagle_n2ition3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{
if (! device_is_zeagle_n2ition3 (abstract))
return DC_STATUS_INVALIDARGS;
// Erase the current contents of the buffer and
// allocate the required amount of memory.
if (!dc_buffer_clear (buffer) || !dc_buffer_resize (buffer, SZ_MEMORY)) {