mmcli,modem: new --inhibit
action on the modem object
Modem device inhibition is really a manager action for which we provide the full modem device 'uid'. This new operation allows to perform device inhibition using the modem object as reference, which is more handy than first looking at the device 'uid' and then running the manager action. $ sudo mmcli -m 0 --inhibit successfully inhibited device with uid '/sys/devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12.2' type Ctrl+C to abort this program and remove the inhibition ^C cancelling the operation... successfully uninhibited device with uid '/sys/devices/pci0000:00/0000:00:14.0/usb1/1-12/1-12.2'
This commit is contained in:
@@ -63,6 +63,7 @@ static gchar *set_current_capabilities_str;
|
|||||||
static gchar *set_allowed_modes_str;
|
static gchar *set_allowed_modes_str;
|
||||||
static gchar *set_preferred_mode_str;
|
static gchar *set_preferred_mode_str;
|
||||||
static gchar *set_current_bands_str;
|
static gchar *set_current_bands_str;
|
||||||
|
static gboolean inhibit_flag;
|
||||||
|
|
||||||
static GOptionEntry entries[] = {
|
static GOptionEntry entries[] = {
|
||||||
{ "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag,
|
{ "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag,
|
||||||
@@ -125,6 +126,10 @@ static GOptionEntry entries[] = {
|
|||||||
"Set bands to be used by a given modem.",
|
"Set bands to be used by a given modem.",
|
||||||
"[BAND1|BAND2...]"
|
"[BAND1|BAND2...]"
|
||||||
},
|
},
|
||||||
|
{ "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag,
|
||||||
|
"Inhibit the modem",
|
||||||
|
NULL
|
||||||
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -167,7 +172,8 @@ mmcli_modem_options_enabled (void)
|
|||||||
!!set_current_capabilities_str +
|
!!set_current_capabilities_str +
|
||||||
!!set_allowed_modes_str +
|
!!set_allowed_modes_str +
|
||||||
!!set_preferred_mode_str +
|
!!set_preferred_mode_str +
|
||||||
!!set_current_bands_str);
|
!!set_current_bands_str +
|
||||||
|
inhibit_flag);
|
||||||
|
|
||||||
if (n_actions == 0 && mmcli_get_common_modem_string ()) {
|
if (n_actions == 0 && mmcli_get_common_modem_string ()) {
|
||||||
/* default to info */
|
/* default to info */
|
||||||
@@ -188,7 +194,7 @@ mmcli_modem_options_enabled (void)
|
|||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monitor_state_flag)
|
if (monitor_state_flag || inhibit_flag)
|
||||||
mmcli_force_async_operation ();
|
mmcli_force_async_operation ();
|
||||||
|
|
||||||
if (info_flag)
|
if (info_flag)
|
||||||
@@ -227,6 +233,42 @@ mmcli_modem_shutdown (void)
|
|||||||
context_free (ctx);
|
context_free (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
inhibition_cancelled (GCancellable *cancellable,
|
||||||
|
const gchar *uid)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_manager_uninhibit_device_sync (ctx->manager, uid, NULL, &error)) {
|
||||||
|
g_printerr ("error: couldn't uninhibit device: '%s'\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
} else
|
||||||
|
g_print ("successfully uninhibited device with uid '%s'\n", uid);
|
||||||
|
|
||||||
|
mmcli_async_operation_done ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
inhibit_device_ready (MMManager *manager,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gchar *uid)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
|
if (!mm_manager_inhibit_device_finish (manager, result, &error)) {
|
||||||
|
g_printerr ("error: couldn't inhibit device: '%s'\n",
|
||||||
|
error ? error->message : "unknown error");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print ("successfully inhibited device with uid '%s'\n", uid);
|
||||||
|
g_print ("type Ctrl+C to abort this program and remove the inhibition\n");
|
||||||
|
|
||||||
|
g_cancellable_connect (ctx->cancellable,
|
||||||
|
G_CALLBACK (inhibition_cancelled),
|
||||||
|
uid, g_free);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cancelled (GCancellable *cancellable)
|
cancelled (GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
@@ -1068,6 +1110,21 @@ get_modem_ready (GObject *source,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Request to inhibit the modem? */
|
||||||
|
if (inhibit_flag) {
|
||||||
|
gchar *uid;
|
||||||
|
|
||||||
|
g_debug ("Asynchronously inhibiting modem...");
|
||||||
|
uid = mm_modem_dup_device (ctx->modem);
|
||||||
|
|
||||||
|
mm_manager_inhibit_device (ctx->manager,
|
||||||
|
uid,
|
||||||
|
ctx->cancellable,
|
||||||
|
(GAsyncReadyCallback)inhibit_device_ready,
|
||||||
|
uid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
g_warn_if_reached ();
|
g_warn_if_reached ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1094,7 +1151,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (monitor_state_flag)
|
if (monitor_state_flag || inhibit_flag)
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
|
|
||||||
/* Initialize context */
|
/* Initialize context */
|
||||||
|
Reference in New Issue
Block a user