From 2212d3e054fbe218c64fa76eeac8480f82d9f623 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 7 Dec 2018 16:12:35 +0100 Subject: api,manager: new InhibitDevice() method This new method allows users of the ModemManager API to take full control of a given device. Unlike other operations in the API, the inhibition is maintained as long as the caller exists in the bus, or until the same caller uninhibits the device. https://gitlab.freedesktop.org/mobile-broadband/ModemManager/issues/98 --- cli/mmcli-manager.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'cli/mmcli-manager.c') diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c index 810b0aa3..dac107c9 100644 --- a/cli/mmcli-manager.c +++ b/cli/mmcli-manager.c @@ -56,6 +56,7 @@ static gboolean list_modems_flag; static gboolean monitor_modems_flag; static gboolean scan_modems_flag; static gchar *set_logging_str; +static gchar *inhibit_device_str; static gchar *report_kernel_event_str; #if defined WITH_UDEV @@ -83,6 +84,10 @@ static GOptionEntry entries[] = { "Request to re-scan looking for modems", NULL }, + { "inhibit-device", 'I', 0, G_OPTION_ARG_STRING, &inhibit_device_str, + "Inhibit device given a unique device identifier", + "[UID]" + }, { "report-kernel-event", 'K', 0, G_OPTION_ARG_STRING, &report_kernel_event_str, "Report kernel event", "[\"key=value,...\"]" @@ -126,6 +131,7 @@ mmcli_manager_options_enabled (void) monitor_modems_flag + scan_modems_flag + !!set_logging_str + + !!inhibit_device_str + !!report_kernel_event_str); #if defined WITH_UDEV @@ -145,7 +151,8 @@ mmcli_manager_options_enabled (void) exit (EXIT_FAILURE); } mmcli_force_async_operation (); - } + } else if (inhibit_device_str) + mmcli_force_async_operation (); #if defined WITH_UDEV if (report_kernel_event_auto_scan) @@ -180,6 +187,41 @@ mmcli_manager_shutdown (void) context_free (ctx); } +static void +inhibition_cancelled (GCancellable *cancellable) +{ + GError *error = NULL; + + if (!mm_manager_uninhibit_device_sync (ctx->manager, inhibit_device_str, 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", inhibit_device_str); + + mmcli_async_operation_done (); +} + +static void +inhibit_device_ready (MMManager *manager, + GAsyncResult *result) +{ + 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", inhibit_device_str); + g_print ("type Ctrl+C to abort this program and remove the inhibition\n"); + + g_cancellable_connect (ctx->cancellable, + G_CALLBACK (inhibition_cancelled), + NULL, + NULL); +} + static void report_kernel_event_process_reply (gboolean result, const GError *error) @@ -463,6 +505,16 @@ get_manager_ready (GObject *source, return; } + /* Request to inhibit device? */ + if (inhibit_device_str) { + mm_manager_inhibit_device (ctx->manager, + inhibit_device_str, + ctx->cancellable, + (GAsyncReadyCallback)inhibit_device_ready, + NULL); + return; + } + g_warn_if_reached (); } -- cgit v1.2.3-70-g09d2