Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/openal-0.0.8/src/alc/alc_error.c @ 17

Last change on this file since 17 was 17, checked in by landauf, 16 years ago

added openal

File size: 3.6 KB
Line 
1/* -*- mode: C; tab-width:8; c-basic-offset:8 -*-
2 * vi:set ts=8:
3 *
4 * alc_error.c
5 *
6 * openal error reporting.
7 *
8 */
9#include "al_siteconfig.h"
10
11#include <AL/al.h>
12#include <AL/alc.h>
13
14#include "al_debug.h"
15#include "al_main.h"
16
17#include "alc/alc_error.h"
18
19/*
20 * alcErrorIndex is a simple index referring to an error.
21 */
22static int alcErrorIndex = 0;
23
24/*
25 * _alcErrorStr is a table of string representations of ALC errors.
26 *
27 * 0 -> ALC_NO_ERROR
28 * 1 -> ALC_INVALID_DEVICE
29 * 2 -> ALC_INVALID_CONTEXT
30 * 3 -> ALC_INVALID_ENUM
31 * 4 -> ALC_INVALID_VALUE
32 */
33static const char *_alcErrorStr[] = {
34        "No alc error.",
35        "There is no accessible sound device/driver/server",
36        "The Context argument does not name a valid context",
37        "Illegal paramater",
38        "Invalid enum parameter value"
39};
40
41/*
42 * ErrorNo2index( ALenum error_number )
43 *
44 * Returns a simple index from an alc error.
45 */
46static int ErrorNo2index( ALenum error_number );
47
48/*
49 * index2ErrorNo( int index )
50 *
51 * Returns an alc error from a simple index.
52 */
53static int index2ErrorNo( int ind );
54
55/*
56 * ErrorNo2index( ALenum error_number )
57 *
58 * Returns a simple index from an alc error.
59 */
60static int ErrorNo2index( ALenum error_number ) {
61        switch( error_number ) {
62                case ALC_NO_ERROR:
63                        return 0;
64                case ALC_INVALID_DEVICE:
65                        return 1;
66                case ALC_INVALID_CONTEXT:
67                        return 2;
68                case ALC_INVALID_ENUM:
69                        return 3;
70                case ALC_INVALID_VALUE:
71                        return 4;
72                default:
73                        _alDebug( ALD_ERROR, __FILE__, __LINE__,
74                                  "Unknown error condition: 0x%x", error_number );
75                        return -1;
76        }
77}
78
79/*
80 * index2ErrorNo( int index )
81 *
82 * Returns an alc error from a simple index.
83 */
84static int index2ErrorNo(int ind) {
85        switch(ind) {
86                case 0:
87                  return ALC_NO_ERROR;
88                  break;
89                case 1:
90                  return ALC_INVALID_DEVICE;
91                  break;
92                case 2:
93                  return ALC_INVALID_CONTEXT;
94                  break;
95                case 3:
96                  return ALC_INVALID_ENUM;
97                  break;
98                case 4:
99                  return ALC_INVALID_VALUE;
100                  break;
101                default:
102                  _alDebug(ALD_ERROR, __FILE__, __LINE__,
103                        "Unknown error index: %d", ind);
104                  break;
105        }
106
107        return -1;
108}
109
110/**
111 * Error support.
112 */
113
114/*
115 * alcGetError( ALCdevice *dev )
116 *
117 * Returns the most recent error generated in the AL state machine,
118 * but for alc.
119 */
120ALCenum alcGetError( UNUSED(ALCdevice *dev) )
121{
122        ALCenum retval;
123
124        retval = index2ErrorNo( alcErrorIndex );
125
126        /*
127         * In deference to the new spec, GetError clears the error
128         * after reading it.
129         */
130        alcErrorIndex = 0;
131
132        return retval;
133}
134
135/*
136 * _alcSetError( ALenum param )
137 *
138 * Sets the alc error, if unset.
139 */
140void _alcSetError( ALenum param ) {
141        int setval;
142
143        setval = ErrorNo2index( param );
144        if(setval == -1) {
145                /* invalid param*/
146                return;
147        }
148
149        if( alcErrorIndex == 0 ) {
150                /*
151                 * Only set error if no previous error has been recorded.
152                 */
153
154                alcErrorIndex = setval;
155        }
156
157        return;
158}
159
160/*
161 * _alcGetErrorString( ALenum param )
162 *
163 * This function returns the string corresponding to the
164 * error in question.  It doesn't validate that the passed
165 * param, so calling functions should ensure that _alcIsError(param)
166 * return AL_TRUE before passing it to this function.
167 */
168const ALubyte *_alcGetErrorString(ALenum param) {
169        int offset;
170
171        offset = ErrorNo2index( param );
172
173        if(offset >= 0) {
174                return (const ALubyte *) _alcErrorStr[ offset ];
175        }
176
177        return NULL;
178}
179
180/*
181 * alcIsError( ALenum param )
182 *
183 * Returns AL_TRUE if param is an alc error, AL_FALSE otherwise.
184 */
185ALboolean alcIsError( ALenum param ) {
186        switch( param ) {
187                case ALC_NO_ERROR:
188                case ALC_INVALID_DEVICE:
189                case ALC_INVALID_CONTEXT:
190                case ALC_INVALID_ENUM:
191                case ALC_INVALID_VALUE:
192                        return AL_TRUE;
193                        break;
194                default:
195                        break;
196        }
197
198        return AL_FALSE;
199}
Note: See TracBrowser for help on using the repository browser.