diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-08-20 15:16:32 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:26 +0100 |
commit | 6221e4f76b5a0edfa253493635a64f971916f9ba (patch) | |
tree | c0377d11f0b060c57e2bee31e3efe06c931abf08 /cli/mmcli-modem.c | |
parent | e341c7ff49ffff5a2986a56e105c01b86b6f6478 (diff) |
cli: add command to reset the modem
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r-- | cli/mmcli-modem.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c index 5ff787b2..ca589091 100644 --- a/cli/mmcli-modem.c +++ b/cli/mmcli-modem.c @@ -40,6 +40,7 @@ typedef struct { gboolean monitor_state_flag; gboolean enable_flag; gboolean disable_flag; + gboolean reset_flag; /* The modem proxy */ MMModem *modem; } Context; @@ -66,6 +67,10 @@ static GOptionEntry entries[] = { "Disable a given modem", NULL }, + { "reset", 'r', 0, G_OPTION_ARG_NONE, &ctxt.reset_flag, + "Reset a given modem", + NULL + }, { NULL } }; @@ -93,7 +98,8 @@ mmcli_modem_options_enabled (void) n_actions = (ctxt.info_flag + ctxt.monitor_state_flag + ctxt.enable_flag + - ctxt.disable_flag); + ctxt.disable_flag + + ctxt.reset_flag); if (n_actions > 1) { g_printerr ("error: too many modem actions requested\n"); @@ -451,6 +457,35 @@ disable_ready (MMModem *modem, } static void +reset_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't reset the modem: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully reseted the modem\n"); +} + +static void +reset_ready (MMModem *modem, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_modem_reset_finish (modem, + result, + &error); + reset_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + +static void state_changed (MMModem *modem, MMModemState old_state, MMModemState new_state, @@ -513,6 +548,15 @@ mmcli_modem_run_asynchronous (GDBusConnection *connection, return FALSE; } + /* Request to reset the modem? */ + if (ctxt.reset_flag) { + mm_modem_reset_async (ctxt.modem, + cancellable, + (GAsyncReadyCallback)reset_ready, + NULL); + return FALSE; + } + g_warn_if_reached (); return FALSE; } @@ -572,5 +616,15 @@ mmcli_modem_run_synchronous (GDBusConnection *connection) return; } + /* Request to reset the modem? */ + if (ctxt.reset_flag) { + gboolean result; + + result = mm_modem_reset (ctxt.modem, &error); + reset_process_reply (result, error); + return; + } + g_warn_if_reached (); } + |