2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 * @short_description: Categorized error messages
24 * This module manages localizable error messages. Developers can use
25 * gst_error_get_message() to get a localized message from a error-code and
33 #include "gst_private.h"
35 #include "gst-i18n-lib.h"
37 #define TABLE(t, d, a, b) t[GST_ ## d ## _ERROR_ ## a] = g_strdup (b)
38 #define QUARK_FUNC(string) \
39 GQuark gst_ ## string ## _error_quark (void) { \
40 static GQuark quark; \
42 quark = g_quark_from_static_string ("gst-" # string "-error-quark"); \
46 gst_g_error_get_type (void)
48 static GType type = 0;
51 type = g_boxed_type_register_static ("GstGError",
52 (GBoxedCopyFunc) g_error_copy, (GBoxedFreeFunc) g_error_free);
56 #define FILE_A_BUG " Please file a bug at "\
57 "http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer."
59 /* initialize the dynamic table of translated core errors */
61 _gst_core_errors_init (void)
65 t = g_new0 (gchar *, GST_CORE_ERROR_NUM_ERRORS);
67 TABLE (t, CORE, FAILED,
68 N_("GStreamer encountered a general core library error."));
69 TABLE (t, CORE, TOO_LAZY,
70 N_("GStreamer developers were too lazy to assign an error code "
71 "to this error." FILE_A_BUG));
72 TABLE (t, CORE, NOT_IMPLEMENTED,
73 N_("Internal GStreamer error: code not implemented." FILE_A_BUG));
74 TABLE (t, CORE, STATE_CHANGE,
75 N_("Internal GStreamer error: state change failed." FILE_A_BUG));
76 TABLE (t, CORE, PAD, N_("Internal GStreamer error: pad problem." FILE_A_BUG));
77 TABLE (t, CORE, THREAD,
78 N_("Internal GStreamer error: thread problem." FILE_A_BUG));
79 TABLE (t, CORE, NEGOTIATION,
80 N_("Internal GStreamer error: negotiation problem." FILE_A_BUG));
81 TABLE (t, CORE, EVENT,
82 N_("Internal GStreamer error: event problem." FILE_A_BUG));
84 N_("Internal GStreamer error: seek problem." FILE_A_BUG));
86 N_("Internal GStreamer error: caps problem." FILE_A_BUG));
87 TABLE (t, CORE, TAG, N_("Internal GStreamer error: tag problem." FILE_A_BUG));
92 /* initialize the dynamic table of translated library errors */
94 _gst_library_errors_init (void)
98 t = g_new0 (gchar *, GST_LIBRARY_ERROR_NUM_ERRORS);
100 TABLE (t, LIBRARY, FAILED,
101 N_("GStreamer encountered a general supporting library error."));
102 TABLE (t, LIBRARY, TOO_LAZY,
103 N_("GStreamer developers were too lazy to assign an error code "
104 "to this error." FILE_A_BUG));
105 TABLE (t, LIBRARY, INIT, N_("Could not initialize supporting library."));
106 TABLE (t, LIBRARY, SHUTDOWN, N_("Could not close supporting library."));
107 TABLE (t, LIBRARY, SETTINGS, N_("Could not close supporting library."));
112 /* initialize the dynamic table of translated resource errors */
114 _gst_resource_errors_init (void)
118 t = g_new0 (gchar *, GST_RESOURCE_ERROR_NUM_ERRORS);
120 TABLE (t, RESOURCE, FAILED,
121 N_("GStreamer encountered a general resource error."));
122 TABLE (t, RESOURCE, TOO_LAZY,
123 N_("GStreamer developers were too lazy to assign an error code "
124 "to this error." FILE_A_BUG));
125 TABLE (t, RESOURCE, NOT_FOUND, N_("Resource not found."));
126 TABLE (t, RESOURCE, BUSY, N_("Resource busy or not available."));
127 TABLE (t, RESOURCE, OPEN_READ, N_("Could not open resource for reading."));
128 TABLE (t, RESOURCE, OPEN_WRITE, N_("Could not open resource for writing."));
129 TABLE (t, RESOURCE, OPEN_READ_WRITE,
130 N_("Could not open resource for reading and writing."));
131 TABLE (t, RESOURCE, CLOSE, N_("Could not close resource."));
132 TABLE (t, RESOURCE, READ, N_("Could not read from resource."));
133 TABLE (t, RESOURCE, WRITE, N_("Could not write to resource."));
134 TABLE (t, RESOURCE, SEEK, N_("Could not perform seek on resource."));
135 TABLE (t, RESOURCE, SYNC, N_("Could not synchronize on resource."));
136 TABLE (t, RESOURCE, SETTINGS,
137 N_("Could not get/set settings from/on resource."));
142 /* initialize the dynamic table of translated stream errors */
144 _gst_stream_errors_init (void)
148 t = g_new0 (gchar *, GST_STREAM_ERROR_NUM_ERRORS);
150 TABLE (t, STREAM, FAILED,
151 N_("GStreamer encountered a general stream error."));
152 TABLE (t, STREAM, TOO_LAZY,
153 N_("GStreamer developers were too lazy to assign an error code "
154 "to this error." FILE_A_BUG));
155 TABLE (t, STREAM, NOT_IMPLEMENTED,
156 N_("Element doesn't implement handling of this stream. "
157 "Please file a bug."));
158 TABLE (t, STREAM, TYPE_NOT_FOUND, N_("Could not determine type of stream."));
159 TABLE (t, STREAM, WRONG_TYPE,
160 N_("The stream is of a different type than handled by this element."));
161 TABLE (t, STREAM, CODEC_NOT_FOUND,
162 N_("There is no codec present that can handle the stream's type."));
163 TABLE (t, STREAM, DECODE, N_("Could not decode stream."));
164 TABLE (t, STREAM, ENCODE, N_("Could not encode stream."));
165 TABLE (t, STREAM, DEMUX, N_("Could not demultiplex stream."));
166 TABLE (t, STREAM, MUX, N_("Could not multiplex stream."));
172 QUARK_FUNC (library);
173 QUARK_FUNC (resource);
177 * gst_error_get_message:
178 * @domain: the GStreamer error domain this error belongs to.
179 * @code: the error code belonging to the domain.
181 * Get a string describing the error message in the current locale.
183 * Returns: a newly allocated string describing the error message in the
187 gst_error_get_message (GQuark domain, gint code)
189 static gchar **gst_core_errors = NULL;
190 static gchar **gst_library_errors = NULL;
191 static gchar **gst_resource_errors = NULL;
192 static gchar **gst_stream_errors = NULL;
194 gchar *message = NULL;
196 /* initialize error message tables if necessary */
197 if (gst_core_errors == NULL)
198 gst_core_errors = _gst_core_errors_init ();
199 if (gst_library_errors == NULL)
200 gst_library_errors = _gst_library_errors_init ();
201 if (gst_resource_errors == NULL)
202 gst_resource_errors = _gst_resource_errors_init ();
203 if (gst_stream_errors == NULL)
204 gst_stream_errors = _gst_stream_errors_init ();
207 if (domain == GST_CORE_ERROR)
208 message = gst_core_errors[code];
209 else if (domain == GST_LIBRARY_ERROR)
210 message = gst_library_errors[code];
211 else if (domain == GST_RESOURCE_ERROR)
212 message = gst_resource_errors[code];
213 else if (domain == GST_STREAM_ERROR)
214 message = gst_stream_errors[code];
216 g_warning ("No error messages for domain %s", g_quark_to_string (domain));
217 return g_strdup_printf (_("No error message for domain %s."),
218 g_quark_to_string (domain));
221 return g_strdup (_(message));
225 ("No standard error message for domain %s and code %d."),
226 g_quark_to_string (domain), code);