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"
44 static GMainLoop *main_loop;
45 DBusConnection *connection;
47 static gboolean timeout_wait(gpointer data)
51 /* Set to whatever number of retries is wanted/needed */
53 g_main_loop_quit(data);
59 static void rl_handler(char *input)
65 printf("Use ctrl-d to exit\n");
68 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
70 rl_callback_read_char();
74 int main(int argc, char *argv[])
79 main_loop = g_main_loop_new(NULL, FALSE);
81 dbus_error_init(&err);
83 connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
85 if (dbus_error_is_set(&err)) {
86 fprintf(stderr, "Connection Error: %s\n", err.message);
87 dbus_error_free(&err);
90 if (connection == NULL) {
91 fprintf(stderr, "Could not connect to system bus...exiting\n");
96 show_interactive(connection, main_loop);
98 error = commands(connection, argv + 1, argc -1);
103 printf("Usage: connmanctl [[command] [args]]\n");
104 commands(connection, &help, 1);
105 printf("\nNote: arguments and output are considered "
106 "EXPERIMENTAL for now.\n\n");
113 gchan = g_io_channel_unix_new(fileno(stdin));
114 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
115 g_io_add_watch(gchan, events, readmonitor, NULL);
116 rl_callback_handler_install("", rl_handler);
118 if (strcmp(argv[1], "monitor") != 0)
119 g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
121 g_main_loop_run(main_loop);
122 rl_callback_handler_remove();
123 g_io_channel_unref(gchan);
124 if (main_loop != NULL)
125 g_main_loop_unref(main_loop);