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