23
|
1 /* Libvisual - The audio visualisation framework.
|
|
2 *
|
|
3 * Copyright (C) 2004, 2005 Dennis Smit <ds@nerds-incorporated.org>
|
|
4 *
|
|
5 * Authors: Dennis Smit <ds@nerds-incorporated.org>
|
|
6 *
|
|
7 * $Id:
|
|
8 *
|
|
9 * This program is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU Lesser General Public License as
|
|
11 * published by the Free Software Foundation; either version 2.1
|
|
12 * of the License, or (at your option) any later version.
|
|
13 *
|
|
14 * This program 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 Lesser General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU Lesser General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23
|
|
24 #include <stdlib.h>
|
|
25 #include <stdio.h>
|
|
26 #include <unistd.h>
|
|
27 #include <string.h>
|
|
28 #include <assert.h>
|
|
29 #include <signal.h>
|
|
30
|
|
31 #include "lv_log.h"
|
|
32 #include "lv_error.h"
|
|
33
|
|
34 static const char *__lv_error_human_readable[] = {
|
|
35 "There was no error", /* VISUAL_OK */
|
|
36
|
|
37 "General error occurred", /* VISUAL_ERROR_GENERAL */
|
|
38 "General NULL pointer error", /* VISUAL_ERROR_NULL */
|
|
39 "An impossible event occurred", /* VISUAL_ERROR_IMPOSSIBLE */
|
|
40
|
|
41 "VisActor is NULL", /* VISUAL_ERROR_ACTOR_NULL */
|
|
42 "VisActor it's video is NULL", /* VISUAL_ERROR_ACTOR_VIDEO_NULL */
|
|
43 "VisActor it's plugin is NULL", /* VISUAL_ERROR_ACTOR_PLUGIN_NULL */
|
|
44 "VisActor failed while trying to forcefully negotiate a GL surface", /* VISUAL_ERROR_ACTOR_GL_NEGOTIATE */
|
|
45
|
|
46 "VisAudio is NULL", /* VISUAL_ERROR_AUDIO_NULL */
|
|
47
|
|
48 "Bitmap is not a bitmap file", /* VISUAL_ERROR_BMP_NO_BMP */
|
|
49 "Bitmap can not be found", /* VISUAL_ERROR_BMP_NOT_FOUND */
|
|
50 "Bitmap is not supported", /* VISUAL_ERROR_BMP_NOT_SUPPORTED */
|
|
51 "Bitmap is corrupted", /* VISUAL_ERROR_BMP_CORRUPTED */
|
|
52
|
|
53 "VisColor is NULL", /* VISUAL_ERROR_COLOR_NULL */
|
|
54
|
|
55 "The code can not run on this architecture", /* VISUAL_ERROR_CPU_INVALID_CODE */
|
|
56
|
|
57 "Global error handler is NULL", /* VISUAL_ERROR_ERROR_HANDLER_NULL */
|
|
58
|
|
59 "VisEvent is NULL", /* VISUAL_ERROR_EVENT_NULL */
|
|
60 "VisEventQueue is NULL", /* VISUAL_ERROR_EVENT_QUEUE_NULL */
|
|
61
|
|
62 "VisInput is NULL", /* VISUAL_ERROR_INPUT_NULL */
|
|
63 "VisInput it's plugin is NULL", /* VISUAL_ERROR_INPUT_PLUGIN_NULL */
|
|
64
|
|
65 "No paths were given to seek for plugins", /* VISUAL_ERROR_LIBVISUAL_NO_PATHS */
|
|
66 "Libvisual is already initialized", /* VISUAL_ERROR_LIBVISUAL_ALREADY_INITIALIZED */
|
|
67 "Libvisual is not initialized", /* VISUAL_ERROR_LIBVISUAL_NOT_INITIALIZED */
|
|
68 "Libvisual has not build a plugin registry", /* VISUAL_ERROR_LIBVISUAL_NO_REGISTRY */
|
|
69
|
|
70 "VisList is NULL", /* VISUAL_ERROR_LIST_NULL */
|
|
71 "VisListEntry is NULL", /* VISUAL_ERROR_LIST_ENTRY_NULL */
|
|
72 "VisListEntry is invalid", /* VISUAL_ERROR_LIST_ENTRY_INVALID */
|
|
73
|
|
74 "Given memory pointer is NULL", /* VISUAL_ERROR_MEM_NULL */
|
|
75
|
|
76 "VisMorph is NULL", /* VISUAL_ERROR_MORPH_NULL */
|
|
77 "VisMorph it's plugin is NULL", /* VISUAL_ERROR_MORPH_PLUGIN_NULL */
|
|
78
|
|
79 "VisPalette is NULL", /* VISUAL_ERROR_PALETTE_NULL */
|
|
80 "VisPalette it's size conflicts", /* VISUAL_ERROR_PALETTE_SIZE */
|
|
81
|
|
82 "VisParamEntry is NULL", /* VISUAL_ERROR_PARAM_NULL */
|
|
83 "VisParamContainer is NULL", /* VISUAL_ERROR_PARAM_CONTAINER_NULL */
|
|
84 "VisParamEntry not found in VisParamContainer", /* VISUAL_ERROR_PARAM_NOT_FOUND */
|
|
85 "VisParamEntry it's change notify callback is NULL", /* VISUAL_ERROR_PARAM_CALLBACK_NULL */
|
|
86 "VisParamEntry contains too many change notify callbacks", /* VISUAL_ERROR_PARAM_CALLBACK_TOO_MANY */
|
|
87 "VisParamEntry is of invalid type", /* VISUAL_ERROR_PARAM_INVALID_TYPE */
|
|
88
|
|
89 "VisPluginData is NULL", /* VISUAL_ERROR_PLUGIN_NULL */
|
|
90 "VisPluginInfo is NULL", /* VISUAL_ERROR_PLUGIN_INFO_NULL */
|
|
91 "VisPluginRef is NULL", /* VISUAL_ERROR_PLUGIN_REF_NULL */
|
|
92 "VisPluginEnvironElement is NULL", /* VISUAL_ERROR_PLUGIN_ENVIRON_NULL */
|
|
93 "Plugin does not have an event handler", /* VISUAL_ERROR_PLUGIN_NO_EVENT_HANDLER */
|
|
94 "Plugin handle is NULL", /* VISUAL_ERROR_PLUGIN_HANDLE_NULL */
|
|
95 "Plugin is already realized", /* VISUAL_ERROR_PLUGIN_ALREADY_REALIZED */
|
|
96
|
|
97 "VisRandomContext is NULL", /* VISUAL_ERROR_RANDOM_CONTEXT_NULL */
|
|
98
|
|
99 "VisSongInfo is NULL", /* VISUAL_ERROR_SONGINFO_NULL */
|
|
100
|
|
101 "VisThread is NULL", /* VISUAL_ERROR_THREAD_NULL */
|
|
102 "Threading is disabled or not supported", /* VISUAL_ERROR_THREAD_NO_THREADING */
|
|
103 "VisMutex is NULL", /* VISUAL_ERROR_MUTEX_NULL */
|
|
104 "VisMutex lock failed", /* VISUAL_ERROR_MUTEX_LOCK_FAILURE */
|
|
105 "VisMutex trylock failed", /* VISUAL_ERROR_MUTEX_TRYLOCK_FAILURE */
|
|
106 "VisMutex unlock failed", /* VISUAL_ERROR_MUTEX_UNLOCK_FAILURE */
|
|
107
|
|
108 "VisTransform is NULL", /* VISUAL_ERROR_TRANSFORM_NULL */
|
|
109 "The VisTransform negotiate with the target VisVideo failed", /* VISUAL_ERROR_TRANSFORM_NEGOTIATE */
|
|
110 "The VisTransform it's plugin is NULL", /* VISUAL_ERROR_TRANSFORM_PLUGIN_NULL */
|
|
111 "The VisTransform it's video is NULL", /* VISUAL_ERROR_TRANSFORM_VIDEO_NULL */
|
|
112 "The VisTransform it's palette is NULL", /* VISUAL_ERROR_TRANSFORM_PALETTE_NULL */
|
|
113
|
|
114 "VisObject destruction failed", /* VISUAL_ERROR_OBJECT_DTOR_FAILED */
|
|
115 "VisObject is NULL", /* VISUAL_ERROR_OBJECT_NULL */
|
|
116 "VisObject is not allocated", /* VISUAL_ERROR_OBJECT_NOT_ALLOCATED */
|
|
117
|
|
118 "VisTime is NULL", /* VISUAL_ERROR_TIME_NULL */
|
|
119 "visual_time_usleep() is not supported", /* VISUAL_ERROR_TIME_NO_USLEEP */
|
|
120 "VisTimer is NULL", /* VISUAL_ERROR_TIMER_NULL */
|
|
121
|
|
122 "VisUIWidget is NULL", /* VISUAL_ERROR_UI_WIDGET_NULL */
|
|
123 "VisUIContainer is NULL", /* VISUAL_ERROR_UI_CONTAINER_NULL */
|
|
124 "VisUIBox is NULL", /* VISUAL_ERROR_UI_BOX_NULL */
|
|
125 "VisUITable is NULL", /* VISUAL_ERROR_UI_TABLE_NULL */
|
|
126 "VisUIFrame is NULL", /* VISUAL_ERROR_UI_FRAME_NULL */
|
|
127 "VisUILabel is NULL", /* VISUAL_ERROR_UI_LABEL_NULL */
|
|
128 "VisUIImage is NULL", /* VISUAL_ERROR_UI_IMAGE_NULL */
|
|
129 "VisUISeparator is NULL", /* VISUAL_ERROR_UI_SEPARATOR_NULL */
|
|
130 "VisUIMutator is NULL", /* VISUAL_ERROR_UI_MUTATOR_NULL */
|
|
131 "VisUIRange is NULL", /* VISUAL_ERROR_UI_RANGE_NULL */
|
|
132 "VisUIEntry is NULL", /* VISUAL_ERROR_UI_ENTRY_NULL */
|
|
133 "VisUISlider is NULL", /* VISUAL_ERROR_UI_SLIDER_NULL */
|
|
134 "VisUINumeric is NULL", /* VISUAL_ERROR_UI_NUMERIC_NULL */
|
|
135 "VisUIColor is NULL", /* VISUAL_ERROR_UI_COLOR_NULL */
|
|
136 "VisUIChoice is NULL", /* VISUAL_ERROR_UI_CHOICE_NULL */
|
|
137 "VisUIPopup is NULL", /* VISUAL_ERROR_UI_POPUP_NULL */
|
|
138 "VisUIList is NULL", /* VISUAL_ERROR_UI_LIST_NULL */
|
|
139 "VisUIRadio is NULL", /* VISUAL_ERROR_UI_RADIO_NULL */
|
|
140 "VisUICheckbox is NULL", /* VISUAL_ERROR_UI_CHECKBOX_NULL */
|
|
141 "VisUIChoiceEntry is NULL", /* VISUAL_ERROR_UI_CHOICE_ENTRY_NULL */
|
|
142 "No choice in VisUIChoice is activated", /* VISUAL_ERROR_UI_CHOICE_NONE_ACTIVE */
|
|
143
|
|
144 "VisVideo is NULL", /* VISUAL_ERROR_VIDEO_NULL */
|
|
145 "VisVideo has allocated pixel buffer", /* VISUAL_ERROR_VIDEO_HAS_ALLOCATED */
|
|
146 "VisVideo it's pixel buffer is NULL", /* VISUAL_ERROR_VIDEO_PIXELS_NULL */
|
|
147 "VisVideo it's pixel buffer is not allocated", /* VISUAL_ERROR_VIDEO_NO_ALLOCATED */
|
|
148 "VisVideo has pixel buffer", /* VISUAL_ERROR_VIDEO_HAS_PIXELS */
|
|
149 "VisVideo is of invalid bytes per pixel", /* VISUAL_ERROR_VIDEO_INVALID_BPP */
|
|
150 "VisVideo is of invalid depth", /* VISUAL_ERROR_VIDEO_INVALID_DEPTH */
|
|
151 "Invalid scale method given", /* VISUAL_ERROR_VIDEO_INVALID_SCALE_METHOD */
|
|
152 "Given coordinates are out of bounds", /* VISUAL_ERROR_VIDEO_OUT_OF_BOUNDS */
|
|
153 "Given VisVideos are not indentical", /* VISUAL_ERROR_VIDEO_NOT_INDENTICAL */
|
|
154 "VisVideo is not depth transformed as requested" /* VISUAL_ERROR_VIDEO_NOT_TRANSFORMED */
|
|
155 };
|
|
156
|
|
157 static VisErrorHandlerFunc error_handler = NULL;
|
|
158 static void *error_handler_priv = NULL;
|
|
159
|
|
160 /**
|
|
161 * @defgroup VisError VisError
|
|
162 * @{
|
|
163 */
|
|
164
|
|
165 /**
|
|
166 * Raise a libvisual error. With the standard error handler this will
|
|
167 * do a raise(SIGTRAP). You can set your own error handler function using the
|
|
168 * visual_error_set_handler.
|
|
169 *
|
|
170 * @see visual_error_set_handler
|
|
171 *
|
|
172 * @return Returns the return value from the handler that is set.
|
|
173 */
|
|
174 int visual_error_raise ()
|
|
175 {
|
|
176 if (error_handler == NULL) {
|
|
177 raise (SIGTRAP);
|
|
178 exit (1);
|
|
179 }
|
|
180
|
|
181 return error_handler (error_handler_priv);
|
|
182 }
|
|
183
|
|
184 /**
|
|
185 * Sets the error handler callback. By using this function you
|
|
186 * can override libvisual it's default error handler.
|
|
187 *
|
|
188 * @param handler The error handler which you want to use
|
|
189 * to handle libvisual errors.
|
|
190 * @param priv Optional private data which could be needed in the
|
|
191 * error handler that has been set.
|
|
192 *
|
|
193 * @return VISUAL_OK on succes, -VISUAL_ERROR_ERROR_HANDLER_NULL on failure.
|
|
194 */
|
|
195 int visual_error_set_handler (VisErrorHandlerFunc handler, void *priv)
|
|
196 {
|
|
197 visual_log_return_val_if_fail (handler != NULL, -VISUAL_ERROR_ERROR_HANDLER_NULL);
|
|
198
|
|
199 error_handler = handler;
|
|
200 error_handler_priv = priv;
|
|
201
|
|
202 return VISUAL_OK;
|
|
203 }
|
|
204
|
|
205 /**
|
|
206 * Translates an error into a human readable string, the returned string should not be freed.
|
|
207 *
|
|
208 * @param err Numeric error value.
|
|
209 *
|
|
210 * @return Human readable string, or NULL on failure.
|
|
211 */
|
|
212 const char *visual_error_to_string (int err)
|
|
213 {
|
|
214 if (abs (err) >= VISUAL_ERROR_LIST_END)
|
|
215 return "The error value given to visual_error_to_string() is invalid";
|
|
216
|
|
217 return __lv_error_human_readable[abs (err)];
|
|
218 }
|
|
219
|
|
220 /**
|
|
221 * @}
|
|
222 */
|
|
223
|