diff options
author | Charlie Brej <cbrej@cs.man.ac.uk> | 2010-08-04 20:30:29 +0100 |
---|---|---|
committer | Charlie Brej <cbrej@cs.man.ac.uk> | 2010-08-04 20:30:29 +0100 |
commit | 26ebd4ac62e7968b230631b3fd02a9a52abcf1ad (patch) | |
tree | e04bc44e20a5a79f04ee41d9b2420806844b4fec | |
parent | c767c5017401639b4d44f68fb014895a2f86c07d (diff) |
Add command line parsing
-rw-r--r-- | src/main.c | 39 |
1 files changed, 31 insertions, 8 deletions
@@ -37,26 +37,49 @@ void print_guid (PtrTidbitGuid guid, gpointer database) } -int main(int argc, char** argv) +int main(int argc, char* argv[]) { - GMainLoop *loop; - + + gboolean enable_http = FALSE; + gboolean enable_dbus = FALSE; + + GOptionEntry option_entries[] = + { + { "enable-http", 'h', 0, G_OPTION_ARG_NONE, &enable_http, "Enable HTTP fontend", NULL }, + { "enable-dbus", 'd', 0, G_OPTION_ARG_NONE, &enable_dbus, "Enable D-BUS fontend", NULL }, + { NULL } + }; + + GError *error = NULL; + GOptionContext *context = g_option_context_new ("- Server for exchanging tidbit packets"); + g_option_context_add_main_entries (context, option_entries, NULL); + if (!g_option_context_parse (context, &argc, &argv, &error)){ + g_print ("option parsing failed: %s\n", error->message); + exit (1); + } + + + + g_type_init (); if (!g_thread_supported ()) g_thread_init (NULL); dbus_g_thread_init (); - loop = g_main_loop_new (NULL, FALSE); + GMainLoop *loop = g_main_loop_new (NULL, FALSE); PtrTidbitDatabase database; - if (argv[1]){ + if (enable_http || enable_dbus) database = tidbit_database_fork_new(tidbit_database_mem_new (), tidbit_database_mem_new ()); - tidbit_dbus_setup (database); - tidbit_http_setup (database); - } else database = tidbit_database_dbus_new (); + + if (enable_http) + tidbit_http_setup (database); + if (enable_dbus) + tidbit_dbus_setup (database); + PtrTidbitRecord record = tidbit_record_new ("test/tablename"); |