5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
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
33 #include <readline/readline.h>
38 #include "data_manager.h"
40 #include "technology.h"
41 #include "interactive.h"
43 static GMainLoop *main_loop;
44 DBusConnection *connection;
46 static gboolean timeout_wait(gpointer data)
50 /* Set to whatever number of retries is wanted/needed */
52 g_main_loop_quit(data);
58 static void rl_handler(char *input)
64 printf("Use ctrl-d to exit\n");
67 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
69 rl_callback_read_char();
73 int main(int argc, char *argv[])
78 main_loop = g_main_loop_new(NULL, FALSE);
80 dbus_error_init(&err);
82 connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
84 if (dbus_error_is_set(&err)) {
85 fprintf(stderr, "Connection Error: %s\n", err.message);
86 dbus_error_free(&err);
89 if (connection == NULL) {
90 fprintf(stderr, "Could not connect to system bus...exiting\n");
95 show_interactive(connection, main_loop);
97 error = commands(connection, argv + 1, argc -1);
102 printf("Usage: connmanctl [[command] [args]]\n");
103 commands(connection, &help, 1);
104 printf("\nNote: arguments and output are considered "
105 "EXPERIMENTAL for now.\n\n");
112 gchan = g_io_channel_unix_new(fileno(stdin));
113 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
114 g_io_add_watch(gchan, events, readmonitor, NULL);
115 rl_callback_handler_install("", rl_handler);
117 if (strcmp(argv[1], "monitor") != 0)
118 g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
120 g_main_loop_run(main_loop);
121 rl_callback_handler_remove();
122 g_io_channel_unref(gchan);
123 if (main_loop != NULL)
124 g_main_loop_unref(main_loop);