From 6221e4f76b5a0edfa253493635a64f971916f9ba Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 20 Aug 2011 15:16:32 +0200 Subject: cli: add command to reset the modem --- cli/mmcli-modem.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'cli/mmcli-modem.c') 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"); @@ -450,6 +456,35 @@ disable_ready (MMModem *modem, mmcli_async_operation_done (); } +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, @@ -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 (); } + -- cgit v1.2.3-70-g09d2