[grilo] core: Fix grl_init() when using the GOptionGroup instead
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] core: Fix grl_init() when using the GOptionGroup instead
- Date: Wed, 11 Feb 2015 14:35:53 +0000 (UTC)
commit 48fa64f445a745e148a2065c8f3d473ef0932366
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jan 22 16:07:50 2015 +0100
core: Fix grl_init() when using the GOptionGroup instead
Using the GOptionGroup instead of grl_init() should still make sure
to setup all the necessary plugin paths, etc. Move most of the code
from grl_init() to pre- and post-parse GOptionGroup hooks.
https://bugzilla.gnome.org/show_bug.cgi?id=743353
src/grilo.c | 80 ++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 50 insertions(+), 30 deletions(-)
---
diff --git a/src/grilo.c b/src/grilo.c
index ce78bc0..fda74ba 100644
--- a/src/grilo.c
+++ b/src/grilo.c
@@ -70,30 +70,12 @@ get_default_plugin_dir (void)
#endif
}
-/**
- * grl_init:
- * @argc: (inout) (allow-none): number of input arguments, length of @argv
- * @argv: (inout) (element-type utf8) (array length=argc) (allow-none) (transfer none): list of arguments
- *
- * Initializes the Grilo library
- *
- * Since: 0.1.6
- */
-void
-grl_init (gint *argc,
- gchar **argv[])
+static gboolean
+pre_parse_hook_cb (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
{
- GOptionContext *ctx;
- GOptionGroup *group;
- GrlRegistry *registry;
- gchar **split_element;
- gchar **split_list;
-
- if (grl_initialized) {
- GRL_DEBUG ("already initialized grl");
- return;
- }
-
#if !GLIB_CHECK_VERSION(2,35,0)
g_type_init ();
#endif
@@ -105,13 +87,18 @@ grl_init (gint *argc,
/* Initialize operations */
grl_operation_init ();
- /* Check options */
- ctx = g_option_context_new ("- Grilo initialization");
- g_option_context_set_ignore_unknown_options (ctx, TRUE);
- group = grl_init_get_option_group ();
- g_option_context_add_group (ctx, group);
- g_option_context_parse (ctx, argc, argv, NULL);
- g_option_context_free (ctx);
+ return TRUE;
+}
+
+static gboolean
+post_parse_hook_cb (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ GrlRegistry *registry;
+ gchar **split_element;
+ gchar **split_list;
/* Initialize GModule */
if (!g_module_supported ()) {
@@ -158,6 +145,38 @@ grl_init (gint *argc,
}
grl_initialized = TRUE;
+
+ return TRUE;
+}
+
+/**
+ * grl_init:
+ * @argc: (inout) (allow-none): number of input arguments, length of @argv
+ * @argv: (inout) (element-type utf8) (array length=argc) (allow-none) (transfer none): list of arguments
+ *
+ * Initializes the Grilo library
+ *
+ * Since: 0.1.6
+ */
+void
+grl_init (gint *argc,
+ gchar **argv[])
+{
+ GOptionContext *ctx;
+ GOptionGroup *group;
+
+ if (grl_initialized) {
+ GRL_DEBUG ("already initialized grl");
+ return;
+ }
+
+ /* Check options */
+ ctx = g_option_context_new ("- Grilo initialization");
+ g_option_context_set_ignore_unknown_options (ctx, TRUE);
+ group = grl_init_get_option_group ();
+ g_option_context_add_group (ctx, group);
+ g_option_context_parse (ctx, argc, argv, NULL);
+ g_option_context_free (ctx);
}
/**
@@ -221,6 +240,7 @@ grl_init_get_option_group (void)
NULL,
NULL);
g_option_group_add_entries (group, grl_args);
+ g_option_group_set_parse_hooks (group, pre_parse_hook_cb, post_parse_hook_cb);
return group;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]