/* diversity-backend - * * Copyright 2007-2008 OpenMoko, Inc. * Authored by Daniel Willmann * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include static GMainLoop *mainloop; static DiversityWorld *world; static void on_signal(int sig) { if (mainloop) g_main_loop_quit(mainloop); else exit(1); } static gboolean no_daemon; static GOptionEntry entries[] = { { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &no_daemon, "Don't become a daemon", NULL }, { NULL } }; static int init(int argc, char **argv, GError **error) { struct sigaction act; GOptionContext *context; act.sa_handler = on_signal; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGINT, &act, NULL); context = g_option_context_new(NULL); g_option_context_add_main_entries(context, entries, NULL); if (!g_option_context_parse(context, &argc, &argv, error)) return FALSE; g_option_context_free(context); return TRUE; } static gboolean backends_load(DiversityWorld *world, GError **error) { #if HAVE_GEOCLUE g_debug("initialize GeoClue backend\n"); if (!geoclue_init(world, error)) { g_printerr("failed to initialize GeoClue backend\n"); return FALSE; } #endif #if HAVE_GYPSY g_debug("initialize Gypsy backend\n"); if (!gypsy_init(world, error)) { g_printerr("failed to initialize Gypsy backend\n"); return FALSE; } #endif #if HAVE_NMEA g_debug("initialize NMEA backend\n"); if (!nmea_init(world, error)) { g_printerr("failed to initialize NMEA backend\n"); return FALSE; } #endif #if HAVE_NM g_debug("initialize NetworkManager backend\n"); if (!nm_init(world, error)) { g_printerr("failed to initialize NetworkManager backend\n"); return FALSE; } #endif #if HAVE_EBOOK g_debug("initialize EBook backend\n"); if (!ebook_init(world, error)) { g_printerr("failed to initialize EBook backend\n"); return FALSE; } #endif #if HAVE_OSM g_debug("initialize OpenStreetMap backend\n"); if (!osm_init(world, error)) { g_printerr("failed to initialize OpenStreetMap backend\n"); return FALSE; } #endif #if HAVE_PHONEKIT g_debug("initialize PhoneKit backend\n"); if (!phonekit_init(world, error)) { g_printerr("failed to initialize PhoneKit backend\n"); return FALSE; } #endif #if HAVE_CONTROL g_debug("initialize Control backend\n"); if (!control_init(world, error)) { g_printerr("failed to initialize Control backend\n"); return FALSE; } #endif #if HAVE_XMPP g_debug("initialize XMPP backend\n"); if (!xmpp_init(world, error)) { g_printerr("failed to initialize XMPP backent\n"); return FALSE; } #endif return TRUE; } static void backends_unload(DiversityWorld *world) { #if HAVE_XMPP xmpp_fini(); #endif #if HAVE_CONTROL control_fini(); #endif #if HAVE_PHONEKIT phonekit_fini(); #endif #if HAVE_OSM osm_fini(); #endif #if HAVE_EBOOK ebook_fini(); #endif #if HAVE_NM nm_fini(); #endif #if HAVE_NMEA nmea_fini(); #endif #if HAVE_GYPSY gypsy_fini(); #endif #if HAVE_GEOCLUE geoclue_fini(); #endif } static void equip_equipments(DiversityWorld *world) { DiversityBard *self; GSList *tmp_list; self = diversity_world_get_self(world); tmp_list = (GSList *) diversity_bard_get_equipments(self); while (tmp_list) { diversity_bard_equip_equipment(self, tmp_list->data); tmp_list = tmp_list->next; } } int main(int argc, char **argv) { GError *error = NULL; if (!init(argc, argv, &error)) { g_printerr("failed to init: %s\n", error->message); goto fail; } if (!no_daemon) { g_printerr("FIXME: daemon mode is not implemented\n"); no_daemon = TRUE; } g_type_init(); world = g_object_new(DIVERSITY_TYPE_WORLD, NULL); if (!backends_load(world, &error)) { g_printerr("failed to load backends: %s\n", error->message); goto fail; } equip_equipments(world); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_main_loop_unref(mainloop); backends_unload(world); g_object_unref(world); return 0; fail: if (error) g_error_free(error); return 1; }