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>
37 #include <dbus/dbus.h>
40 #include "client/data_manager.h"
41 #include "client/services.h"
42 #include "client/technology.h"
43 #include "client/interactive.h"
44 #include "client/monitor.h"
46 static GMainLoop *main_loop;
48 static gboolean timeout_wait(gpointer data)
52 /* Set to whatever number of retries is wanted/needed */
54 g_main_loop_quit(data);
60 static void rl_handler(char *input)
66 printf("Use ctrl-d to exit\n");
69 static gboolean readmonitor(GIOChannel *channel, GIOCondition condition,
71 rl_callback_read_char();
75 int main(int argc, char *argv[])
77 DBusConnection *connection;
81 main_loop = g_main_loop_new(NULL, FALSE);
83 dbus_error_init(&err);
85 connection = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, &err);
87 if (dbus_error_is_set(&err)) {
88 fprintf(stderr, "Connection Error: %s\n", err.message);
89 dbus_error_free(&err);
92 if (connection == NULL) {
93 fprintf(stderr, "Could not connect to system bus...exiting\n");
98 show_interactive(connection, main_loop);
100 error = commands_no_options(connection, argv + 1, argc - 1);
102 error = commands_options(connection, argv + 1, argc - 1);
103 if (strcmp(argv[1], "monitor") != 0)
110 fprintf(stderr, "%s is not a valid command, check help.\n",
114 gchan = g_io_channel_unix_new(fileno(stdin));
115 events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
116 g_io_add_watch(gchan, events, readmonitor, NULL);
117 rl_callback_handler_install("", rl_handler);
119 if (strcmp(argv[1], "monitor") != 0)
120 g_timeout_add_full(G_PRIORITY_DEFAULT, 100, timeout_wait,
122 g_main_loop_run(main_loop);
123 rl_callback_handler_remove();
124 g_io_channel_unref(gchan);
125 if (main_loop != NULL)
126 g_main_loop_unref(main_loop);