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