validate: Add a method to easily get plugin configuration
authorThibault Saunier <thibault.saunier@collabora.com>
Mon, 2 Mar 2015 10:03:08 +0000 (11:03 +0100)
committerThibault Saunier <tsaunier@gnome.org>
Fri, 10 Apr 2015 14:53:41 +0000 (16:53 +0200)
Reviewers: Mathieu_Du

Differential Revision: http://phabricator.freedesktop.org/D77

validate/gst/plugins/gapplication/gstvalidategapplication.c
validate/gst/validate/validate.c
validate/gst/validate/validate.h

index ad27806..7dc4f4d 100644 (file)
@@ -30,6 +30,7 @@
 #include <gst/gst.h>
 #include <gio/gio.h>
 
+#include "../../validate/validate.h"
 #include "../../validate/gst-validate-scenario.h"
 #include "../../validate/gst-validate-utils.h"
 
@@ -45,25 +46,22 @@ _execute_stop (GstValidateScenario * scenario, GstValidateAction * action)
 static gboolean
 gst_validate_gapplication_init (GstPlugin * plugin)
 {
-  GList *structures, *tmp;
-  const gchar *appname = NULL, *config = g_getenv ("GST_VALIDATE_CONFIG");
+  GList *config, *tmp;
+  const gchar *appname;
 
-  if (!config)
-    return TRUE;
-
-  structures = gst_validate_utils_structs_parse_from_filename (config);
+  config = gst_validate_plugin_get_config (plugin);
 
-  if (!structures)
+  if (!config)
     return TRUE;
 
-  for (tmp = structures; tmp; tmp = tmp->next) {
-    if (gst_structure_has_name (tmp->data, "gapplication"))
-      appname = gst_structure_get_string (tmp->data, "application-name");
+  for (tmp = config; tmp; tmp = tmp->next) {
+    appname = gst_structure_get_string (tmp->data, "application-name");
   }
-  g_list_free_full (structures, (GDestroyNotify) gst_structure_free);
 
-  if (appname && g_strcmp0 (g_get_prgname (), appname))
+  if (appname && g_strcmp0 (g_get_prgname (), appname)) {
+    GST_INFO_OBJECT (plugin, "App: %s is not %s", g_get_prgname (), appname);
     return TRUE;
+  }
 
   gst_validate_register_action_type_dynamic (plugin, "stop",
       GST_RANK_PRIMARY, _execute_stop, NULL,
index f99c4e9..3dfbf16 100644 (file)
@@ -36,6 +36,7 @@
 #include <unistd.h>
 
 #include "validate.h"
+#include "gst-validate-utils.h"
 #include "gst-validate-internal.h"
 
 #ifdef G_OS_WIN32
@@ -79,6 +80,37 @@ gst_validate_registry_get (void)
   return registry;
 }
 
+#define GST_VALIDATE_PLUGIN_CONFIG "gst-validate-plugin-config"
+
+static void
+_free_plugin_config (gpointer data)
+{
+  g_list_free_full (data, (GDestroyNotify) gst_structure_free);
+}
+
+GList *
+gst_validate_plugin_get_config (GstPlugin * plugin)
+{
+  GList *structures = NULL, *tmp, *plugin_conf = NULL;
+  const gchar *config = g_getenv ("GST_VALIDATE_CONFIG");
+
+  if ((plugin_conf =
+          g_object_get_data (G_OBJECT (plugin), GST_VALIDATE_PLUGIN_CONFIG)))
+    return plugin_conf;
+
+  if (config)
+    structures = gst_validate_utils_structs_parse_from_filename (config);
+
+  for (tmp = structures; tmp; tmp = tmp->next) {
+    if (gst_structure_has_name (tmp->data, gst_plugin_get_name (plugin)))
+      plugin_conf = g_list_append (plugin_conf, tmp->data);
+  }
+  g_object_set_data_full (G_OBJECT (plugin), GST_VALIDATE_PLUGIN_CONFIG,
+      plugin_conf, _free_plugin_config);
+
+  return plugin_conf;
+}
+
 static void
 gst_validate_init_plugins (void)
 {
index 938d74b..6c5d714 100644 (file)
@@ -16,5 +16,6 @@
 #include <gst/validate/gst-validate-media-info.h>
 
 void gst_validate_init (void);
+GList * gst_validate_plugin_get_config (GstPlugin * plugin);
 
 #endif /* _GST_VALIDATE_H */