changing error signal add error codes and domains

Original commit message from CVS:
changing error signal
add error codes and domains
parent 3aaa423f
2004-01-18 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/Makefile.am:
* gst/autoplug/gstspideridentity.c:
(gst_spider_identity_sink_loop_type_finding):
* gst/elements/gstfakesink.c: (gst_fakesink_change_state):
* gst/elements/gstfilesink.c: (gst_filesink_open_file),
(gst_filesink_close_file), (gst_filesink_handle_event),
(gst_filesink_chain):
* gst/elements/gstfilesrc.c: (gst_filesrc_set_property),
(gst_filesrc_map_region), (gst_filesrc_get_read),
(gst_filesrc_open_file):
* gst/elements/gstidentity.c: (gst_identity_chain):
* gst/elements/gstmultidisksrc.c: (gst_multidisksrc_open_file):
* gst/elements/gstpipefilter.c: (gst_pipefilter_get),
(gst_pipefilter_chain), (gst_pipefilter_open_file):
* gst/elements/gsttypefindelement.c: (gst_type_find_element_chain):
* gst/gst.h:
* gst/gst_private.h:
* gst/gstelement.c: (gst_element_class_init),
(gst_element_default_error), (gst_element_error_func),
(gst_element_error_extended):
* gst/gstelement.h:
* gst/gsterror.c: (_gst_core_errors_init),
(_gst_library_errors_init), (_gst_resource_errors_init),
(_gst_stream_errors_init), (gst_error_get_message):
* gst/gsterror.h:
* gst/gstinfo.c: (_gst_debug_init):
* gst/gstmarshal.list:
* gst/gstpad.c: (gst_pad_set_explicit_caps),
(gst_pad_recover_caps_error), (gst_pad_pull):
* gst/gstqueue.c: (gst_queue_chain), (gst_queue_get):
* gst/schedulers/gstbasicscheduler.c:
(gst_basic_scheduler_chainhandler_proxy),
(gst_basic_scheduler_gethandler_proxy),
(gst_basic_scheduler_cothreaded_chain):
* po/POTFILES.in:
* po/fr.po:
* po/nl.po:
change error signal
add error categories
2004-01-18 Jeremy Simon <jesimon@libertysurf.fr>
* gst/gsttag.c: (_gst_tag_initialize):
......
......@@ -86,6 +86,7 @@ libgstreamer_@GST_MAJORMINOR@_la_SOURCES = \
gstdata.c \
gstelement.c \
gstelementfactory.c \
gsterror.c \
gstevent.c \
gstfilter.c \
gstformat.c \
......@@ -147,6 +148,7 @@ gst_headers = \
gstcpu.h \
gstdata.h \
gstelement.h \
gsterror.h \
gstevent.h \
gstfilter.h \
gstformat.h \
......
......@@ -501,7 +501,7 @@ gst_spider_identity_sink_loop_type_finding (GstSpiderIdentity *ident)
}
if (find.best_probability > 0)
goto plug;
gst_element_error(GST_ELEMENT(ident), "Could not find media type", NULL);
gst_element_error (ident, STREAM, TYPE_NOT_FOUND, NULL, NULL);
find.buffer = GST_BUFFER (gst_event_new (GST_EVENT_EOS));
end:
......
......@@ -391,7 +391,8 @@ gst_fakesink_change_state (GstElement *element)
return GST_STATE_SUCCESS;
error:
gst_element_error (element, "failed state change as requested");
gst_element_error (element, CORE, STATE_CHANGE,
NULL, NULL);
return GST_STATE_FAILURE;
}
......@@ -25,6 +25,8 @@
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include <gst/gst.h>
#include <errno.h>
#include "gstfilesink.h"
......@@ -33,6 +35,7 @@
#include <sys/types.h>
#include <unistd.h>
GST_DEBUG_CATEGORY_STATIC (gst_filesink_debug);
#define GST_CAT_DEFAULT gst_filesink_debug
......@@ -230,18 +233,18 @@ gst_filesink_open_file (GstFileSink *sink)
/* open the file */
if (!sink->filename)
{
gst_element_error (GST_ELEMENT (sink),
"Error opening file: no file given");
gst_element_error (sink, RESOURCE, NOT_FOUND,
(_("No filename specified")), NULL);
return FALSE;
}
sink->file = fopen (sink->filename, "w");
if (sink->file == NULL) {
gst_element_error (GST_ELEMENT (sink),
"Error opening file %s: %s",
sink->filename, g_strerror(errno));
gst_element_error (sink, RESOURCE, OPEN_WRITE,
(_("Could not open file \"%s\" for writing"), sink->filename),
("system error: %s", strerror (errno)));
return FALSE;
}
}
GST_FLAG_SET (sink, GST_FILESINK_OPEN);
......@@ -257,9 +260,9 @@ gst_filesink_close_file (GstFileSink *sink)
if (fclose (sink->file) != 0)
{
gst_element_error (GST_ELEMENT (sink),
"Error closing file %s: %s",
sink->filename, g_strerror(errno));
gst_element_error (sink, RESOURCE, CLOSE,
(_("Error closing file \"%s\""), sink->filename),
GST_ERROR_SYSTEM);
}
else {
GST_FLAG_UNSET (sink, GST_FILESINK_OPEN);
......@@ -324,9 +327,9 @@ gst_filesink_handle_event (GstPad *pad, GstEvent *event)
if (GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH)
if (fflush (filesink->file))
gst_element_error (GST_ELEMENT (filesink),
"Error flushing file %s: %s",
filesink->filename, g_strerror(errno));
gst_element_error (filesink, RESOURCE, WRITE,
(_("Error while writing to file \"%s\""), filesink->filename),
GST_ERROR_SYSTEM);
switch (GST_EVENT_SEEK_METHOD(event))
{
......@@ -356,9 +359,9 @@ gst_filesink_handle_event (GstPad *pad, GstEvent *event)
}
case GST_EVENT_FLUSH:
if (fflush (filesink->file)) {
gst_element_error (GST_ELEMENT (filesink),
"Error flushing file %s: %s",
filesink->filename, g_strerror(errno));
gst_element_error (filesink, RESOURCE, WRITE,
(_("Error while writing to file \"%s\""), filesink->filename),
GST_ERROR_SYSTEM);
}
break;
case GST_EVENT_EOS:
......@@ -408,10 +411,11 @@ gst_filesink_chain (GstPad *pad, GstData *_data)
GST_BUFFER_SIZE (buf) - bytes_written,
filesink->file);
if (wrote <= 0) {
gst_element_error (GST_ELEMENT (filesink),
"Only %d of %d bytes written: %s",
bytes_written, GST_BUFFER_SIZE (buf),
strerror (errno));
gst_element_error (filesink, RESOURCE, WRITE,
(_("Error while writing to file \"%s\""), filesink->filename),
("Only %d of %d bytes written: %s",
bytes_written, GST_BUFFER_SIZE (buf),
strerror (errno)));
break;
}
bytes_written += wrote;
......
......@@ -35,6 +35,8 @@
#include <errno.h>
#include <string.h>
#include "../gst-i18n-lib.h"
/**********************************************************************
* GStreamer Default File Source
......@@ -297,7 +299,7 @@ gst_filesrc_set_property (GObject *object, guint prop_id, const GValue *value, G
src->mapsize = g_value_get_ulong (value);
g_object_notify (G_OBJECT (src), "mmapsize");
} else {
GST_INFO_OBJECT (src, "invalid mapsize, must a multiple of pagesize, which is %d",
GST_INFO_OBJECT (src, "invalid mapsize, must be a multiple of pagesize, which is %d",
src->pagesize);
}
break;
......@@ -391,7 +393,9 @@ gst_filesrc_map_region (GstFileSrc *src, off_t offset, size_t size)
mmapregion = mmap (NULL, size, PROT_READ, MAP_SHARED, src->fd, offset);
if (mmapregion == NULL) {
gst_element_error (GST_ELEMENT (src), "couldn't map file");
gst_element_error (src, RESOURCE, TOO_LAZY,
NULL,
("mmap call failed"));
return NULL;
}
else if (mmapregion == MAP_FAILED) {
......@@ -636,12 +640,15 @@ gst_filesrc_get_read (GstFileSrc *src)
ret = read (src->fd, GST_BUFFER_DATA (buf), readsize);
if (ret < 0){
gst_element_error (GST_ELEMENT (src), "reading file (%s)",
strerror (errno), NULL);
gst_element_error (src, RESOURCE, READ,
NULL,
("system error: %s", strerror (errno)));
return NULL;
}
if (ret < readsize) {
gst_element_error (GST_ELEMENT (src), "unexpected end of file", NULL);
gst_element_error (src, RESOURCE, READ,
NULL,
("unexpected end of file"));
return NULL;
}
......@@ -711,18 +718,47 @@ gst_filesrc_check_filesize (GstFileSrc *src)
return TRUE;
}
/* open the file and mmap it, necessary to go to READY state */
static gboolean
static gboolean
gst_filesrc_open_file (GstFileSrc *src)
{
g_return_val_if_fail (!GST_FLAG_IS_SET (src ,GST_FILESRC_OPEN), FALSE);
if (src->filename == NULL)
{
gst_element_error (src, RESOURCE, NOT_FOUND,
(_("No filename specified")),
NULL);
return FALSE;
}
if (src->filename == NULL)
{
gst_element_error (src, RESOURCE, NOT_FOUND,
(_("No file specified for reading")),
NULL);
return FALSE;
}
GST_INFO_OBJECT (src, "opening file %s",src->filename);
/* open the file */
src->fd = open (src->filename, O_RDONLY);
if (src->fd < 0) {
gst_element_error (GST_ELEMENT (src), "opening file \"%s\" (%s)",
src->filename, strerror (errno), NULL);
if (src->fd < 0)
{
if (errno == ENOENT)
gst_element_error (src, RESOURCE, NOT_FOUND,
NULL,
NULL);
/* thomas
gst_element_error (src, RESOURCE, NOT_FOUND,
(_("File \"%s\" does not exist"), src->filename),
NULL);
*/
else
gst_element_error (src, RESOURCE, OPEN_READ,
(_("Could not open file \"%s\" for reading"), src->filename),
GST_ERROR_SYSTEM);
return FALSE;
} else {
/* check if it is a regular file, otherwise bail out */
......@@ -731,8 +767,9 @@ gst_filesrc_open_file (GstFileSrc *src)
fstat(src->fd, &stat_results);
if (!S_ISREG(stat_results.st_mode)) {
gst_element_error (GST_ELEMENT (src), "opening file \"%s\" failed. it isn't a regular file",
src->filename, NULL);
gst_element_error (src, RESOURCE, OPEN_READ,
(_("File \"%s\" isn't a regular file"), src->filename),
NULL);
close(src->fd);
return FALSE;
}
......
......@@ -27,6 +27,7 @@
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include "gstidentity.h"
GST_DEBUG_CATEGORY_STATIC (gst_identity_debug);
......@@ -165,7 +166,9 @@ gst_identity_chain (GstPad *pad, GstData *_data)
identity->error_after--;
if (identity->error_after == 0) {
gst_buffer_unref (buf);
gst_element_error (GST_ELEMENT (identity), "errored after iterations as requested");
gst_element_error (identity, CORE, FAILED,
(_("Failed after iterations as requested")),
NULL);
return;
}
}
......
......@@ -26,11 +26,15 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include "gstmultidisksrc.h"
GST_DEBUG_CATEGORY_STATIC (gst_multidisksrc_debug);
......@@ -236,9 +240,11 @@ gboolean gst_multidisksrc_open_file (GstMultiDiskSrc *src, GstPad *srcpad)
src->fd = open ((const char *) src->currentfilename, O_RDONLY);
if (src->fd < 0) {
perror ("open");
gst_element_error (GST_ELEMENT (src), g_strconcat("opening file \"", src->currentfilename, "\"", NULL));
gst_element_error (src, RESOURCE, OPEN_READ,
(_("Could not open file \"%s\" for reading"), src->currentfilename),
("system error: %s", strerror (errno)));
return FALSE;
} else {
/* find the file length */
src->size = lseek (src->fd, 0, SEEK_END);
......@@ -249,7 +255,9 @@ gboolean gst_multidisksrc_open_file (GstMultiDiskSrc *src, GstPad *srcpad)
/* collapse state if that failed */
if (src->map == NULL) {
close (src->fd);
gst_element_error (GST_ELEMENT (src),"mmapping file");
gst_element_error (src, RESOURCE, TOO_LAZY,
NULL,
("mmap call failed"));
return FALSE;
}
GST_FLAG_SET (src, GST_MULTIDISKSRC_OPEN);
......
......@@ -26,11 +26,15 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include "gstmultidisksrc.h"
GST_DEBUG_CATEGORY_STATIC (gst_multidisksrc_debug);
......@@ -236,9 +240,11 @@ gboolean gst_multidisksrc_open_file (GstMultiDiskSrc *src, GstPad *srcpad)
src->fd = open ((const char *) src->currentfilename, O_RDONLY);
if (src->fd < 0) {
perror ("open");
gst_element_error (GST_ELEMENT (src), g_strconcat("opening file \"", src->currentfilename, "\"", NULL));
gst_element_error (src, RESOURCE, OPEN_READ,
(_("Could not open file \"%s\" for reading"), src->currentfilename),
("system error: %s", strerror (errno)));
return FALSE;
} else {
/* find the file length */
src->size = lseek (src->fd, 0, SEEK_END);
......@@ -249,7 +255,9 @@ gboolean gst_multidisksrc_open_file (GstMultiDiskSrc *src, GstPad *srcpad)
/* collapse state if that failed */
if (src->map == NULL) {
close (src->fd);
gst_element_error (GST_ELEMENT (src),"mmapping file");
gst_element_error (src, RESOURCE, TOO_LAZY,
NULL,
("mmap call failed"));
return FALSE;
}
GST_FLAG_SET (src, GST_MULTIDISKSRC_OPEN);
......
......@@ -2,7 +2,7 @@
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
*
* gstpipefilter.c:
* gstpipefilter.c:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -26,6 +26,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
......@@ -33,6 +34,7 @@
# include "config.h"
#endif
#include "../gst-i18n-lib.h"
#include "gstpipefilter.h"
GST_DEBUG_CATEGORY_STATIC (gst_pipefilter_debug);
......@@ -167,8 +169,8 @@ gst_pipefilter_get (GstPad *pad)
readbytes = read(pipefilter->fdout[0], GST_BUFFER_DATA(newbuf), pipefilter->bytes_per_read);
GST_DEBUG ("read %ld bytes", readbytes);
if (readbytes < 0) {
perror("read");
gst_element_error(GST_ELEMENT(pipefilter),"reading");
gst_element_error (pipefilter, RESOURCE, READ,
NULL, ("system error: %s", strerror (errno)));
return NULL;
}
/* if we didn't get as many bytes as we asked for, we're at EOF */
......@@ -211,8 +213,8 @@ gst_pipefilter_chain (GstPad *pad,GstData *_data)
writebytes = write(pipefilter->fdin[1],data,size);
GST_DEBUG ("written %ld bytes", writebytes);
if (writebytes < 0) {
perror("write");
gst_element_error(GST_ELEMENT(pipefilter),"writing");
gst_element_error (pipefilter, RESOURCE, WRITE,
NULL, ("system error: %s", strerror (errno)));
return;
}
gst_buffer_unref(buf);
......@@ -267,8 +269,8 @@ gst_pipefilter_open_file (GstPipefilter *src)
if((src->childpid = fork()) == -1)
{
perror("fork");
gst_element_error(GST_ELEMENT(src),"forking");
gst_element_error (src, RESOURCE, TOO_LAZY,
NULL, ("system error: %s", strerror (errno)));
return FALSE;
}
......@@ -280,9 +282,9 @@ gst_pipefilter_open_file (GstPipefilter *src)
dup2(src->fdin[0], STDIN_FILENO); /* set the childs input stream */
dup2(src->fdout[1], STDOUT_FILENO); /* set the childs output stream */
execvp(src->command[0], &src->command[0]);
/* will only reach if error */
perror("exec");
gst_element_error(GST_ELEMENT(src),"starting child process");
/* will only be reached if execvp has an error */
gst_element_error (src, RESOURCE, TOO_LAZY,
NULL, ("system error: %s", strerror (errno)));
return FALSE;
}
......
......@@ -44,6 +44,7 @@
#include <gst/gsttypefind.h>
#include <gst/gstutils.h>
#include <gst/gsterror.h>
GST_DEBUG_CATEGORY_STATIC (gst_type_find_element_debug);
#define GST_CAT_DEFAULT gst_type_find_element_debug
......@@ -556,7 +557,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
if (typefind->caps) {
stop_typefinding (typefind);
} else if (typefind->possibilities == NULL) {
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
gst_element_error (typefind, STREAM, TYPE_NOT_FOUND,
NULL, NULL);
} else {
/* set up typefind element for next iteration */
typefind->possibilities = g_list_sort (typefind->possibilities, compare_type_find_entry);
......
......@@ -44,6 +44,7 @@
#include <gst/gsttypefind.h>
#include <gst/gstutils.h>
#include <gst/gsterror.h>
GST_DEBUG_CATEGORY_STATIC (gst_type_find_element_debug);
#define GST_CAT_DEFAULT gst_type_find_element_debug
......@@ -556,7 +557,8 @@ gst_type_find_element_chain (GstPad *pad, GstData *data)
if (typefind->caps) {
stop_typefinding (typefind);
} else if (typefind->possibilities == NULL) {
gst_element_error (GST_ELEMENT (typefind), "media type could not be detected");
gst_element_error (typefind, STREAM, TYPE_NOT_FOUND,
NULL, NULL);
} else {
/* set up typefind element for next iteration */
typefind->possibilities = g_list_sort (typefind->possibilities, compare_type_find_entry);
......
......@@ -37,6 +37,7 @@
#include <gst/gstclock.h>
#include <gst/gstcpu.h>
#include <gst/gstelement.h>
#include <gst/gsterror.h>
#include <gst/gstevent.h>
#include <gst/gstindex.h>
#include <gst/gstinfo.h>
......
......@@ -60,6 +60,7 @@ extern GstDebugCategory *GST_CAT_THREAD;
extern GstDebugCategory *GST_CAT_XML;
extern GstDebugCategory *GST_CAT_NEGOTIATION;
extern GstDebugCategory *GST_CAT_REFCOUNTING;
extern GstDebugCategory *GST_CAT_ERROR_SYSTEM;
extern GstDebugCategory *GST_CAT_EVENT;
extern GstDebugCategory *GST_CAT_PARAMS;
extern GstDebugCategory *GST_CAT_CALL_TRACE;
......
......@@ -27,10 +27,12 @@
#include "gstelement.h"
#include "gstbin.h"
#include "gsterror.h"
#include "gstscheduler.h"
#include "gstevent.h"
#include "gstutils.h"
#include "gstinfo.h"
#include "gst-i18n-lib.h"
/* Element signals and args */
enum {
......@@ -66,7 +68,7 @@ static void gst_element_real_get_property (GObject *object, guint prop_id, GVa
static void gst_element_dispose (GObject *object);
static GstElementStateReturn gst_element_change_state (GstElement *element);
static void gst_element_error_func (GstElement* element, GstElement *source, gchar *errormsg);
static void gst_element_error_func (GstElement* element, GstElement *source, GError *error, gchar *debug);
static void gst_element_found_tag_func (GstElement* element, GstElement *source, GstTagList *tag_list);
#ifndef GST_DISABLE_LOADSAVE
......@@ -129,9 +131,9 @@ gst_element_class_init (GstElementClass *klass)
gst_element_signals[ERROR] =
g_signal_new ("error", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, error), NULL, NULL,
gst_marshal_VOID__OBJECT_STRING, G_TYPE_NONE, 2,
GST_TYPE_ELEMENT, G_TYPE_STRING);
gst_element_signals[EOS] =
gst_marshal_VOID__OBJECT_POINTER_STRING, G_TYPE_NONE, 3,
GST_TYPE_ELEMENT, G_TYPE_POINTER, G_TYPE_STRING);
gst_element_signals[EOS] =
g_signal_new ("eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, eos), NULL, NULL,
gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
......@@ -152,7 +154,7 @@ gst_element_class_init (GstElementClass *klass)
#endif
klass->change_state = GST_DEBUG_FUNCPTR (gst_element_change_state);
klass->error = GST_DEBUG_FUNCPTR (gst_element_error_func);
klass->error = GST_DEBUG_FUNCPTR (gst_element_error_func);
klass->found_tag = GST_DEBUG_FUNCPTR (gst_element_found_tag_func);
klass->numpadtemplates = 0;
......@@ -221,21 +223,25 @@ gst_element_real_get_property (GObject *object, guint prop_id, GValue *value, GP
* gst_element_default_error:
* @object: a #GObject that signalled the error.
* @orig: the #GstObject that initiated the error.
* @error: the error message.
* @error: the GError.
* @debug: an additional debug information string, or NULL.
*
* Adds a default error signal callback to an
* element. The user data passed to the g_signal_connect is
* ignored.
* The default handler will simply print the error string
* using g_print.
* A default error signal callback to attach to an element.
* The user data passed to the g_signal_connect is ignored.
*
* The default handler will simply print the error string using g_print.
*/
void
gst_element_default_error (GObject *object, GstObject *orig, gchar *error)
{
gchar *name = gst_object_get_path_string (orig);
g_print ("ERROR: %s: %s\n", name, error);
gst_element_default_error (GObject *object, GstObject *source, GError *error, gchar *debug)
{
gchar *name = gst_object_get_path_string (source);
g_print (_("ERROR: from element %s: %s.\n"), name, error->message);
if (debug)
g_print (_("Additional debug info:\n%s\n"), debug);
g_free (name);
}
}
typedef struct {
const GParamSpec *pspec;
......@@ -2056,19 +2062,22 @@ gst_element_unlink (GstElement *src, GstElement *dest)
}
static void
gst_element_error_func (GstElement* element, GstElement *source,
gchar *errormsg)
gst_element_error_func (GstElement* element, GstElement *source,
GError *error, gchar *debug)
{
/* tell the parent */
if (GST_OBJECT_PARENT (element)) {
GST_CAT_DEBUG (GST_CAT_EVENT, "forwarding error \"%s\" from %s to %s",
errormsg, GST_ELEMENT_NAME (element),
GST_OBJECT_NAME (GST_OBJECT_PARENT (element)));
GST_CAT_DEBUG (GST_CAT_ERROR_SYSTEM, "forwarding error \"%s\" from %s to %s",
error->message, GST_ELEMENT_NAME (element),
GST_OBJECT_NAME (GST_OBJECT_PARENT (element)));
gst_object_ref (GST_OBJECT (element));
g_signal_emit (G_OBJECT (GST_OBJECT_PARENT (element)),
gst_element_signals[ERROR], 0, source, errormsg);
g_signal_emit (G_OBJECT (GST_OBJECT_PARENT (element)),
gst_element_signals[ERROR], 0, source, error, debug);
gst_object_unref (GST_OBJECT (element));