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"
46 #include "interactive.h"
48 static DBusConnection *interactive_conn;
50 static gboolean rl_handler(char *input)
52 char **long_args = NULL;
62 long_args = g_strsplit(input, " ", 0);
64 if (long_args == NULL || long_args[0] == NULL) {
65 g_strfreev(long_args);
70 for (num_args = 0; long_args[num_args] != NULL; num_args++);
72 error = commands(interactive_conn, long_args, num_args);
74 if ((strcmp(long_args[0], "quit") == 0)
75 || (strcmp(long_args[0], "exit") == 0)
76 || (strcmp(long_args[0], "q") == 0)) {
77 g_strfreev(long_args);
81 fprintf(stderr, "%s is not a valid command, check help.\n",
85 g_strfreev(long_args);
91 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
93 if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
94 g_io_channel_unref(channel);
97 rl_callback_read_char();
101 void show_interactive(DBusConnection *connection, GMainLoop *mainloop)
105 gchan = g_io_channel_unix_new(fileno(stdin));
106 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
107 interactive_conn = connection;
110 g_io_add_watch(gchan, events, readmonitor, NULL);
111 rl_callback_handler_install("connmanctl> ", (void *)rl_handler);
112 g_main_loop_run(mainloop);
114 rl_callback_handler_remove();
115 g_io_channel_unref(gchan);