Removed plugable schedulers.
[platform/upstream/gstreamer.git] / gst / gsterror.c
1 /* GStreamer
2  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gst_private.h"
25 #include <gst/gst.h>
26 #include "gst-i18n-lib.h"
27
28 #define TABLE(t, d, a, b) t[GST_ ## d ## _ERROR_ ## a] = g_strdup (b)
29 #define QUARK_FUNC(string)                                              \
30 GQuark gst_ ## string ## _error_quark (void) {                          \
31   static GQuark quark;                                                  \
32   if (!quark)                                                           \
33     quark = g_quark_from_static_string ("gst-" # string "-error-quark"); \
34   return quark; }
35
36 GType
37 gst_g_error_get_type (void)
38 {
39   static GType type = 0;
40
41   if (!type)
42     type = g_boxed_type_register_static ("GstGError",
43         (GBoxedCopyFunc) g_error_copy, (GBoxedFreeFunc) g_error_free);
44   return type;
45 }
46
47 /* initialize the dynamic table of translated core errors */
48 static gchar **
49 _gst_core_errors_init (void)
50 {
51   gchar **t = NULL;
52
53   t = g_new0 (gchar *, GST_CORE_ERROR_NUM_ERRORS);
54
55   TABLE (t, CORE, FAILED,
56       N_("GStreamer encountered a general core library error."));
57   TABLE (t, CORE, TOO_LAZY,
58       N_("GStreamer developers were too lazy to assign an error code "
59           "to this error.  Please file a bug."));
60   TABLE (t, CORE, NOT_IMPLEMENTED,
61       N_
62       ("Internal GStreamer error: code not implemented.  Please file a bug."));
63   TABLE (t, CORE, STATE_CHANGE,
64       N_("Internal GStreamer error: state change failed.  Please file a bug."));
65   TABLE (t, CORE, PAD,
66       N_("Internal GStreamer error: pad problem.  Please file a bug."));
67   TABLE (t, CORE, THREAD,
68       N_("Internal GStreamer error: thread problem.  Please file a bug."));
69   TABLE (t, CORE, NEGOTIATION,
70       N_("Internal GStreamer error: negotiation problem.  Please file a bug."));
71   TABLE (t, CORE, EVENT,
72       N_("Internal GStreamer error: event problem.  Please file a bug."));
73   TABLE (t, CORE, SEEK,
74       N_("Internal GStreamer error: seek problem.  Please file a bug."));
75   TABLE (t, CORE, CAPS,
76       N_("Internal GStreamer error: caps problem.  Please file a bug."));
77   TABLE (t, CORE, TAG,
78       N_("Internal GStreamer error: tag problem.  Please file a bug."));
79
80   return t;
81 }
82
83 /* initialize the dynamic table of translated library errors */
84 static gchar **
85 _gst_library_errors_init (void)
86 {
87   gchar **t = NULL;
88
89   t = g_new0 (gchar *, GST_LIBRARY_ERROR_NUM_ERRORS);
90
91   TABLE (t, LIBRARY, FAILED,
92       N_("GStreamer encountered a general supporting library error."));
93   TABLE (t, LIBRARY, TOO_LAZY,
94       N_("GStreamer developers were too lazy to assign an error code "
95           "to this error.  Please file a bug."));
96   TABLE (t, LIBRARY, INIT, N_("Could not initialize supporting library."));
97   TABLE (t, LIBRARY, SHUTDOWN, N_("Could not close supporting library."));
98   TABLE (t, LIBRARY, SETTINGS, N_("Could not close supporting library."));
99
100   return t;
101 }
102
103 /* initialize the dynamic table of translated resource errors */
104 static gchar **
105 _gst_resource_errors_init (void)
106 {
107   gchar **t = NULL;
108
109   t = g_new0 (gchar *, GST_RESOURCE_ERROR_NUM_ERRORS);
110
111   TABLE (t, RESOURCE, FAILED,
112       N_("GStreamer encountered a general resource error."));
113   TABLE (t, RESOURCE, TOO_LAZY,
114       N_("GStreamer developers were too lazy to assign an error code "
115           "to this error.  Please file a bug."));
116   TABLE (t, RESOURCE, NOT_FOUND, N_("Resource not found."));
117   TABLE (t, RESOURCE, BUSY, N_("Resource busy or not available."));
118   TABLE (t, RESOURCE, OPEN_READ, N_("Could not open resource for reading."));
119   TABLE (t, RESOURCE, OPEN_WRITE, N_("Could not open resource for writing."));
120   TABLE (t, RESOURCE, OPEN_READ_WRITE,
121       N_("Could not open resource for reading and writing."));
122   TABLE (t, RESOURCE, CLOSE, N_("Could not close resource."));
123   TABLE (t, RESOURCE, READ, N_("Could not read from resource."));
124   TABLE (t, RESOURCE, WRITE, N_("Could not write to resource."));
125   TABLE (t, RESOURCE, SEEK, N_("Could not perform seek on resource."));
126   TABLE (t, RESOURCE, SYNC, N_("Could not synchronize on resource."));
127   TABLE (t, RESOURCE, SETTINGS,
128       N_("Could not get/set settings from/on resource."));
129
130   return t;
131 }
132
133 /* initialize the dynamic table of translated stream errors */
134 static gchar **
135 _gst_stream_errors_init (void)
136 {
137   gchar **t = NULL;
138
139   t = g_new0 (gchar *, GST_STREAM_ERROR_NUM_ERRORS);
140
141   TABLE (t, STREAM, FAILED,
142       N_("GStreamer encountered a general stream error."));
143   TABLE (t, STREAM, TOO_LAZY,
144       N_("GStreamer developers were too lazy to assign an error code "
145           "to this error.  Please file a bug."));
146   TABLE (t, STREAM, NOT_IMPLEMENTED,
147       N_("Element doesn't implement handling of this stream. "
148           "Please file a bug."));
149   TABLE (t, STREAM, TYPE_NOT_FOUND, N_("Could not determine type of stream."));
150   TABLE (t, STREAM, WRONG_TYPE,
151       N_("The stream is of a different type than handled by this element."));
152   TABLE (t, STREAM, CODEC_NOT_FOUND,
153       N_("There is no codec present that can handle the stream's type."));
154   TABLE (t, STREAM, DECODE, N_("Could not decode stream."));
155   TABLE (t, STREAM, ENCODE, N_("Could not encode stream."));
156   TABLE (t, STREAM, DEMUX, N_("Could not demultiplex stream."));
157   TABLE (t, STREAM, MUX, N_("Could not multiplex stream."));
158   TABLE (t, STREAM, FORMAT, N_("Stream is of the wrong format."));
159
160   return t;
161 }
162
163 QUARK_FUNC (core)
164     QUARK_FUNC (library)
165     QUARK_FUNC (resource)
166     QUARK_FUNC (stream)
167
168 /**
169  * gst_error_get_message:
170  * @domain: the GStreamer error domain this error belongs to.
171  * @code: the error code belonging to the domain.
172  *
173  * Returns: a newly allocated string describing the error message in the
174  * current locale.
175  */
176      gchar *gst_error_get_message (GQuark domain, gint code)
177 {
178   static gchar **gst_core_errors = NULL;
179   static gchar **gst_library_errors = NULL;
180   static gchar **gst_resource_errors = NULL;
181   static gchar **gst_stream_errors = NULL;
182
183   gchar *message = NULL;
184
185   /* initialize error message tables if necessary */
186   if (gst_core_errors == NULL)
187     gst_core_errors = _gst_core_errors_init ();
188   if (gst_library_errors == NULL)
189     gst_library_errors = _gst_library_errors_init ();
190   if (gst_resource_errors == NULL)
191     gst_resource_errors = _gst_resource_errors_init ();
192   if (gst_stream_errors == NULL)
193     gst_stream_errors = _gst_stream_errors_init ();
194
195
196   if (domain == GST_CORE_ERROR)
197     message = gst_core_errors[code];
198   else if (domain == GST_LIBRARY_ERROR)
199     message = gst_library_errors[code];
200   else if (domain == GST_RESOURCE_ERROR)
201     message = gst_resource_errors[code];
202   else if (domain == GST_STREAM_ERROR)
203     message = gst_stream_errors[code];
204   else {
205     g_warning ("No error messages for domain %s", g_quark_to_string (domain));
206     return g_strdup_printf (_("No error message for domain %s."),
207         g_quark_to_string (domain));
208   }
209   if (message)
210     return g_strdup (_(message));
211   else
212     return
213         g_strdup_printf (_
214         ("No standard error message for domain %s and code %d."),
215         g_quark_to_string (domain), code);
216 }