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