adding a helper printf function for gst_element_error

Original commit message from CVS:
adding a helper printf function for gst_element_error
This commit is contained in:
Thomas Vander Stichele 2004-01-19 11:32:35 +00:00
parent f26ac1474a
commit b0a02001fa
3 changed files with 42 additions and 4 deletions

View file

@ -1,3 +1,10 @@
2004-01-19 Thomas Vander Stichele <thomas at apestaart dot org>
* 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 <thomas at apestaart dot org> 2004-01-19 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/gstelement.h: * gst/gstelement.h:

View file

@ -2349,6 +2349,29 @@ gst_element_convert (GstElement *element,
return FALSE; return FALSE;
} }
/**
* 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: * gst_element_error_extended:
* @element: a #GstElement with the error. * @element: a #GstElement with the error.
@ -2361,7 +2384,7 @@ gst_element_convert (GstElement *element,
* *
* signals an error condition on an element. * signals an error condition on an element.
* This function is used internally by elements. * This function is used internally by elements.
* It results in the "error_2" signal. * It results in the "error" signal.
*/ */
void void
gst_element_error_extended gst_element_error_extended
@ -2378,13 +2401,20 @@ gst_element_error_extended
/* check if we send the given message or the default error message */ /* check if we send the given message or the default error message */
if ((message == NULL) || (message[0] == 0)) 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); g_free (message);
sent_message = gst_error_get_message (domain, code); sent_message = gst_error_get_message (domain, code);
} }
else else
sent_message = message; 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 */ /* create error message */
GST_CAT_INFO (GST_CAT_ERROR_SYSTEM, "signaling error in %s: %s", GST_CAT_INFO (GST_CAT_ERROR_SYSTEM, "signaling error in %s: %s",
GST_ELEMENT_NAME (element), GST_ELEMENT_NAME (element),

View file

@ -142,8 +142,8 @@ typedef enum {
#define gst_element_error(el, domain, code, message, debug) G_STMT_START { \ #define gst_element_error(el, domain, code, message, debug) G_STMT_START { \
gst_element_error_extended (GST_ELEMENT(el), \ gst_element_error_extended (GST_ELEMENT(el), \
GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \ GST_ ## domain ## _ERROR, GST_ ## domain ## _ERROR_ ## code, \
g_strdup_printf message, \ gst_element_error_printf message, \
g_strdup_printf debug, \ gst_element_error_printf debug, \
__FILE__, GST_FUNCTION, __LINE__); } G_STMT_END __FILE__, GST_FUNCTION, __LINE__); } G_STMT_END
typedef struct _GstElementFactory GstElementFactory; 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); 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); 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); gboolean gst_element_is_locked_state (GstElement *element);