summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-12 13:55:34 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-21 16:22:18 +0200
commit6a07479b9eac213c707e04cdf090f1fdb14e16a0 (patch)
tree2c6d7583148ad047c511d205e7080b8bb9f0d857 /client
parent56687906c9ac83c0480175b0354f7582a03a685d (diff)
downloadconnman-6a07479b9eac213c707e04cdf090f1fdb14e16a0.tar.gz
connman-6a07479b9eac213c707e04cdf090f1fdb14e16a0.tar.bz2
connman-6a07479b9eac213c707e04cdf090f1fdb14e16a0.zip
client: Create prototypes for all commands
Provide the infrastructure to factor out the commands.
Diffstat (limited to 'client')
-rw-r--r--client/commands.c114
-rw-r--r--client/interactive.c15
-rw-r--r--client/interactive.h1
-rw-r--r--client/main.c14
4 files changed, 133 insertions, 11 deletions
diff --git a/client/commands.c b/client/commands.c
index 75856cd2..cbc440fc 100644
--- a/client/commands.c
+++ b/client/commands.c
@@ -64,6 +64,8 @@ static char *proxy_simple[] = {
NULL
};
+static int cmd_help(char *args[], int num, struct option *options);
+
void show_help(void)
{
printf("Usage: connmanctl <command> [args]\n"
@@ -278,6 +280,118 @@ int monitor_switch(int argc, char *argv[], int c, DBusConnection *conn)
return 0;
}
+static int cmd_enable(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_disable(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_state(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_services(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_technologies(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_scan(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_connect(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_disconnect(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_config(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_monitor(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+static int cmd_exit(char *args[], int num, struct option *options)
+{
+ return 0;
+}
+
+static const struct {
+ const char *cmd;
+ const char *argument;
+ struct option *options;
+ const char **options_desc;
+ int (*func) (char *args[], int num, struct option *options);
+ const char *desc;
+} cmd_table[] = {
+ { "enable", "<technology>|offline", NULL, NULL,
+ cmd_enable, "Enables given technology or offline mode" },
+ { "disable", "<technology>|offline", NULL, NULL,
+ cmd_disable, "Disables given technology or offline mode"},
+ { "state", NULL, NULL, NULL,
+ cmd_state, "Shows if the system is online or offline" },
+ { "services", NULL, NULL, NULL,
+ cmd_services, "Display services" },
+ { "technologies", NULL, NULL, NULL,
+ cmd_technologies, "Display technologies" },
+ { "scan", "<technology>", NULL, NULL,
+ cmd_scan, "Scans for new services for given technology" },
+ { "connect", "<service>", NULL, NULL,
+ cmd_connect, "Connect a given service" },
+ { "disconnect", "<service>", NULL, NULL,
+ cmd_disconnect, "Disconnect a given service" },
+ { "config", "<service>", NULL, NULL,
+ cmd_config, "Set service configuration options" },
+ { "monitor", NULL, NULL, NULL,
+ cmd_monitor, "Monitor signals from interfaces" },
+ { "help", NULL, NULL, NULL,
+ cmd_help, "Show help" },
+ { "exit", NULL, NULL, NULL,
+ cmd_exit, "Exit" },
+ { "quit", NULL, NULL, NULL,
+ cmd_exit, "Quit" },
+ { NULL, },
+};
+
+static int cmd_help(char *args[], int num, struct option *options)
+{
+ return -1;
+}
+
+int commands(DBusConnection *connection, char *argv[], int argc)
+{
+ int i;
+
+ for (i = 0; cmd_table[i].cmd != NULL; i++) {
+ if (g_strcmp0(cmd_table[i].cmd, argv[0]) == 0 &&
+ cmd_table[i].func != NULL) {
+ return cmd_table[i].func(argv, argc,
+ cmd_table[i].options);
+ }
+ }
+
+ return -1;
+}
+
int commands_no_options(DBusConnection *connection, char *argv[], int argc)
{
DBusMessage *message = NULL;
diff --git a/client/interactive.c b/client/interactive.c
index d2c4f794..5f9c77a5 100644
--- a/client/interactive.c
+++ b/client/interactive.c
@@ -87,13 +87,16 @@ static gboolean rl_handler(char *input)
free(input);
exit(EXIT_FAILURE);
} else {
- error = commands_no_options(interactive_conn,
+ error = commands(interactive_conn, long_args, num_args);
+ if (error == -1) {
+ error = commands_no_options(interactive_conn,
+ long_args, num_args);
+ if (error == -1)
+ error = commands_options(interactive_conn,
long_args, num_args);
- if (error == -1)
- error = commands_options(interactive_conn, long_args,
- num_args);
- else
- return error;
+ else
+ return error;
+ }
}
if ((strcmp(long_args[0], "quit") == 0)
|| (strcmp(long_args[0], "exit") == 0)
diff --git a/client/interactive.h b/client/interactive.h
index a2bd0510..a09aca31 100644
--- a/client/interactive.h
+++ b/client/interactive.h
@@ -23,6 +23,7 @@
#include <dbus/dbus.h>
void show_interactive(DBusConnection *connection, GMainLoop *mainloop);
+int commands(DBusConnection *connection, char *argv[], int argc);
int commands_no_options(DBusConnection *connection, char *argv[], int argc);
int commands_options(DBusConnection *connection, char *argv[], int argc);
void show_help(void);
diff --git a/client/main.c b/client/main.c
index ab642772..d54d1488 100644
--- a/client/main.c
+++ b/client/main.c
@@ -95,13 +95,17 @@ int main(int argc, char *argv[])
if (argc < 2)
show_interactive(connection, main_loop);
- error = commands_no_options(connection, argv + 1, argc - 1);
+ error = commands(connection, argv + 1, argc -1);
if (error == -1) {
- error = commands_options(connection, argv + 1, argc - 1);
- if (strcmp(argv[1], "monitor") != 0)
+ error = commands_no_options(connection, argv + 1, argc - 1);
+ if (error == -1) {
+ error = commands_options(connection, argv + 1,
+ argc - 1);
+ if (strcmp(argv[1], "monitor") != 0)
+ return error;
+ } else {
return error;
- } else {
- return error;
+ }
}
if (error == -1) {