dvbbasebin: better error reporting

https://bugzilla.gnome.org/show_bug.cgi?id=678892
This commit is contained in:
Tim-Philipp Müller 2013-04-21 18:28:52 +01:00
parent fc2b55919d
commit bd504e379b
5 changed files with 44 additions and 26 deletions

View file

@ -920,6 +920,7 @@ dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
GError ** error)
{
DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (handler);
GError *err = NULL;
gchar *location;
location = gst_uri_get_location (uri);
@ -927,7 +928,7 @@ dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
if (location == NULL)
goto no_location;
if (!set_properties_for_channel (GST_ELEMENT (dvbbasebin), location))
if (!set_properties_for_channel (GST_ELEMENT (dvbbasebin), location, &err))
goto set_properties_failed;
/* FIXME: here is where we parse channels.conf */
@ -935,18 +936,24 @@ dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
g_free (location);
return TRUE;
/* ERRORS */
post_error_and_exit:
{
gst_element_message_full (GST_ELEMENT (dvbbasebin), GST_MESSAGE_ERROR,
err->domain, err->code, g_strdup (err->message), NULL, __FILE__,
GST_FUNCTION, __LINE__);
g_propagate_error (error, err);
return FALSE;
}
no_location:
{
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
g_set_error (&err, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
"No details to DVB URI");
return FALSE;
goto post_error_and_exit;
}
set_properties_failed:
{
g_set_error (error, GST_URI_ERROR, GST_URI_ERROR_BAD_URI,
"Could not set properties from DVB URI");
g_free (location);
return FALSE;
goto post_error_and_exit;
}
}

View file

@ -24,12 +24,21 @@
#include "config.h"
#endif
#include <gst/gst-i18n-plugin.h>
#include "gstdvbsrc.h"
#include "dvbbasebin.h"
static gboolean
plugin_init (GstPlugin * plugin)
{
#ifdef ENABLE_NLS
GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
LOCALEDIR);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
if (!gst_dvbsrc_plugin_init (plugin))
return FALSE;

View file

@ -913,13 +913,6 @@ gst_dvbsrc_plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gstdvbsrc_debug, "dvbsrc", 0, "DVB Source Element");
#ifdef ENABLE_NLS
GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
LOCALEDIR);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif /* ENABLE_NLS */
return gst_element_register (plugin, "dvbsrc", GST_RANK_NONE,
GST_TYPE_DVBSRC);
}

View file

@ -31,6 +31,8 @@
#include <string.h>
#include <gst/gst.h>
#include <gst/gst-i18n-plugin.h>
#include "parsechannels.h"
GST_DEBUG_CATEGORY_EXTERN (dvb_base_bin_debug);
@ -43,7 +45,8 @@ GST_DEBUG_CATEGORY_EXTERN (dvb_base_bin_debug);
/* this will do zap style channels.conf only for the moment */
static GHashTable *
parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
GError ** error)
{
gchar *contents;
gchar **lines;
@ -149,17 +152,21 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
open_fail:
{
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
("Opening channels configuration file '%s' failed : %s", filename,
err->message));
if (err->code == G_FILE_ERROR_NOENT) {
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND,
_("Couldn't find DVB channel configuration file"));
} else {
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ,
_("Couldn't load DVB channel configuration file: %s"), err->message);
}
g_clear_error (&err);
return NULL;
}
no_channels:
{
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
("Channels configuration file doesn't contain any channels"));
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
_("DVB channel configuration file doesn't contain any channels"));
g_hash_table_unref (res);
return NULL;
}
@ -182,7 +189,8 @@ destroy_channels_hash (GHashTable * channels)
}
gboolean
set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
set_properties_for_channel (GstElement * dvbbasebin,
const gchar * channel_name, GError ** error)
{
gboolean ret = FALSE;
GHashTable *channels, *params;
@ -195,7 +203,7 @@ set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
filename = g_build_filename (g_get_user_config_dir (),
"gstreamer-" GST_API_VERSION, "dvb-channels.conf", NULL);
}
channels = parse_channels_conf_from_file (dvbbasebin, filename);
channels = parse_channels_conf_from_file (dvbbasebin, filename, error);
g_free (filename);
if (!channels)
@ -424,9 +432,9 @@ beach:
unknown_channel:
{
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
("Couldn't find configuration properties for channel \"%s\"",
channel_name));
/* FIXME: is channel name guaranteed to be ASCII or UTF-8? */
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND,
_("Couldn't find details for DVB channel %s"), channel_name);
destroy_channels_hash (channels);
return FALSE;
}

View file

@ -24,7 +24,8 @@
#ifndef PARSE_CHANNELS_H
#define PARSE_CHANNELS_H
gboolean set_properties_for_channel(GstElement *dvbbasebin,
const gchar* channel_name);
gboolean set_properties_for_channel (GstElement * dvbbasebin,
const gchar * channel_name,
GError ** error);
#endif