diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-25 10:41:09 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-25 11:44:18 +0200 |
commit | 75d84b7402e61f8d793f876775be9623f842d43a (patch) | |
tree | 3ee9ef10127c7c3af0708e889cbb484291ade3c5 /cli/mmcli-modem.c | |
parent | 8b863c5a4bd03a6b8ff668e25f750b51bc19ddbe (diff) |
cli: get AT command timeout directly from our default operation timeout
We remove the `--command-timeout' option, as the AT command timeout is now
directly computed from our default DBus timeout (modifiable with `--timeout').
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r-- | cli/mmcli-modem.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 63542134..3be15da2 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -51,7 +51,6 @@ static gboolean disable_flag; static gboolean reset_flag; static gchar *factory_reset_str; static gchar *command_str; -static gint command_timeout; static gboolean list_bearers_flag; static gchar *create_bearer_str; static gchar *delete_bearer_str; @@ -84,10 +83,6 @@ static GOptionEntry entries[] = { "Send an AT command to the modem", "[COMMAND]" }, - { "command-timeout", 0, 0, G_OPTION_ARG_INT, &command_timeout, - "Timeout for AT command", - "[SECONDS]" - }, { "list-bearers", 0, 0, G_OPTION_ARG_NONE, &list_bearers_flag, "List packet data bearers available in a given modem", NULL @@ -554,6 +549,21 @@ command_ready (MMModem *modem, mmcli_async_operation_done (); } +static guint +command_get_timeout (MMModem *modem) +{ + gint timeout; + + /* If --timeout was given, it should already have been set in the proxy */ + timeout = (g_dbus_proxy_get_default_timeout (G_DBUS_PROXY (modem)) / 1000) - 1; + if (timeout <= 0) { + g_printerr ("error: timeout is too short (%d)\n", timeout); + exit (EXIT_FAILURE); + } + + return (guint)timeout; +} + static void list_bearers_process_reply (GList *result, const GError *error) @@ -847,10 +857,16 @@ get_modem_ready (GObject *source, /* Request to send a command to the modem? */ if (command_str) { - g_debug ("Asynchronously sending a command to the modem..."); + guint timeout; + + timeout = command_get_timeout (ctx->modem); + + g_debug ("Asynchronously sending a command to the modem (%u seconds timeout)...", + timeout); + mm_modem_command (ctx->modem, command_str, - command_timeout ? command_timeout : 30, + timeout, ctx->cancellable, (GAsyncReadyCallback)command_ready, NULL); @@ -1028,11 +1044,16 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) /* Request to send a command to the modem? */ if (command_str) { gchar *result; + guint timeout; + + timeout = command_get_timeout (ctx->modem); + + g_debug ("Synchronously sending command to modem (%u seconds timeout)...", + timeout); - g_debug ("Synchronously sending command to modem..."); result = mm_modem_command_sync (ctx->modem, command_str, - command_timeout ? command_timeout : 30, + timeout, NULL, &error); command_process_reply (result, error); |