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
29 #include <readline/readline.h>
33 #include <dbus/dbus.h>
36 #include "client/data_manager.h"
37 #include "client/services.h"
38 #include "client/technology.h"
39 #include "client/interactive.h"
40 #include "client/monitor.h"
42 static GMainLoop *main_loop;
44 static gboolean timeout_wait(gpointer data)
48 /* Set to whatever number of retries is wanted/needed */
50 g_main_loop_quit(data);
56 static void rl_handler(char *input)
62 printf("Use ctrl-d to exit\n");
65 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
67 rl_callback_read_char();
71 int main(int argc, char *argv[])
73 DBusConnection *connection;
77 main_loop = g_main_loop_new(NULL, FALSE);
79 dbus_error_init(&err);
81 connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
83 if (dbus_error_is_set(&err)) {
84 fprintf(stderr, "Connection Error: %s\n", err.message);
85 dbus_error_free(&err);
88 if (connection == NULL) {
89 fprintf(stderr, "Could not connect to system bus...exiting\n");
98 if (strcmp(argv[1], "interactive") == 0) {
100 fprintf(stderr, "Interactive cannot accept an argument,"
104 show_interactive(connection, main_loop);
107 error = commands_no_options(connection, argv + 1, argc - 1);
109 error = commands_options(connection, argv + 1, argc - 1);
110 if (strcmp(argv[1], "monitor") != 0)
117 fprintf(stderr, "%s is not a valid command, check help.\n",
121 gchan = g_io_channel_unix_new(fileno(stdin));
122 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
123 g_io_add_watch(gchan, events, readmonitor, NULL);
124 rl_callback_handler_install("", rl_handler);
126 if (strcmp(argv[1], "monitor") != 0)
127 g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
129 g_main_loop_run(main_loop);
130 rl_callback_handler_remove();
131 g_io_channel_unref(gchan);
132 if (main_loop != NULL)
133 g_main_loop_unref(main_loop);