grim/guifications3

merging

2011-05-16, Gary Kramlich
8e6f170cb062
merging
/*
* Guifications - The end-all, be-all notification framework
* Copyright (C) 2003-2009 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <gf_lib.h>
#include "guifications-daemon-connections.h"
#include "guifications-daemon-feed-manager.h"
#include "guifications-daemon-signals.h"
/******************************************************************************
* Globals
*****************************************************************************/
static GfPreferenceEngine *engine = NULL;
static GMainLoop *main_loop = NULL;
static gchar *log_filename = NULL;
static GOptionEntry entries[] = {
{
"log", 'l', 0, G_OPTION_ARG_FILENAME, &log_filename,
"The filename to log to. If no filename is given, stdout is used.",
"filename",
}, {
NULL,
}
};
/******************************************************************************
* API
*****************************************************************************/
void
gfd_init(gint *argc, gchar ***argv) {
gchar *homedir = NULL, *path = NULL;
gf_lib_init(argc, argv);
if(log_filename) {
GfLogger *logger = gf_file_logger_new(log_filename);
gf_logger_open(logger);
gf_log_set_logger(logger);
/* remove our reference to the new logger */
g_object_unref(G_OBJECT(logger));
g_free(log_filename);
}
/* add the glib log handlers */
gf_log_add_g_log_handlers();
/* Create our preference engine */
homedir = gf_fs_user_home_dir();
path = g_build_filename(homedir, ".guifications", "daemon",
"preferences.xml", NULL);
g_free(homedir);
engine = gf_preference_engine_xml_new(path);
g_free(path);
gf_preferences_add_engine(engine, "/daemon");
/* add our plugin path to the plugin manager */
path = g_build_filename(LIBDIR, "guifications-daemon", NULL);
gf_plugin_manager_add_path(path);
g_free(path);
/* initialize various subsystems */
gfd_signals_init();
gfd_feed_manager_init();
gfd_connections_init(gfd_feed_manager_get_manager(), engine);
/* create our main loop */
main_loop = g_main_loop_new(NULL, FALSE);
/* refresh the list of plugins now that the local connection is setup */
gf_plugin_manager_refresh();
/* now refresh the connections for any plugins */
gfd_connections_refresh();
}
void
gfd_run(void) {
/* we connect here so that we don't get any messages before we hit the main
* loop.
*/
gfd_connections_listen();
gf_log_event("Guifications-Daemon", "Started.\n");
g_main_loop_run(main_loop);
}
void
gfd_quit(void) {
gf_log_event("Guifications-Daemon", "Shutting down.\n");
/* shutdown the subsystems */
gfd_connections_close();
gfd_signals_uninit();
/* clean up the preference engine */
g_object_unref(G_OBJECT(engine));
gf_log_event("Guifications-Daemon", "Stopped.\n");
/* stop the main loop */
g_main_loop_quit(main_loop);
main_loop = NULL;
}
/******************************************************************************
* Exports
*****************************************************************************/
gint
main(gint argc, gchar **argv) {
GError *error = NULL;
GOptionContext *ctx = NULL;
ctx = g_option_context_new(NULL);
g_option_context_add_main_entries(ctx, entries, GETTEXT_PACKAGE);
g_option_context_add_group(ctx, gf_get_option_group());
g_option_context_parse(ctx, &argc, &argv, &error);
g_option_context_free(ctx);
if(error) {
fprintf(stderr, "%s\n", error->message);
g_error_free(error);
return 1;
}
gfd_init(&argc, &argv);
gfd_run();
return 0;
}