cli: add command to reset the modem
This commit is contained in:
@@ -40,6 +40,7 @@ typedef struct {
|
|||||||
gboolean monitor_state_flag;
|
gboolean monitor_state_flag;
|
||||||
gboolean enable_flag;
|
gboolean enable_flag;
|
||||||
gboolean disable_flag;
|
gboolean disable_flag;
|
||||||
|
gboolean reset_flag;
|
||||||
/* The modem proxy */
|
/* The modem proxy */
|
||||||
MMModem *modem;
|
MMModem *modem;
|
||||||
} Context;
|
} Context;
|
||||||
@@ -66,6 +67,10 @@ static GOptionEntry entries[] = {
|
|||||||
"Disable a given modem",
|
"Disable a given modem",
|
||||||
NULL
|
NULL
|
||||||
},
|
},
|
||||||
|
{ "reset", 'r', 0, G_OPTION_ARG_NONE, &ctxt.reset_flag,
|
||||||
|
"Reset a given modem",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,7 +98,8 @@ mmcli_modem_options_enabled (void)
|
|||||||
n_actions = (ctxt.info_flag +
|
n_actions = (ctxt.info_flag +
|
||||||
ctxt.monitor_state_flag +
|
ctxt.monitor_state_flag +
|
||||||
ctxt.enable_flag +
|
ctxt.enable_flag +
|
||||||
ctxt.disable_flag);
|
ctxt.disable_flag +
|
||||||
|
ctxt.reset_flag);
|
||||||
|
|
||||||
if (n_actions > 1) {
|
if (n_actions > 1) {
|
||||||
g_printerr ("error: too many modem actions requested\n");
|
g_printerr ("error: too many modem actions requested\n");
|
||||||
@@ -450,6 +456,35 @@ disable_ready (MMModem *modem,
|
|||||||
mmcli_async_operation_done ();
|
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
|
static void
|
||||||
state_changed (MMModem *modem,
|
state_changed (MMModem *modem,
|
||||||
MMModemState old_state,
|
MMModemState old_state,
|
||||||
@@ -513,6 +548,15 @@ mmcli_modem_run_asynchronous (GDBusConnection *connection,
|
|||||||
return FALSE;
|
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 ();
|
g_warn_if_reached ();
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -572,5 +616,15 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
return;
|
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 ();
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user