summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2018-12-17 14:10:26 +0100
committerAleksander Morgado <aleksander@gnu.org>2019-01-03 19:48:25 +0000
commit0c8a612535ac7320929c5f9c2fd070a5a635017c (patch)
tree86217c31d7146739cb743bf762cc740618643888
parent76771042045198c94e40b9f4744b847eadc8a55a (diff)
downloadModemManager-aleksander/inhibit.tar.gz
mmcli,modem: new `--inhibit` action on the modem objectaleksander/inhibit
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'
-rw-r--r--cli/mmcli-modem.c63
1 files changed, 60 insertions, 3 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
index 3729b6441..2b7e3569b 100644
--- a/cli/mmcli-modem.c
+++ b/cli/mmcli-modem.c
@@ -63,6 +63,7 @@ static gchar *set_current_capabilities_str;
static gchar *set_allowed_modes_str;
static gchar *set_preferred_mode_str;
static gchar *set_current_bands_str;
+static gboolean inhibit_flag;
static GOptionEntry entries[] = {
{ "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.",
"[BAND1|BAND2...]"
},
+ { "inhibit", 0, 0, G_OPTION_ARG_NONE, &inhibit_flag,
+ "Inhibit the modem",
+ NULL
+ },
{ NULL }
};
@@ -167,7 +172,8 @@ mmcli_modem_options_enabled (void)
!!set_current_capabilities_str +
!!set_allowed_modes_str +
!!set_preferred_mode_str +
- !!set_current_bands_str);
+ !!set_current_bands_str +
+ inhibit_flag);
if (n_actions == 0 && mmcli_get_common_modem_string ()) {
/* default to info */
@@ -188,7 +194,7 @@ mmcli_modem_options_enabled (void)
exit (EXIT_FAILURE);
}
- if (monitor_state_flag)
+ if (monitor_state_flag || inhibit_flag)
mmcli_force_async_operation ();
if (info_flag)
@@ -228,6 +234,42 @@ mmcli_modem_shutdown (void)
}
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
cancelled (GCancellable *cancellable)
{
mmcli_async_operation_done ();
@@ -1068,6 +1110,21 @@ get_modem_ready (GObject *source,
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 ();
}
@@ -1094,7 +1151,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
{
GError *error = NULL;
- if (monitor_state_flag)
+ if (monitor_state_flag || inhibit_flag)
g_assert_not_reached ();
/* Initialize context */