diff options
-rw-r--r-- | libjaylink/Makefile.am | 1 | ||||
-rw-r--r-- | libjaylink/error.c | 82 | ||||
-rw-r--r-- | libjaylink/libjaylink.h | 3 |
3 files changed, 86 insertions, 0 deletions
diff --git a/libjaylink/Makefile.am b/libjaylink/Makefile.am index f957b23..b285735 100644 --- a/libjaylink/Makefile.am +++ b/libjaylink/Makefile.am @@ -24,6 +24,7 @@ libjaylink_la_SOURCES = \ core.c \ device.c \ discovery.c \ + error.c \ list.c \ log.c \ transport.c \ diff --git a/libjaylink/error.c b/libjaylink/error.c new file mode 100644 index 0000000..0c5934b --- /dev/null +++ b/libjaylink/error.c @@ -0,0 +1,82 @@ +/* + * This file is part of the libjaylink project. + * + * Copyright (C) 2014 Marc Schink <jaylink-dev@marcschink.de> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "libjaylink.h" + +/** + * @file + * + * Error handling. + */ + +/** + * Return a human-readable description of a libjaylink error code. + * + * @param error_code A libjaylink error code. See #jaylink_error for valid + * values. + * + * @return A string which describes the given error code or the string + * <i>unknown error</i> if the error code is not known. The string is + * null-terminated and must not be free'd by the caller. + */ +const char *jaylink_strerror(int error_code) +{ + switch (error_code) { + case JAYLINK_OK: + return "no error"; + case JAYLINK_ERR: + return "unspecified error"; + case JAYLINK_ERR_MALLOC: + return "memory allocation error"; + case JAYLINK_ERR_ARG: + return "invalid argument"; + case JAYLINK_ERR_TIMEOUT: + return "timeout occurred"; + default: + return "unknown error"; + } +} + +/** + * Return the name of a libjaylink error code. + * + * @param error_code A libjaylink error code. See #jaylink_error for valid + * values. + * + * @return A string which contains the name for the given error code or the + * string <i>unknown error code</i> if the error code is not known. The + * string is null-terminated and must not be free'd by the caller. + */ +const char *jaylink_strerror_name(int error_code) +{ + switch (error_code) { + case JAYLINK_OK: + return "JAYLINK_OK"; + case JAYLINK_ERR: + return "JAYLINK_ERR"; + case JAYLINK_ERR_MALLOC: + return "JAYLINK_ERR_MALLOC"; + case JAYLINK_ERR_ARG: + return "JAYLINK_ERR_ARG"; + case JAYLINK_ERR_TIMEOUT: + return "JAYLINK_ERR_TIMEOUT"; + default: + return "unknown error code"; + } +} diff --git a/libjaylink/libjaylink.h b/libjaylink/libjaylink.h index bb61658..14a1268 100644 --- a/libjaylink/libjaylink.h +++ b/libjaylink/libjaylink.h @@ -107,6 +107,9 @@ struct jaylink_device_handle; int jaylink_init(struct jaylink_context **ctx); void jaylink_exit(struct jaylink_context *ctx); +const char *jaylink_strerror(int error_code); +const char *jaylink_strerror_name(int error_code); + int jaylink_log_set_level(struct jaylink_context *ctx, int level); int jaylink_log_get_level(const struct jaylink_context *ctx); |