diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-04-25 16:49:16 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-05-03 17:08:31 +0300 |
commit | fff12a67390147487a7d3b41e7c8aa60487243ed (patch) | |
tree | 52aa328c9f09b41f948ac468caa2b9eed864a5e2 /client | |
parent | 96eeaec35d249a615537e33981151b699a64d76f (diff) | |
download | connman-fff12a67390147487a7d3b41e7c8aa60487243ed.tar.gz connman-fff12a67390147487a7d3b41e7c8aa60487243ed.tar.bz2 connman-fff12a67390147487a7d3b41e7c8aa60487243ed.zip |
client: Enable method call return to exit or continue running
Enable a client method call return function to exit or continue running when
in non-interactive mode. When a connmanctl_dbus_method_return_func_t returns
-EINPROGRESS in non-interactive mode, the command line client is kept running
even after the method call has been processed.
The command line client needs to keep running after a successful Agent
registration in order to process Agent method calls. Also enabling tethering
in non-interactive mode needs the client executing until SSID, passphrase and
tethering mode have been set.
Diffstat (limited to 'client')
-rw-r--r-- | client/commands.c | 68 | ||||
-rw-r--r-- | client/dbus_helpers.c | 5 | ||||
-rw-r--r-- | client/dbus_helpers.h | 2 |
3 files changed, 50 insertions, 25 deletions
diff --git a/client/commands.c b/client/commands.c index 692026f0..fb44545f 100644 --- a/client/commands.c +++ b/client/commands.c @@ -107,7 +107,7 @@ static int parse_args(char *arg, struct connman_option *options) return '?'; } -static void enable_return(DBusMessageIter *iter, const char *error, +static int enable_return(DBusMessageIter *iter, const char *error, void *user_data) { char *tech = user_data; @@ -125,6 +125,8 @@ static void enable_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s\n", str, error); g_free(user_data); + + return 0; } static int cmd_enable(char *args[], int num, struct connman_option *options) @@ -151,7 +153,7 @@ static int cmd_enable(char *args[], int num, struct connman_option *options) "Powered", DBUS_TYPE_BOOLEAN, &b); } -static void disable_return(DBusMessageIter *iter, const char *error, +static int disable_return(DBusMessageIter *iter, const char *error, void *user_data) { char *tech = user_data; @@ -169,6 +171,8 @@ static void disable_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s\n", str, error); g_free(user_data); + + return 0; } static int cmd_disable(char *args[], int num, struct connman_option *options) @@ -195,19 +199,21 @@ static int cmd_disable(char *args[], int num, struct connman_option *options) "Powered", DBUS_TYPE_BOOLEAN, &b); } -static void state_print(DBusMessageIter *iter, const char *error, +static int state_print(DBusMessageIter *iter, const char *error, void *user_data) { DBusMessageIter entry; if (error != NULL) { fprintf(stderr, "Error: %s", error); - return; + return 0; } dbus_message_iter_recurse(iter, &entry); __connmanctl_dbus_print(&entry, " ", " = ", "\n"); fprintf(stdout, "\n"); + + return 0; } static int cmd_state(char *args[], int num, struct connman_option *options) @@ -220,7 +226,7 @@ static int cmd_state(char *args[], int num, struct connman_option *options) state_print, NULL, DBUS_TYPE_INVALID); } -static void services_list(DBusMessageIter *iter, const char *error, +static int services_list(DBusMessageIter *iter, const char *error, void *user_data) { if (error == NULL) { @@ -229,9 +235,11 @@ static void services_list(DBusMessageIter *iter, const char *error, } else { fprintf(stderr, "Error: %s\n", error); } + + return 0; } -static void services_properties(DBusMessageIter *iter, const char *error, +static int services_properties(DBusMessageIter *iter, const char *error, void *user_data) { char *path = user_data; @@ -257,6 +265,8 @@ static void services_properties(DBusMessageIter *iter, const char *error, } g_free(user_data); + + return 0; } static int cmd_services(char *args[], int num, struct connman_option *options) @@ -296,14 +306,14 @@ static int cmd_services(char *args[], int num, struct connman_option *options) services_properties, path, DBUS_TYPE_INVALID); } -static void technology_print(DBusMessageIter *iter, const char *error, +static int technology_print(DBusMessageIter *iter, const char *error, void *user_data) { DBusMessageIter array; if (error != NULL) { fprintf(stderr, "Error: %s\n", error); - return; + return 0; } dbus_message_iter_recurse(iter, &array); @@ -323,6 +333,8 @@ static void technology_print(DBusMessageIter *iter, const char *error, dbus_message_iter_next(&array); } + + return 0; } static int cmd_technologies(char *args[], int num, @@ -341,7 +353,7 @@ struct tether_enable { dbus_bool_t enable; }; -static void tether_set_return(DBusMessageIter *iter, const char *error, +static int tether_set_return(DBusMessageIter *iter, const char *error, void *user_data) { struct tether_enable *tether = user_data; @@ -364,6 +376,8 @@ static void tether_set_return(DBusMessageIter *iter, const char *error, g_free(tether->path); g_free(user_data); + + return 0; } static int tether_set(char *technology, int set_tethering) @@ -397,20 +411,24 @@ struct tether_properties { int set_tethering; }; -static void tether_update(struct tether_properties *tether) +static int tether_update(struct tether_properties *tether) { printf("%d %d %d\n", tether->ssid_result, tether->passphrase_result, tether->set_tethering); if (tether->ssid_result == 0 && tether->passphrase_result == 0) - tether_set("wifi", tether->set_tethering); + return tether_set("wifi", tether->set_tethering); if (tether->ssid_result != -EINPROGRESS && - tether->passphrase_result != -EINPROGRESS) + tether->passphrase_result != -EINPROGRESS) { g_free(tether); + return 0; + } + + return -EINPROGRESS; } -static void tether_set_ssid_return(DBusMessageIter *iter, const char *error, +static int tether_set_ssid_return(DBusMessageIter *iter, const char *error, void *user_data) { struct tether_properties *tether = user_data; @@ -423,10 +441,10 @@ static void tether_set_ssid_return(DBusMessageIter *iter, const char *error, tether->ssid_result = -EINVAL; } - tether_update(tether); + return tether_update(tether); } -static void tether_set_passphrase_return(DBusMessageIter *iter, +static int tether_set_passphrase_return(DBusMessageIter *iter, const char *error, void *user_data) { struct tether_properties *tether = user_data; @@ -439,7 +457,7 @@ static void tether_set_passphrase_return(DBusMessageIter *iter, tether->passphrase_result = -EINVAL; } - tether_update(tether); + return tether_update(tether); } static int tether_set_ssid(char *ssid, char *passphrase, int set_tethering) @@ -506,7 +524,7 @@ static int cmd_tether(char *args[], int num, struct connman_option *options) return tether_set(args[1], set_tethering); } -static void scan_return(DBusMessageIter *iter, const char *error, +static int scan_return(DBusMessageIter *iter, const char *error, void *user_data) { char *path = user_data; @@ -519,6 +537,8 @@ static void scan_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s", path, error); g_free(user_data); + + return 0; } static int cmd_scan(char *args[], int num, struct connman_option *options) @@ -537,7 +557,7 @@ static int cmd_scan(char *args[], int num, struct connman_option *options) scan_return, path, DBUS_TYPE_INVALID); } -static void connect_return(DBusMessageIter *iter, const char *error, +static int connect_return(DBusMessageIter *iter, const char *error, void *user_data) { char *path = user_data; @@ -550,6 +570,8 @@ static void connect_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s\n", path, error); g_free(user_data); + + return 0; } static int cmd_connect(char *args[], int num, struct connman_option *options) @@ -568,7 +590,7 @@ static int cmd_connect(char *args[], int num, struct connman_option *options) connect_return, path, DBUS_TYPE_INVALID); } -static void disconnect_return(DBusMessageIter *iter, const char *error, +static int disconnect_return(DBusMessageIter *iter, const char *error, void *user_data) { char *path = user_data; @@ -581,6 +603,8 @@ static void disconnect_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s\n", path, error); g_free(user_data); + + return 0; } static int cmd_disconnect(char *args[], int num, struct connman_option *options) @@ -597,11 +621,9 @@ static int cmd_disconnect(char *args[], int num, struct connman_option *options) return __connmanctl_dbus_method_call(connection, path, "net.connman.Service", "Disconnect", disconnect_return, path, DBUS_TYPE_INVALID); - - return 0; } -static void config_return(DBusMessageIter *iter, const char *error, +static int config_return(DBusMessageIter *iter, const char *error, void *user_data) { char *service_name = user_data; @@ -610,6 +632,8 @@ static void config_return(DBusMessageIter *iter, const char *error, fprintf(stderr, "Error %s: %s\n", service_name, error); g_free(user_data); + + return 0; } struct config_append { diff --git a/client/dbus_helpers.c b/client/dbus_helpers.c index 9c0e1eb2..a3e08433 100644 --- a/client/dbus_helpers.c +++ b/client/dbus_helpers.c @@ -127,6 +127,7 @@ struct dbus_callback { static void dbus_method_reply(DBusPendingCall *call, void *user_data) { struct dbus_callback *callback = user_data; + int res = 0; DBusMessage *reply; DBusMessageIter iter; @@ -146,11 +147,11 @@ static void dbus_method_reply(DBusPendingCall *call, void *user_data) } dbus_message_iter_init(reply, &iter); - callback->cb(&iter, NULL, callback->user_data); + res = callback->cb(&iter, NULL, callback->user_data); end: __connmanctl_redraw_rl(); - if (__connmanctl_is_interactive() == false) + if (__connmanctl_is_interactive() == false && res != -EINPROGRESS) __connmanctl_quit(); g_free(callback); diff --git a/client/dbus_helpers.h b/client/dbus_helpers.h index 7956a05c..fde11837 100644 --- a/client/dbus_helpers.h +++ b/client/dbus_helpers.h @@ -32,7 +32,7 @@ extern "C" { void __connmanctl_dbus_print(DBusMessageIter *iter, const char *pre, const char *dict, const char *sep); -typedef void (*connmanctl_dbus_method_return_func_t)(DBusMessageIter *iter, +typedef int (*connmanctl_dbus_method_return_func_t)(DBusMessageIter *iter, const char *error, void *user_data); int __connmanctl_dbus_method_call(DBusConnection *connection, const char *path, const char *interface, const char *method, |