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 (); } diff --git a/docs/reference/libmm-glib/libmm-glib-sections.txt b/docs/reference/libmm-glib/libmm-glib-sections.txt index 08c58973..41f3b0d6 100644 --- a/docs/reference/libmm-glib/libmm-glib-sections.txt +++ b/docs/reference/libmm-glib/libmm-glib-sections.txt @@ -18,6 +18,12 @@ mm_manager_get_version mm_manager_scan_devices mm_manager_scan_devices_finish mm_manager_scan_devices_sync +mm_manager_inhibit_device +mm_manager_inhibit_device_finish +mm_manager_inhibit_device_sync +mm_manager_uninhibit_device +mm_manager_uninhibit_device_finish +mm_manager_uninhibit_device_sync mm_manager_set_logging mm_manager_set_logging_finish mm_manager_set_logging_sync @@ -1731,6 +1737,9 @@ mm_gdbus_org_freedesktop_modem_manager1_get_version mm_gdbus_org_freedesktop_modem_manager1_call_scan_devices mm_gdbus_org_freedesktop_modem_manager1_call_scan_devices_finish mm_gdbus_org_freedesktop_modem_manager1_call_scan_devices_sync +mm_gdbus_org_freedesktop_modem_manager1_call_inhibit_device +mm_gdbus_org_freedesktop_modem_manager1_call_inhibit_device_finish +mm_gdbus_org_freedesktop_modem_manager1_call_inhibit_device_sync mm_gdbus_org_freedesktop_modem_manager1_call_set_logging mm_gdbus_org_freedesktop_modem_manager1_call_set_logging_finish mm_gdbus_org_freedesktop_modem_manager1_call_set_logging_sync @@ -1740,6 +1749,7 @@ mm_gdbus_org_freedesktop_modem_manager1_call_report_kernel_event_sync mm_gdbus_org_freedesktop_modem_manager1_set_version mm_gdbus_org_freedesktop_modem_manager1_override_properties +mm_gdbus_org_freedesktop_modem_manager1_complete_inhibit_device mm_gdbus_org_freedesktop_modem_manager1_complete_scan_devices mm_gdbus_org_freedesktop_modem_manager1_complete_set_logging mm_gdbus_org_freedesktop_modem_manager1_complete_report_kernel_event diff --git a/introspection/org.freedesktop.ModemManager1.xml b/introspection/org.freedesktop.ModemManager1.xml index 4d7a4e84..85b62134 100644 --- a/introspection/org.freedesktop.ModemManager1.xml +++ b/introspection/org.freedesktop.ModemManager1.xml @@ -106,6 +106,27 @@ + + + + + +