From b0a02001fa57cbb6d2bc57010690ceafcad35695 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 19 Jan 2004 11:32:35 +0000 Subject: [PATCH] adding a helper printf function for gst_element_error Original commit message from CVS: adding a helper printf function for gst_element_error --- ChangeLog | 7 +++++++ gst/gstelement.c | 34 ++++++++++++++++++++++++++++++++-- gst/gstelement.h | 5 +++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 75d7318..1289800 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2004-01-19 Thomas Vander Stichele + * gst/gstelement.c: (gst_element_error_printf), + (gst_element_error_extended): + * gst/gstelement.h: + add a helper printf function so we can have NULL values passed. + +2004-01-19 Thomas Vander Stichele + * gst/gstelement.h: add G_STMT macros to gst_element_error, which isn't strictly necessary but people tell me to anyway. diff --git a/gst/gstelement.c b/gst/gstelement.c index 9e81a39..12d25cd 100644 --- a/gst/gstelement.c +++ b/gst/gstelement.c @@ -2350,6 +2350,29 @@ gst_element_convert (GstElement *element, } /** + * gst_element_error_printf: + * @format: the printf-like format to use, or NULL + * + * This function is only used internally by the #gst_element_error macro. + * + * Returns: a newly allocated string, or NULL if the format was NULL or "" + */ +gchar * +gst_element_error_printf (const gchar *format, ...) +{ + va_list args; + gchar *buffer; + + if (format == NULL) return NULL; + if (format[0] == 0) return NULL; + + va_start (args, format); + buffer = g_strdup_vprintf (format, args); + va_end (args); + return buffer; +} + +/** * gst_element_error_extended: * @element: a #GstElement with the error. * @domain: the GStreamer error domain this error belongs to. @@ -2361,7 +2384,7 @@ gst_element_convert (GstElement *element, * * signals an error condition on an element. * This function is used internally by elements. - * It results in the "error_2" signal. + * It results in the "error" signal. */ void gst_element_error_extended @@ -2378,13 +2401,20 @@ gst_element_error_extended /* check if we send the given message or the default error message */ if ((message == NULL) || (message[0] == 0)) { - /* we got this message from g_strdup_printf (NULL); */ + /* we got this message from g_strdup_printf (""); */ g_free (message); sent_message = gst_error_get_message (domain, code); } else sent_message = message; + if ((debug == NULL) || (debug[0] == 0)) + { + /* we got this debug from g_strdup_printf (""); */ + g_free (debug); + debug = NULL; + } + /* create error message */ GST_CAT_INFO (GST_CAT_ERROR_SYSTEM, "signaling error in %s: %s", GST_ELEMENT_NAME (element), diff --git a/gst/gstelement.h b/gst/gstelement.h index ae3ccd6..3d1626b 100644 --- a/gst/gstelement.h +++ b/gst/gstelement.h @@ -142,8 +142,8 @@ typedef enum { #define gst_element_error(el, domain, code, message, debug) G_STMT_START { \ gst_element_error_extended (GST_ELEMENT(el), \ GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \ - g_strdup_printf message, \ - g_strdup_printf debug, \ + gst_element_error_printf message, \ + gst_element_error_printf debug, \ __FILE__, GST_FUNCTION, __LINE__); } G_STMT_END typedef struct _GstElementFactory GstElementFactory; @@ -365,6 +365,7 @@ void gst_element_found_tags_for_pad (GstElement *element, GstPad *pad, GstCloc void gst_element_set_eos (GstElement *element); +gchar * gst_element_error_printf (const gchar *format, ...); void gst_element_error_extended (GstElement *element, GQuark domain, gint code, gchar *message, gchar *debug, const gchar *file, const gchar *function, gint line); gboolean gst_element_is_locked_state (GstElement *element); -- 2.7.4