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) GError ** error)
{ {
DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (handler); DvbBaseBin *dvbbasebin = GST_DVB_BASE_BIN (handler);
GError *err = NULL;
gchar *location; gchar *location;
location = gst_uri_get_location (uri); location = gst_uri_get_location (uri);
@ -927,7 +928,7 @@ dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
if (location == NULL) if (location == NULL)
goto no_location; 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; goto set_properties_failed;
/* FIXME: here is where we parse channels.conf */ /* 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); g_free (location);
return TRUE; return TRUE;
/* ERRORS */ /* 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: 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"); "No details to DVB URI");
return FALSE; goto post_error_and_exit;
} }
set_properties_failed: 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); g_free (location);
return FALSE; goto post_error_and_exit;
} }
} }

View file

@ -24,12 +24,21 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/gst-i18n-plugin.h>
#include "gstdvbsrc.h" #include "gstdvbsrc.h"
#include "dvbbasebin.h" #include "dvbbasebin.h"
static gboolean static gboolean
plugin_init (GstPlugin * plugin) 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)) if (!gst_dvbsrc_plugin_init (plugin))
return FALSE; 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"); 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, return gst_element_register (plugin, "dvbsrc", GST_RANK_NONE,
GST_TYPE_DVBSRC); GST_TYPE_DVBSRC);
} }

View file

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

View file

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