Add a new device descriptor object.

As the name already indicates, a device descriptor is lightweight
object which describes a single device. Currently, the api supports
getting the device name (vendor and product) and model number. But
this can extended with other features when necessary.
This commit is contained in:
Jef Driesen 2012-05-20 20:47:26 +02:00
parent fbe712fc8f
commit a78cf2f939
5 changed files with 123 additions and 0 deletions

View File

@ -4,6 +4,7 @@ libdivecomputer_HEADERS = \
common.h \
utils.h \
buffer.h \
descriptor.h \
iterator.h \
device.h \
parser.h \

View File

@ -0,0 +1,48 @@
/*
* libdivecomputer
*
* Copyright (C) 2012 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifndef DC_DESCRIPTOR_H
#define DC_DESCRIPTOR_H
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct dc_descriptor_t dc_descriptor_t;
const char *
dc_descriptor_get_vendor (dc_descriptor_t *descriptor);
const char *
dc_descriptor_get_product (dc_descriptor_t *descriptor);
dc_family_t
dc_descriptor_get_type (dc_descriptor_t *descriptor);
unsigned int
dc_descriptor_get_model (dc_descriptor_t *descriptor);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DC_DESCRIPTOR_H */

View File

@ -11,6 +11,7 @@ libdivecomputer_la_LDFLAGS = \
libdivecomputer_la_SOURCES = \
version.c \
descriptor.c \
iterator-private.h iterator.c \
device-private.h device.c \
parser-private.h parser.c \

68
src/descriptor.c Normal file
View File

@ -0,0 +1,68 @@
/*
* libdivecomputer
*
* Copyright (C) 2012 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#include <stddef.h>
#include <stdlib.h>
#include <libdivecomputer/descriptor.h>
struct dc_descriptor_t {
const char *vendor;
const char *product;
dc_family_t type;
unsigned int model;
};
const char *
dc_descriptor_get_vendor (dc_descriptor_t *descriptor)
{
if (descriptor == NULL)
return NULL;
return descriptor->vendor;
}
const char *
dc_descriptor_get_product (dc_descriptor_t *descriptor)
{
if (descriptor == NULL)
return NULL;
return descriptor->product;
}
dc_family_t
dc_descriptor_get_type (dc_descriptor_t *descriptor)
{
if (descriptor == NULL)
return DC_FAMILY_NULL;
return descriptor->type;
}
unsigned int
dc_descriptor_get_model (dc_descriptor_t *descriptor)
{
if (descriptor == NULL)
return 0;
return descriptor->model;
}

View File

@ -20,6 +20,11 @@ dc_datetime_mktime
dc_iterator_next
dc_iterator_free
dc_descriptor_get_vendor
dc_descriptor_get_product
dc_descriptor_get_type
dc_descriptor_get_model
dc_parser_get_type
dc_parser_set_data
dc_parser_get_datetime