1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/* 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 <glib/gmain.h>
#include <gmodule.h>
#include <libgda/libgda.h>
#include <libgda/gda-intl.h>
/* 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;
}
|