[797] | 1 | //error.h: |
---|
| 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[797] | 5 | * |
---|
| 6 | * This file is part of libroar a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[797] | 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #ifndef _LIBROARERROR_H_ |
---|
| 37 | #define _LIBROARERROR_H_ |
---|
| 38 | |
---|
| 39 | #include "libroar.h" |
---|
| 40 | |
---|
[3874] | 41 | struct roar_message; |
---|
| 42 | |
---|
[5544] | 43 | enum roar_error_type { |
---|
| 44 | ROAR_ERROR_TYPE_ROARAUDIO = 0, |
---|
| 45 | ROAR_ERROR_TYPE_ERRNO, |
---|
| 46 | ROAR_ERROR_TYPE_WINSOCK, |
---|
| 47 | ROAR_ERROR_TYPE_HERROR, |
---|
| 48 | ROAR_ERROR_TYPE_YIFF, |
---|
| 49 | ROAR_ERROR_TYPE_APPLICATION, |
---|
[5554] | 50 | ROAR_ERROR_TYPE_HTTP, |
---|
| 51 | ROAR_ERROR_TYPE_EAI /* getaddrinfo() and friends */ |
---|
[5544] | 52 | }; |
---|
| 53 | |
---|
[3877] | 54 | /* |
---|
| 55 | Off Size (Byte) |
---|
| 56 | | | /- Name |
---|
| 57 | 0 1 Version |
---|
| 58 | 1 1 Cmd |
---|
| 59 | 2 1 RA Errno |
---|
| 60 | 3 1 RA SubErrno |
---|
| 61 | 4 2 Portable Errno |
---|
| 62 | 6 2 Flags |
---|
| 63 | (8 0 Datalen) |
---|
| 64 | 8 N Data |
---|
| 65 | */ |
---|
| 66 | |
---|
| 67 | struct roar_error_frame { |
---|
| 68 | int version; |
---|
| 69 | int cmd; |
---|
| 70 | int ra_errno; |
---|
| 71 | int ra_suberrno; |
---|
| 72 | int p_errno; |
---|
| 73 | uint16_t flags; |
---|
| 74 | size_t datalen; |
---|
| 75 | void * data; |
---|
| 76 | }; |
---|
| 77 | |
---|
[5154] | 78 | struct roar_error_state { |
---|
| 79 | size_t refc; |
---|
[5251] | 80 | int libroar_error; // roar_error |
---|
| 81 | int system_error; // errno |
---|
| 82 | #ifdef ROAR_TARGET_WIN32 |
---|
| 83 | int winsock_error; // WSAGetLastError(), WSASetLastError() |
---|
[5286] | 84 | #endif |
---|
| 85 | #ifdef ROAR_HAVE_VAR_H_ERRNO |
---|
[5251] | 86 | int syssock_herror; // h_errno |
---|
| 87 | #endif |
---|
| 88 | #ifdef __YIFF__ |
---|
| 89 | yiffc_error_t yiffc_error; // yiffc_error |
---|
| 90 | #endif |
---|
[5154] | 91 | }; |
---|
| 92 | |
---|
[5146] | 93 | struct roar_error_frame * roar_err_errorframe(void); |
---|
| 94 | |
---|
| 95 | int roar_err_init(struct roar_error_frame * frame); |
---|
[5216] | 96 | void * roar_err_buildmsg(struct roar_message * mes, void ** data, struct roar_error_frame * frame); |
---|
| 97 | int roar_err_parsemsg(struct roar_message * mes, void * data, struct roar_error_frame * frame); |
---|
[3874] | 98 | |
---|
[4873] | 99 | #define roar_error (*roar_errno2()) |
---|
[4869] | 100 | int * roar_errno2(void); |
---|
| 101 | |
---|
[4872] | 102 | // clear RoarAudio's error value |
---|
[4185] | 103 | void roar_err_clear(void); |
---|
[4872] | 104 | |
---|
| 105 | // clear system's error value (errno) |
---|
[4871] | 106 | void roar_err_clear_errno(void); |
---|
[4872] | 107 | |
---|
| 108 | // clear all error values (to be used before calling roar_err_update()) |
---|
[4871] | 109 | void roar_err_clear_all(void); |
---|
[4872] | 110 | |
---|
| 111 | // syncs RoarAudio's and system's error values |
---|
[4871] | 112 | void roar_err_update(void); |
---|
[4872] | 113 | |
---|
| 114 | // test of system's error value is set to 'no error' |
---|
[5154] | 115 | int roar_err_is_errno_clear(void); |
---|
| 116 | |
---|
[4872] | 117 | // set RoarAudio's error value |
---|
[4869] | 118 | void roar_err_set(const int error); |
---|
[4872] | 119 | |
---|
| 120 | // sync RoarAudio's error value with the value from the system |
---|
[4185] | 121 | void roar_err_from_errno(void); |
---|
[4872] | 122 | |
---|
| 123 | // sync systen's error value with the value from RoarAudio |
---|
[4185] | 124 | void roar_err_to_errno(void); |
---|
| 125 | |
---|
[5544] | 126 | // Convert error codes between diffrent representations. |
---|
| 127 | // returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state. |
---|
| 128 | int roar_err_convert(int * out, const enum roar_error_type outtype, const int in, const enum roar_error_type intype); |
---|
| 129 | |
---|
| 130 | // Outputs a default error for the given type. |
---|
| 131 | // returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state. |
---|
| 132 | int roar_err_get_default_error(int * out, const enum roar_error_type type); |
---|
| 133 | |
---|
[5312] | 134 | // Resets the stored state to 'no error' state. This can be used |
---|
| 135 | // to init the state. |
---|
| 136 | int roar_err_initstore(struct roar_error_state * state); |
---|
| 137 | |
---|
[5154] | 138 | // store a error state (both libroar and system) |
---|
[5539] | 139 | // returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state. |
---|
[5154] | 140 | int roar_err_store(struct roar_error_state * state); |
---|
| 141 | |
---|
| 142 | // restore error state to values at time of call to roar_err_store() |
---|
[5539] | 143 | // returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state. |
---|
[5154] | 144 | int roar_err_restore(struct roar_error_state * state); |
---|
| 145 | |
---|
[4872] | 146 | // Return a string descriping the error |
---|
[4793] | 147 | const char * roar_error2str(const int error); |
---|
| 148 | |
---|
[5538] | 149 | // Error string looking like a read only variable. |
---|
| 150 | #define roar_errorstring (roar_error2str(roar_error)) |
---|
| 151 | |
---|
[797] | 152 | #endif |
---|
| 153 | |
---|
| 154 | //ll |
---|