summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-03-27 13:53:53 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-04-04 10:24:06 +0300
commitd1184f48499c21e12504b52d06cf637dd11fa4d1 (patch)
tree59723cec208438ef56ffb7d7bedff60db5a1cffd /client
parent497769cbdb3e1883a51ea237c46664a26d72b42f (diff)
downloadconnman-d1184f48499c21e12504b52d06cf637dd11fa4d1.tar.gz
connman-d1184f48499c21e12504b52d06cf637dd11fa4d1.tar.bz2
connman-d1184f48499c21e12504b52d06cf637dd11fa4d1.zip
client: Remove readline handling from main.c
Diffstat (limited to 'client')
-rw-r--r--client/main.c110
1 files changed, 6 insertions, 104 deletions
diff --git a/client/main.c b/client/main.c
index 8aa845dd..6d3c57f9 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2,12 +2,12 @@
*
* Connection Manager
*
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
- *
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
+ * 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
@@ -20,107 +20,9 @@
*
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <string.h>
-#include <errno.h>
-#include <readline/readline.h>
-
-#include <glib.h>
-#include <gdbus.h>
-
-#include "data_manager.h"
-#include "services.h"
-#include "technology.h"
-#include "interactive.h"
-
-static GMainLoop *main_loop;
-DBusConnection *connection;
-
-static gboolean timeout_wait(gpointer data)
-{
- static int i;
- i++;
- /* Set to whatever number of retries is wanted/needed */
- if (i == 1) {
- g_main_loop_quit(data);
- return FALSE;
- }
- return TRUE;
-}
-
-static void rl_handler(char *input)
-{
-
- if (input == NULL)
- exit(EXIT_FAILURE);
- else
- printf("Use ctrl-d to exit\n");
-}
-
-static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
- gpointer user_data){
- rl_callback_read_char();
- return TRUE;
-}
+#include "input.h"
int main(int argc, char *argv[])
{
- DBusError err;
- int events, error;
- GIOChannel *gchan;
- main_loop = g_main_loop_new(NULL, FALSE);
-
- dbus_error_init(&err);
-
- connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
-
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error: %s\n", err.message);
- dbus_error_free(&err);
- }
-
- if (connection == NULL) {
- fprintf(stderr, "Could not connect to system bus...exiting\n");
- exit(EXIT_FAILURE);
- }
-
- if (argc < 2)
- show_interactive(connection, main_loop);
-
- error = commands(connection, argv + 1, argc -1);
-
- if (error == -1) {
- char *help = "help";
-
- printf("Usage: connmanctl [[command] [args]]\n");
- commands(connection, &help, 1);
- printf("\nNote: arguments and output are considered "
- "EXPERIMENTAL for now.\n\n");
- return -EINVAL;
- }
-
- if (error < 0)
- return error;
-
- gchan = g_io_channel_unix_new(fileno(stdin));
- events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
- g_io_add_watch(gchan, events, readmonitor, NULL);
- rl_callback_handler_install("", rl_handler);
-
- if (strcmp(argv[1], "monitor") != 0)
- g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
- main_loop, NULL);
- g_main_loop_run(main_loop);
- rl_callback_handler_remove();
- g_io_channel_unref(gchan);
- if (main_loop != NULL)
- g_main_loop_unref(main_loop);
- return 0;
+ return __connmanctl_input_init(argc, argv);
}