/* GDA Library * Copyright (C) 1998-2002 The GNOME Foundation. * * This Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This Library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include #include #include #include /* Include the marshalers here */ #include "gda-marshal.h" #include "gda-marshal.c" /* end of marshalers */ static GMainLoop *main_loop = NULL; /** * gda_init * @app_id: name of the program. * @version: revision number of the program. * @nargs: number of arguments, usually argc from main(). * @args: list of arguments, usually argv from main(). * * Initializes the GDA library. */ void gda_init (const gchar *app_id, const gchar *version, gint nargs, gchar *args[]) { static gboolean initialized = FALSE; if (initialized) { gda_log_error (_("Attempt to initialize an already initialized client")); return; } bindtextdomain (GETTEXT_PACKAGE, LIBGDA_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); g_type_init (); g_set_prgname (app_id); if (!g_module_supported ()) g_error (_("libgda needs GModule. Finishing...")); initialized = TRUE; } typedef struct { GdaInitFunc init_func; gpointer user_data; } InitCbData; static gboolean idle_cb (gpointer user_data) { InitCbData *cb_data = (InitCbData *) user_data; g_return_val_if_fail (cb_data != NULL, FALSE); if (cb_data->init_func) cb_data->init_func (cb_data->user_data); g_free (cb_data); return FALSE; } /** * gda_main_run * @init_func: function to be called when everything has been initialized. * @user_data: data to be passed to the init function. * * Runs the GDA main loop, which is nothing more than the Bonobo main * loop, but with internally added stuff specific for applications using * libgda. * * You can specify a function to be called after everything has been correctly * initialized (that is, for initializing your own stuff). */ void gda_main_run (GdaInitFunc init_func, gpointer user_data) { if (main_loop) return; if (init_func) { InitCbData *cb_data; cb_data = g_new (InitCbData, 1); cb_data->init_func = init_func; cb_data->user_data = user_data; g_idle_add ((GSourceFunc) idle_cb, cb_data); } main_loop = g_main_loop_new (g_main_context_default (), FALSE); g_main_loop_run (main_loop); } /** * gda_main_quit * * Exits the main loop. */ void gda_main_quit (void) { g_main_loop_quit (main_loop); g_main_loop_unref (main_loop); main_loop = NULL; }