source: roaraudio/include/libroar/error.h @ 5544:16ca0566b0e9

Last change on this file since 5544:16ca0566b0e9 was 5544:16ca0566b0e9, checked in by phi, 12 years ago

Improved error handling (including on win32) (Closes: #235)

File size: 4.6 KB
Line 
1//error.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
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
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
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
41struct roar_message;
42
43enum 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,
50 ROAR_ERROR_TYPE_HTTP
51};
52
53/*
54  Off Size (Byte)
55    | | /- Name
56    0 1 Version
57    1 1 Cmd
58    2 1 RA Errno
59    3 1 RA SubErrno
60    4 2 Portable Errno
61    6 2 Flags
62   (8 0 Datalen)
63    8 N Data
64 */
65
66struct roar_error_frame {
67 int version;
68 int cmd;
69 int ra_errno;
70 int ra_suberrno;
71 int p_errno;
72 uint16_t flags;
73 size_t datalen;
74 void * data;
75};
76
77struct roar_error_state {
78 size_t refc;
79 int libroar_error; // roar_error
80 int system_error; // errno
81#ifdef ROAR_TARGET_WIN32
82 int winsock_error; // WSAGetLastError(), WSASetLastError()
83#endif
84#ifdef ROAR_HAVE_VAR_H_ERRNO
85 int syssock_herror; // h_errno
86#endif
87#ifdef __YIFF__
88 yiffc_error_t yiffc_error; // yiffc_error
89#endif
90};
91
92struct roar_error_frame * roar_err_errorframe(void);
93
94int    roar_err_init(struct roar_error_frame * frame);
95void * roar_err_buildmsg(struct roar_message * mes, void ** data, struct roar_error_frame * frame);
96int    roar_err_parsemsg(struct roar_message * mes, void *  data, struct roar_error_frame * frame);
97
98#define roar_error (*roar_errno2())
99int *  roar_errno2(void);
100
101// clear RoarAudio's error value
102void   roar_err_clear(void);
103
104// clear system's error value (errno)
105void   roar_err_clear_errno(void);
106
107// clear all error values (to be used before calling roar_err_update())
108void   roar_err_clear_all(void);
109
110// syncs RoarAudio's and system's error values
111void   roar_err_update(void);
112
113// test of system's error value is set to 'no error'
114int    roar_err_is_errno_clear(void);
115
116// set RoarAudio's error value
117void   roar_err_set(const int error);
118
119// sync RoarAudio's error value with the value from the system
120void   roar_err_from_errno(void);
121
122// sync systen's error value with the value from RoarAudio
123void   roar_err_to_errno(void);
124
125// Convert error codes between diffrent representations.
126// returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state.
127int    roar_err_convert(int * out, const enum roar_error_type outtype, const int in, const enum roar_error_type intype);
128
129// Outputs a default error for the given type.
130// returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state.
131int    roar_err_get_default_error(int * out, const enum roar_error_type type);
132
133// Resets the stored state to 'no error' state. This can be used
134// to init the state.
135int    roar_err_initstore(struct roar_error_state * state);
136
137// store a error state (both libroar and system)
138// returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state.
139int    roar_err_store(struct roar_error_state * state);
140
141// restore error state to values at time of call to roar_err_store()
142// returnes the error or ROAR_ERROR_NONE on success so it does not alter global error state.
143int    roar_err_restore(struct roar_error_state * state);
144
145// Return a string descriping the error
146const char * roar_error2str(const int error);
147
148// Error string looking like a read only variable.
149#define roar_errorstring (roar_error2str(roar_error))
150
151#endif
152
153//ll
Note: See TracBrowser for help on using the repository browser.