5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <readline/readline.h>
32 #include <readline/history.h>
36 #include <sys/types.h>
44 #include "technology.h"
45 #include "data_manager.h"
47 #include "interactive.h"
49 static DBusConnection *interactive_conn;
51 static gboolean rl_handler(char *input)
53 char **long_args = NULL;
63 long_args = g_strsplit(input, " ", 0);
65 if (long_args == NULL || long_args[0] == NULL) {
66 g_strfreev(long_args);
71 for (num_args = 0; long_args[num_args] != NULL; num_args++);
73 error = commands(interactive_conn, long_args, num_args);
75 if ((strcmp(long_args[0], "quit") == 0)
76 || (strcmp(long_args[0], "exit") == 0)
77 || (strcmp(long_args[0], "q") == 0)) {
78 g_strfreev(long_args);
82 fprintf(stderr, "%s is not a valid command, check help.\n",
86 g_strfreev(long_args);
92 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
94 if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
95 g_io_channel_unref(channel);
98 rl_callback_read_char();
102 void show_interactive(DBusConnection *connection, GMainLoop *mainloop)
106 gchan = g_io_channel_unix_new(fileno(stdin));
107 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
108 interactive_conn = connection;
111 g_io_add_watch(gchan, events, readmonitor, NULL);
112 rl_callback_handler_install("connmanctl> ", (void *)rl_handler);
113 g_main_loop_run(mainloop);
115 rl_callback_handler_remove();
116 g_io_channel_unref(gchan);