From e276ec65ba17e9eeea9625796ae5df96e654f65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20Cu=C3=B1at?= Date: Fri, 3 Apr 2015 21:33:10 +0200 Subject: [PATCH] Add errmsg() function for libdivecomputer.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Taken as is from libdivecomputer exaples/common.c to improve verbosity on libdc return codes. Intended to be used on error messages shown to the user on main window complementarily to those messages managed by dev_info(). Signed-off-by: Salvador Cuñat Signed-off-by: Dirk Hohndel --- libdivecomputer.c | 34 ++++++++++++++++++++++++++++++++++ libdivecomputer.h | 1 + 2 files changed, 35 insertions(+) diff --git a/libdivecomputer.c b/libdivecomputer.c index 950b9da4e..27e3dbd10 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -26,6 +26,40 @@ double progress_bar_fraction = 0.0; static int stoptime, stopdepth, ndl, po2, cns; static bool in_deco, first_temp_is_air; +/* + * Directly taken from libdivecomputer's examples/common.c to improve + * the error messages resulting from libdc's return codes + */ +const char *errmsg (dc_status_t rc) +{ + switch (rc) { + case DC_STATUS_SUCCESS: + return "Success"; + case DC_STATUS_UNSUPPORTED: + return "Unsupported operation"; + case DC_STATUS_INVALIDARGS: + return "Invalid arguments"; + case DC_STATUS_NOMEMORY: + return "Out of memory"; + case DC_STATUS_NODEVICE: + return "No device found"; + case DC_STATUS_NOACCESS: + return "Access denied"; + case DC_STATUS_IO: + return "Input/output error"; + case DC_STATUS_TIMEOUT: + return "Timeout"; + case DC_STATUS_PROTOCOL: + return "Protocol error"; + case DC_STATUS_DATAFORMAT: + return "Data format error"; + case DC_STATUS_CANCELLED: + return "Cancelled"; + default: + return "Unknown error"; + } +} + static dc_status_t create_parser(device_data_t *devdata, dc_parser_t **parser) { return dc_parser_new(parser, devdata->device); diff --git a/libdivecomputer.h b/libdivecomputer.h index eaaa998bc..d1e4ad9a4 100644 --- a/libdivecomputer.h +++ b/libdivecomputer.h @@ -41,6 +41,7 @@ typedef struct device_data_t struct dive_table *download_table; } device_data_t; +const char *errmsg (dc_status_t rc); const char *do_libdivecomputer_import(device_data_t *data); const char *do_uemis_import(device_data_t *data);