[PATCH 1/4] Add grl_init() function



It initializes all stuff required in Grilo.

More specifically:

  - It registers default metadata keys in the registry.
  - It registers grilo media types in glib type-system.
---
 src/Makefile.am            |    2 +-
 src/{grilo.h => grilo.c}   |   47 +++++++++++++++++++++----------------------
 src/grilo.h                |    6 +++++
 src/grl-plugin-registry.c  |    2 -
 tools/grilo-test-ui/main.c |    1 +
 5 files changed, 31 insertions(+), 27 deletions(-)
 copy src/{grilo.h => grilo.c} (56%)

diff --git a/src/Makefile.am b/src/Makefile.am
index 59c35e8..8770014 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,7 +24,7 @@ lib GRL_NAME@_la_SOURCES =					\
 	grl-metadata-key.c grl-metadata-key-priv.h		\
 	grl-metadata-source.c grl-metadata-source-priv.h	\
 	grl-media-source.c					\
-	grl-log.c
+	grl-log.c grilo.c
 
 data_c_sources =		\
 	data/grl-data.c		\
diff --git a/src/grilo.h b/src/grilo.c
similarity index 56%
copy from src/grilo.h
copy to src/grilo.c
index e65503b..9881f5a 100644
--- a/src/grilo.h
+++ b/src/grilo.c
@@ -20,32 +20,31 @@
  *
  */
 
-#ifndef _GRILO_H_
-#define _GRILO_H_
+#include "grilo.h"
+#include "grl-metadata-key-priv.h"
 
-#define _GRILO_H_INSIDE_
+static gboolean grl_initialized = FALSE;
 
-#ifdef HAVE_CONFIG_H
-# ifndef PACKAGE
-#  include "config.h"
-# endif
-#endif
+void
+grl_init (gint *argc,
+          gchar **argv[])
+{
+  GrlPluginRegistry *registry;
 
-#include <grl-error.h>
-#include <grl-log.h>
-#include <grl-plugin-registry.h>
-#include <grl-media-plugin.h>
-#include <grl-media-source.h>
-#include <grl-metadata-source.h>
-#include <grl-metadata-key.h>
-#include <grl-data.h>
-#include <grl-media.h>
-#include <grl-media-audio.h>
-#include <grl-media-video.h>
-#include <grl-media-image.h>
-#include <grl-media-box.h>
-#include <grl-config.h>
+  if (grl_initialized) {
+    g_debug ("already initialized grl");
+    return;
+  }
 
-#undef _GRILO_H_INSIDE_
+  /* Register default metadata keys */
+  registry = grl_plugin_registry_get_instance ();
+  grl_metadata_key_setup_system_keys (registry);
 
-#endif /* _GRILO_H_ */
+  /* Register GrlMedia in glib typesystem */
+  g_type_class_ref (GRL_TYPE_MEDIA_BOX);
+  g_type_class_ref (GRL_TYPE_MEDIA_AUDIO);
+  g_type_class_ref (GRL_TYPE_MEDIA_VIDEO);
+  g_type_class_ref (GRL_TYPE_MEDIA_IMAGE);
+
+  grl_initialized = TRUE;
+}
diff --git a/src/grilo.h b/src/grilo.h
index e65503b..9380cf2 100644
--- a/src/grilo.h
+++ b/src/grilo.h
@@ -48,4 +48,10 @@
 
 #undef _GRILO_H_INSIDE_
 
+G_BEGIN_DECLS
+
+void grl_init (gint *argc, gchar **argv[]);
+
+G_END_DECLS
+
 #endif /* _GRILO_H_ */
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index f573cd5..3e1a60b 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -39,7 +39,6 @@
 
 #include "grl-plugin-registry.h"
 #include "grl-media-plugin-priv.h"
-#include "grl-metadata-key-priv.h"
 #include "config.h"
 
 #include <string.h>
@@ -133,7 +132,6 @@ grl_plugin_registry_init (GrlPluginRegistry *registry)
   registry->priv->system_keys =
     g_param_spec_pool_new (FALSE);
 
-  grl_metadata_key_setup_system_keys (registry);
   grl_plugin_registry_setup_ranks (registry);
 }
 
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 6c26ed2..e7d4f53 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -1532,6 +1532,7 @@ int
 main (int argc, gchar *argv[])
 {
   gtk_init (&argc, &argv);
+  grl_init (&argc, &argv);
   grl_log_init ("*:*");
   launchers_setup ();
   ui_setup ();
-- 
1.7.0.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]