test
Fork of mbed-libxively-6eca970 by
src/libxively/xi_err.h@0:82702e998d3f, 2013-06-26 (annotated)
- Committer:
- xively
- Date:
- Wed Jun 26 10:40:43 2013 +0000
- Revision:
- 0:82702e998d3f
libxively v0.1.1-rc0 (34c8b32)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xively | 0:82702e998d3f | 1 | // Copyright (c) 2003-2013, LogMeIn, Inc. All rights reserved. |
xively | 0:82702e998d3f | 2 | // This is part of Xively C library, it is under the BSD 3-Clause license. |
xively | 0:82702e998d3f | 3 | |
xively | 0:82702e998d3f | 4 | /** |
xively | 0:82702e998d3f | 5 | * \file xi_err.h |
xively | 0:82702e998d3f | 6 | * \author Olgierd Humenczuk |
xively | 0:82702e998d3f | 7 | * \brief Error handling (POSIX-like) |
xively | 0:82702e998d3f | 8 | * |
xively | 0:82702e998d3f | 9 | * * Every function should return a value |
xively | 0:82702e998d3f | 10 | * * There are special values (usually `0` or `-1`) which indicate occurrence of an error |
xively | 0:82702e998d3f | 11 | * * User can detect and lookup errors using declarations below |
xively | 0:82702e998d3f | 12 | */ |
xively | 0:82702e998d3f | 13 | |
xively | 0:82702e998d3f | 14 | #ifndef __XI_ERR_H__ |
xively | 0:82702e998d3f | 15 | #define __XI_ERR_H__ |
xively | 0:82702e998d3f | 16 | |
xively | 0:82702e998d3f | 17 | #ifdef __cplusplus |
xively | 0:82702e998d3f | 18 | extern "C" { |
xively | 0:82702e998d3f | 19 | #endif |
xively | 0:82702e998d3f | 20 | |
xively | 0:82702e998d3f | 21 | typedef enum |
xively | 0:82702e998d3f | 22 | { |
xively | 0:82702e998d3f | 23 | XI_NO_ERR = 0 |
xively | 0:82702e998d3f | 24 | , XI_OUT_OF_MEMORY |
xively | 0:82702e998d3f | 25 | , XI_HTTP_STATUS_PARSE_ERROR |
xively | 0:82702e998d3f | 26 | , XI_HTTP_HEADER_PARSE_ERROR |
xively | 0:82702e998d3f | 27 | , XI_HTTP_PARSE_ERROR |
xively | 0:82702e998d3f | 28 | , XI_HTTP_ENCODE_CREATE_DATASTREAM |
xively | 0:82702e998d3f | 29 | , XI_HTTP_ENCODE_UPDATE_DATASTREAM |
xively | 0:82702e998d3f | 30 | , XI_HTTP_ENCODE_GET_DATASTREAM |
xively | 0:82702e998d3f | 31 | , XI_HTTP_ENCODE_DELETE_DATASTREAM |
xively | 0:82702e998d3f | 32 | , XI_HTTP_ENCODE_DELETE_DATAPOINT |
xively | 0:82702e998d3f | 33 | , XI_HTTP_ENCODE_DELETE_RANGE_DATAPOINT |
xively | 0:82702e998d3f | 34 | , XI_HTTP_ENCODE_UPDATE_FEED |
xively | 0:82702e998d3f | 35 | , XI_HTTP_CONSTRUCT_REQUEST_BUFFER_OVERRUN |
xively | 0:82702e998d3f | 36 | , XI_HTTP_CONSTRUCT_CONTENT_BUFFER_OVERRUN |
xively | 0:82702e998d3f | 37 | , XI_CSV_ENCODE_DATAPOINT_BUFFER_OVERRUN |
xively | 0:82702e998d3f | 38 | , XI_CSV_ENCODE_DATASTREAM_BUFFER_OVERRUN |
xively | 0:82702e998d3f | 39 | , XI_CSV_DECODE_FEED_PARSER_ERROR |
xively | 0:82702e998d3f | 40 | , XI_CSV_DECODE_DATAPOINT_PARSER_ERROR |
xively | 0:82702e998d3f | 41 | , XI_CSV_TIME_CONVERTION_ERROR |
xively | 0:82702e998d3f | 42 | , XI_SOCKET_INITIALIZATION_ERROR |
xively | 0:82702e998d3f | 43 | , XI_SOCKET_GETHOSTBYNAME_ERROR |
xively | 0:82702e998d3f | 44 | , XI_SOCKET_CONNECTION_ERROR |
xively | 0:82702e998d3f | 45 | , XI_SOCKET_SHUTDOWN_ERROR |
xively | 0:82702e998d3f | 46 | , XI_SOCKET_WRITE_ERROR |
xively | 0:82702e998d3f | 47 | , XI_SOCKET_READ_ERROR |
xively | 0:82702e998d3f | 48 | , XI_SOCKET_CLOSE_ERROR |
xively | 0:82702e998d3f | 49 | , XI_DATAPOINT_VALUE_BUFFER_OVERFLOW |
xively | 0:82702e998d3f | 50 | , XI_ERR_COUNT |
xively | 0:82702e998d3f | 51 | } xi_err_t; |
xively | 0:82702e998d3f | 52 | |
xively | 0:82702e998d3f | 53 | #define XI_MAX_ERR_STRING 64 |
xively | 0:82702e998d3f | 54 | |
xively | 0:82702e998d3f | 55 | /** |
xively | 0:82702e998d3f | 56 | * \brief Error description lookup table |
xively | 0:82702e998d3f | 57 | */ |
xively | 0:82702e998d3f | 58 | extern const char* xi_err_string[ XI_ERR_COUNT ]; |
xively | 0:82702e998d3f | 59 | |
xively | 0:82702e998d3f | 60 | /** |
xively | 0:82702e998d3f | 61 | * \brief Error getter for the user |
xively | 0:82702e998d3f | 62 | * \return The `xi_err_t` structure which can be converted to a string using `xi_get_error_string()` method. |
xively | 0:82702e998d3f | 63 | * |
xively | 0:82702e998d3f | 64 | * \warning It resets the last error value, so it's always a good idea to make a copy of it! |
xively | 0:82702e998d3f | 65 | */ |
xively | 0:82702e998d3f | 66 | extern xi_err_t xi_get_last_error( void ); |
xively | 0:82702e998d3f | 67 | |
xively | 0:82702e998d3f | 68 | /** |
xively | 0:82702e998d3f | 69 | * \brief Error setter for the library itself |
xively | 0:82702e998d3f | 70 | * \note Current implementation used a global state variable (_errno_), which is not thread-safe. |
xively | 0:82702e998d3f | 71 | * If thread-safety is required, than _errno_ should be made thread-local. |
xively | 0:82702e998d3f | 72 | */ |
xively | 0:82702e998d3f | 73 | extern void xi_set_err( xi_err_t e ); |
xively | 0:82702e998d3f | 74 | |
xively | 0:82702e998d3f | 75 | /** |
xively | 0:82702e998d3f | 76 | * \brief Error description string getter for a given value of `xi_err_t` |
xively | 0:82702e998d3f | 77 | */ |
xively | 0:82702e998d3f | 78 | extern const char* xi_get_error_string( xi_err_t e ); |
xively | 0:82702e998d3f | 79 | |
xively | 0:82702e998d3f | 80 | #ifdef __cplusplus |
xively | 0:82702e998d3f | 81 | } |
xively | 0:82702e998d3f | 82 | #endif |
xively | 0:82702e998d3f | 83 | |
xively | 0:82702e998d3f | 84 | #endif // __XI_ERR_H__ |