Clean up argument parsing GError handling

Pass a GError in, so that clutter_init() can effectively print out a
critical warning on initialization failure, like it used to do in the
olden days.
This commit is contained in:
Emmanuele Bassi 2011-03-04 23:55:02 +00:00
parent 4f3a4ab01b
commit 8bde5febd1

View File

@ -1772,11 +1772,13 @@ clutter_get_option_group (void)
* Returns a #GOptionGroup for the command line arguments recognized * Returns a #GOptionGroup for the command line arguments recognized
* by Clutter. You should add this group to your #GOptionContext with * by Clutter. You should add this group to your #GOptionContext with
* g_option_context_add_group(), if you are using g_option_context_parse() * g_option_context_add_group(), if you are using g_option_context_parse()
* to parse your commandline arguments. Unlike clutter_get_option_group(), * to parse your commandline arguments.
* calling g_option_context_parse() with the #GOptionGroup returned by this *
* function requires a subsequent explicit call to clutter_init(); use this * Unlike clutter_get_option_group(), calling g_option_context_parse() with
* function when needing to set foreign display connection with * the #GOptionGroup returned by this function requires a subsequent explicit
* clutter_x11_set_display(), or with <function>gtk_clutter_init()</function>. * call to clutter_init(); use this function when needing to set foreign
* display connection with clutter_x11_set_display(), or with
* <function>gtk_clutter_init()</function>.
* *
* Return value: (transfer full): a #GOptionGroup for the commandline arguments * Return value: (transfer full): a #GOptionGroup for the commandline arguments
* recognized by Clutter * recognized by Clutter
@ -1904,14 +1906,15 @@ clutter_init_with_args (int *argc,
static gboolean static gboolean
clutter_parse_args (int *argc, clutter_parse_args (int *argc,
char ***argv) char ***argv,
GError **error)
{ {
GOptionContext *option_context; GOptionContext *option_context;
GOptionGroup *clutter_group, *cogl_group; GOptionGroup *clutter_group, *cogl_group;
#ifdef CLUTTER_ENABLE_PROFILE #ifdef CLUTTER_ENABLE_PROFILE
GOptionGroup *uprof_group; GOptionGroup *uprof_group;
#endif #endif
GError *error = NULL; GError *internal_error = NULL;
gboolean ret = TRUE; gboolean ret = TRUE;
if (clutter_is_initialized) if (clutter_is_initialized)
@ -1922,7 +1925,6 @@ clutter_parse_args (int *argc,
g_option_context_set_help_enabled (option_context, FALSE); g_option_context_set_help_enabled (option_context, FALSE);
/* Initiate any command line options from the backend */ /* Initiate any command line options from the backend */
clutter_group = clutter_get_option_group (); clutter_group = clutter_get_option_group ();
g_option_context_set_main_group (option_context, clutter_group); g_option_context_set_main_group (option_context, clutter_group);
@ -1934,14 +1936,9 @@ clutter_parse_args (int *argc,
g_option_context_add_group (option_context, uprof_group); g_option_context_add_group (option_context, uprof_group);
#endif #endif
if (!g_option_context_parse (option_context, argc, argv, &error)) if (!g_option_context_parse (option_context, argc, argv, &internal_error))
{ {
if (error) g_propagate_error (error, internal_error);
{
g_warning ("%s", error->message);
g_error_free (error);
}
ret = FALSE; ret = FALSE;
} }
@ -1956,12 +1953,20 @@ clutter_parse_args (int *argc,
* @argv: (array length=argc) (inout) (allow-none): A pointer to an array * @argv: (array length=argc) (inout) (allow-none): A pointer to an array
* of arguments. * of arguments.
* *
* It will initialise everything needed to operate with Clutter and * Initialises everything needed to operate with Clutter and parses some
* parses some standard command line options. @argc and @argv are * standard command line options; @argc and @argv are adjusted accordingly
* adjusted accordingly so your own code will never see those standard * so your own code will never see those standard arguments.
* arguments.
* *
* Return value: 1 on success, < 0 on failure. * It is safe to call this function multiple times.
*
* <note>This function will not abort in case of errors during
* initialization; clutter_init() will print out the error message on
* stderr, and will return an error code. It is up to the application
* code to handle this case. If you need to display the error message
* yourself, you can use clutter_init_with_args(), which takes a #GError
* pointer.</note>
*
* Return value: a #ClutterInitError value
*/ */
ClutterInitError ClutterInitError
clutter_init (int *argc, clutter_init (int *argc,
@ -1969,6 +1974,7 @@ clutter_init (int *argc,
{ {
ClutterMainContext *ctx; ClutterMainContext *ctx;
GError *error = NULL; GError *error = NULL;
ClutterInitError res;
if (clutter_is_initialized) if (clutter_is_initialized)
return CLUTTER_INIT_SUCCESS; return CLUTTER_INIT_SUCCESS;
@ -1987,16 +1993,27 @@ clutter_init (int *argc,
/* parse_args will trigger backend creation and things like /* parse_args will trigger backend creation and things like
* DISPLAY connection etc. * DISPLAY connection etc.
*/ */
if (clutter_parse_args (argc, argv) == FALSE) if (!clutter_parse_args (argc, argv, &error))
{ {
CLUTTER_NOTE (MISC, "failed to parse arguments."); g_critical ("Unable to initialize Clutter: %s", error->message);
return CLUTTER_INIT_ERROR_INTERNAL; g_error_free (error);
}
return CLUTTER_INIT_SUCCESS; res = CLUTTER_INIT_ERROR_INTERNAL;
} }
else else
return clutter_init_real (&error); res = CLUTTER_INIT_SUCCESS;
}
else
{
res = clutter_init_real (&error);
if (error != NULL)
{
g_critical ("Unable to initialize Clutter: %s", error->message);
g_error_free (error);
}
}
return res;
} }
gboolean gboolean