Implement custom device open method

This method can be used by external applications to open a
device and to pass their custom implementation for the
serial communication.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Claudiu Olteanu 2015-06-27 15:22:04 +03:00 committed by Dirk Hohndel
parent 5dbaa7a053
commit 8c3e44aa0c
2 changed files with 27 additions and 0 deletions

View File

@ -2,6 +2,7 @@
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
* Copyright (C) 2015 Claudiu Olteanu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -27,6 +28,7 @@
#include "descriptor.h"
#include "buffer.h"
#include "datetime.h"
#include "custom_serial.h"
#ifdef __cplusplus
extern "C" {
@ -72,6 +74,9 @@ typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size,
dc_status_t
dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name);
dc_status_t
dc_device_custom_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_serial_t *serial);
dc_family_t
dc_device_get_type (dc_device_t *device);

View File

@ -2,6 +2,7 @@
* libdivecomputer
*
* Copyright (C) 2008 Jef Driesen
* Copyright (C) 2015 Claudiu Olteanu
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -174,6 +175,27 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
return rc;
}
dc_status_t
dc_device_custom_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_serial_t *serial)
{
dc_status_t rc = DC_STATUS_SUCCESS;
dc_device_t *device = NULL;
if (out == NULL || descriptor == NULL || serial == NULL)
return DC_STATUS_INVALIDARGS;
switch (dc_descriptor_get_type (descriptor)) {
case DC_FAMILY_HW_OSTC3:
rc = hw_ostc3_device_custom_open (&device, context, serial);
break;
default:
return DC_STATUS_INVALIDARGS;
}
*out = device;
return rc;
}
int
dc_device_isinstance (dc_device_t *device, const dc_device_vtable_t *vtable)