message: accept NULL error argument in gst_message_parse_{error,warning,info}

And simplify code a bit while at it.

https://bugzilla.gnome.org/show_bug.cgi?id=693704
This commit is contained in:
Tim-Philipp Müller 2013-02-13 16:52:13 +00:00
parent fb3b53328f
commit 5fc34add25
2 changed files with 40 additions and 57 deletions

View file

@ -1314,28 +1314,12 @@ gst_message_parse_structure_change (GstMessage * message,
void void
gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug) gst_message_parse_error (GstMessage * message, GError ** gerror, gchar ** debug)
{ {
const GValue *error_gvalue;
GError *error_val;
GstStructure *structure;
g_return_if_fail (GST_IS_MESSAGE (message)); g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR); g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_ERROR);
structure = GST_MESSAGE_STRUCTURE (message); gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR)); GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
g_return_if_fail (error_gvalue != NULL); GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
error_val = (GError *) g_value_get_boxed (error_gvalue);
if (error_val)
*gerror = g_error_copy (error_val);
else
*gerror = NULL;
if (debug)
*debug =
g_value_dup_string (gst_structure_id_get_value (structure,
GST_QUARK (DEBUG)));
} }
/** /**
@ -1354,28 +1338,12 @@ void
gst_message_parse_warning (GstMessage * message, GError ** gerror, gst_message_parse_warning (GstMessage * message, GError ** gerror,
gchar ** debug) gchar ** debug)
{ {
const GValue *error_gvalue;
GError *error_val;
GstStructure *structure;
g_return_if_fail (GST_IS_MESSAGE (message)); g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING); g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_WARNING);
structure = GST_MESSAGE_STRUCTURE (message); gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR)); GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
g_return_if_fail (error_gvalue != NULL); GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
error_val = (GError *) g_value_get_boxed (error_gvalue);
if (error_val)
*gerror = g_error_copy (error_val);
else
*gerror = NULL;
if (debug)
*debug =
g_value_dup_string (gst_structure_id_get_value (structure,
GST_QUARK (DEBUG)));
} }
/** /**
@ -1393,28 +1361,12 @@ gst_message_parse_warning (GstMessage * message, GError ** gerror,
void void
gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug) gst_message_parse_info (GstMessage * message, GError ** gerror, gchar ** debug)
{ {
const GValue *error_gvalue;
GError *error_val;
GstStructure *structure;
g_return_if_fail (GST_IS_MESSAGE (message)); g_return_if_fail (GST_IS_MESSAGE (message));
g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO); g_return_if_fail (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
structure = GST_MESSAGE_STRUCTURE (message); gst_structure_id_get (GST_MESSAGE_STRUCTURE (message),
error_gvalue = gst_structure_id_get_value (structure, GST_QUARK (GERROR)); GST_QUARK (GERROR), G_TYPE_ERROR, gerror,
g_return_if_fail (error_gvalue != NULL); GST_QUARK (DEBUG), G_TYPE_STRING, debug, NULL);
g_return_if_fail (G_VALUE_TYPE (error_gvalue) == G_TYPE_ERROR);
error_val = (GError *) g_value_get_boxed (error_gvalue);
if (error_val)
*gerror = g_error_copy (error_val);
else
*gerror = NULL;
if (debug)
*debug =
g_value_dup_string (gst_structure_id_get_value (structure,
GST_QUARK (DEBUG)));
} }
/** /**

View file

@ -54,6 +54,8 @@ GST_START_TEST (test_parsing)
error = NULL; error = NULL;
debug = NULL; debug = NULL;
gst_message_parse_error (message, NULL, NULL);
gst_message_parse_error (message, &error, &debug); gst_message_parse_error (message, &error, &debug);
fail_if (error == NULL); fail_if (error == NULL);
fail_if (debug == NULL); fail_if (debug == NULL);
@ -82,6 +84,8 @@ GST_START_TEST (test_parsing)
warning = NULL; warning = NULL;
debug = NULL; debug = NULL;
gst_message_parse_warning (message, NULL, NULL);
gst_message_parse_warning (message, &warning, &debug); gst_message_parse_warning (message, &warning, &debug);
fail_if (warning == NULL); fail_if (warning == NULL);
fail_if (debug == NULL); fail_if (debug == NULL);
@ -96,6 +100,33 @@ GST_START_TEST (test_parsing)
} }
/* GST_MESSAGE_INFO */ /* GST_MESSAGE_INFO */
{ {
GError *info = NULL;
gchar *debug;
info = g_error_new (domain, 10, "test info");
fail_if (info == NULL);
message = gst_message_new_info (NULL, info, "info string");
fail_if (message == NULL);
fail_unless (GST_MESSAGE_TYPE (message) == GST_MESSAGE_INFO);
fail_unless (GST_MESSAGE_SRC (message) == NULL);
g_error_free (info);
info = NULL;
debug = NULL;
gst_message_parse_info (message, NULL, NULL);
gst_message_parse_info (message, &info, &debug);
fail_if (info == NULL);
fail_if (debug == NULL);
fail_unless (strcmp (info->message, "test info") == 0);
fail_unless (info->domain == domain);
fail_unless (info->code == 10);
fail_unless (strcmp (debug, "info string") == 0);
gst_message_unref (message);
g_error_free (info);
g_free (debug);
} }
/* GST_MESSAGE_TAG */ /* GST_MESSAGE_TAG */
{ {