gstinfo: Reduce code duplication around level pattern matching
authorJan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Tue, 27 Mar 2018 08:14:27 +0000 (10:14 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 5 Apr 2018 09:52:13 +0000 (10:52 +0100)
Move the match, logging and set_threshold to a new function.

The log levels are different, so choose the higher one (LOG). Having two
equivalent messages at two different levels seems like a bad idea
anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=794717

gst/gstinfo.c

index 8bb1a2a..63857ce 100644 (file)
@@ -1577,6 +1577,20 @@ gst_debug_get_default_threshold (void)
   return (GstDebugLevel) g_atomic_int_get (&__default_level);
 }
 
+static gboolean
+gst_debug_apply_entry (GstDebugCategory * cat, LevelNameEntry * entry)
+{
+  if (!g_pattern_match_string (entry->pat, cat->name))
+    return FALSE;
+
+  if (gst_is_initialized ())
+    GST_LOG ("category %s matches pattern %p - gets set to level %d",
+        cat->name, entry->pat, entry->level);
+
+  gst_debug_category_set_threshold (cat, entry->level);
+  return TRUE;
+}
+
 static void
 gst_debug_reset_threshold (gpointer category, gpointer unused)
 {
@@ -1589,13 +1603,8 @@ gst_debug_reset_threshold (gpointer category, gpointer unused)
     LevelNameEntry *entry = walk->data;
 
     walk = g_slist_next (walk);
-    if (g_pattern_match_string (entry->pat, cat->name)) {
-      if (gst_is_initialized ())
-        GST_LOG ("category %s matches pattern %p - gets set to level %d",
-            cat->name, entry->pat, entry->level);
-      gst_debug_category_set_threshold (cat, entry->level);
+    if (gst_debug_apply_entry (cat, entry))
       goto exit;
-    }
   }
   gst_debug_category_set_threshold (cat, gst_debug_get_default_threshold ());
 
@@ -1617,12 +1626,7 @@ for_each_threshold_by_entry (gpointer data, gpointer user_data)
   GstDebugCategory *cat = (GstDebugCategory *) data;
   LevelNameEntry *entry = (LevelNameEntry *) user_data;
 
-  if (g_pattern_match_string (entry->pat, cat->name)) {
-    if (gst_is_initialized ())
-      GST_TRACE ("category %s matches pattern %p - gets set to level %d",
-          cat->name, entry->pat, entry->level);
-    gst_debug_category_set_threshold (cat, entry->level);
-  }
+  gst_debug_apply_entry (cat, entry);
 }
 
 /**