diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-12-30 16:53:19 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:41 +0100 |
commit | a34f51b0a5e694514a6d32dac60809303ecf9969 (patch) | |
tree | bc64542aaeedd743f539b50e2db570386ffbdc3c /cli/mmcli-modem.c | |
parent | 6002ad1b70722c1960d9ae923150aca6c4041d2c (diff) |
cli: new `--set-allowed-bands'
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r-- | cli/mmcli-modem.c | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 7b5534cf..57cf702f 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -55,6 +55,7 @@ static gchar *create_bearer_str; static gchar *delete_bearer_str; static gchar *set_allowed_modes_str; static gchar *set_preferred_mode_str; +static gchar *set_allowed_bands_str; static GOptionEntry entries[] = { { "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag, @@ -93,6 +94,10 @@ static GOptionEntry entries[] = { "Set allowed modes in a given modem.", "[MODE1|MODE2...]" }, + { "set-allowed-bands", 0, 0, G_OPTION_ARG_STRING, &set_allowed_bands_str, + "Set allowed bands in a given modem.", + "[BAND1|BAND2...]" + }, { "set-preferred-mode", 0, 0, G_OPTION_ARG_STRING, &set_preferred_mode_str, "Set preferred mode in a given modem (Must give allowed modes with --set-allowed-modes)", "[MODE]" @@ -134,7 +139,8 @@ mmcli_modem_options_enabled (void) !!delete_bearer_str + !!factory_reset_str + !!set_allowed_modes_str + - !!set_preferred_mode_str); + !!set_preferred_mode_str + + !!set_allowed_bands_str); if (n_actions == 0 && mmcli_get_common_modem_string ()) { /* default to info */ @@ -645,6 +651,50 @@ parse_modes (MMModemMode *allowed, } } +static void +set_allowed_bands_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't set allowed bands: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully set allowed bands in the modem\n"); +} + +static void +set_allowed_bands_ready (MMModem *modem, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_modem_set_allowed_bands_finish (modem, result, &error); + set_allowed_bands_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + +static void +parse_bands (MMModemBand **allowed, + guint *n_allowed) +{ + GError *error = NULL; + + mm_common_get_bands_from_string (set_allowed_bands_str, + allowed, + n_allowed, + &error); + if (error) { + g_printerr ("error: couldn't parse list of allowed bands: '%s'\n", + error->message); + exit (EXIT_FAILURE); + } +} + static void state_changed (MMModem *modem, @@ -791,6 +841,22 @@ get_modem_ready (GObject *source, return; } + /* Request to set allowed bands in a given modem? */ + if (set_allowed_bands_str) { + MMModemBand *allowed; + guint n_allowed; + + parse_bands (&allowed, &n_allowed); + mm_modem_set_allowed_bands (ctx->modem, + allowed, + n_allowed, + ctx->cancellable, + (GAsyncReadyCallback)set_allowed_bands_ready, + NULL); + g_free (allowed); + return; + } + g_warn_if_reached (); } @@ -940,5 +1006,22 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) return; } + /* Request to set allowed bands in a given modem? */ + if (set_allowed_bands_str) { + gboolean result; + MMModemBand *allowed; + guint n_allowed; + + parse_bands (&allowed, &n_allowed); + result = mm_modem_set_allowed_bands_sync (ctx->modem, + allowed, + n_allowed, + NULL, + &error); + g_free (allowed); + set_allowed_bands_process_reply (result, error); + return; + } + g_warn_if_reached (); } |