From c4a584416ab4af81b6cae653625c78f9158de1e6 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 28 Sep 2016 18:49:08 +0200 Subject: core: allow disabling auto-scan and notifying ports one by one via API This commit enables a new core ModemManager daemon option, so that automatic detection of available modems is totally disabled: '--no-auto-scan'. Note that this option also replaces the previously used '--test-no-auto-scan' option, which was only used during tests. Along with the new ModemManager option, a new ReportKernelEvent() method in the API is defined, which allows notifying the daemon of which interfaces it should be accessing, as well as the main details of each interface. The only mandatory parameters in the new method are 'action' (add/remove), 'name' (the name of the interface) and 'subsystem' (the subsystem of the interface). The mmcli tool has support for using the new api method via several new options: * The '--report-kernel-event' option allows specifying device ports one by one, and is a direct mapping of the ReportKernelEvent() method: $ sudo mmcli --report-kernel-event="action=add,name=wwan0,subsystem=net" $ sudo mmcli --report-kernel-event="action=add,name=cdc-wdm0,subsystem=usbmisc" * The '--report-kernel-event-auto-scan' option uses udev monitoring to notify events automatically to the daemon. This allows to operate in a way equivalent to the default daemon operation (with implicit auto-scan). Worth noting that the ReportKernelEvent() method is only usable when '--no-auto-scan' is explicitly used in the daemon. An error will be reported if the method is tried while standard udev monitoring is enabled (implicit if auto scan isn't explicitly disabled in the daemon). If mmcli is going to be used only to report 'real time' events, an optional '--initial-kernel-events=[PATH]' may be given in the ModemManager call to automatically process a set of port kernel events one by one on boot. The file may e.g. contain: action=add,name=wwan0,subsystem=net action=add,name=cdc-wdm0,subsystem=usbmisc --- libmm-glib/mm-manager.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) (limited to 'libmm-glib/mm-manager.c') diff --git a/libmm-glib/mm-manager.c b/libmm-glib/mm-manager.c index cb196b3f..6a9ce5dd 100644 --- a/libmm-glib/mm-manager.c +++ b/libmm-glib/mm-manager.c @@ -497,6 +497,130 @@ mm_manager_scan_devices_sync (MMManager *manager, /*****************************************************************************/ +/** + * mm_manager_report_kernel_event_finish: + * @manager: A #MMManager. + * @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_manager_report_kernel_event(). + * @error: Return location for error or %NULL. + * + * Finishes an operation started with mm_manager_report_kernel_event(). + * + * Returns: %TRUE if the operation succeded, %FALSE if @error is set. + */ +gboolean +mm_manager_report_kernel_event_finish (MMManager *manager, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_boolean (G_TASK (res), error); +} + +static void +report_kernel_event_ready (MmGdbusOrgFreedesktopModemManager1 *manager_iface_proxy, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!mm_gdbus_org_freedesktop_modem_manager1_call_report_kernel_event_finish ( + manager_iface_proxy, + res, + &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +/** + * mm_manager_report_kernel_event: + * @manager: A #MMManager. + * @properties: the properties of the kernel event. + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. + * @user_data: User data to pass to @callback. + * + * Asynchronously report kernel event. + * + * When the operation is finished, @callback will be invoked in the + * thread-default main loop + * of the thread you are calling this method from. You can then call + * mm_manager_report_kernel_event_finish() to get the result of the operation. + * + * See mm_manager_report_kernel_event_sync() for the synchronous, blocking version of this method. + */ +void +mm_manager_report_kernel_event (MMManager *manager, + MMKernelEventProperties *properties, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + GError *inner_error = NULL; + GVariant *dictionary; + + g_return_if_fail (MM_IS_MANAGER (manager)); + + task = g_task_new (manager, cancellable, callback, user_data); + + if (!ensure_modem_manager1_proxy (manager, &inner_error)) { + g_task_return_error (task, inner_error); + g_object_unref (task); + return; + } + + dictionary = mm_kernel_event_properties_get_dictionary (properties); + mm_gdbus_org_freedesktop_modem_manager1_call_report_kernel_event ( + manager->priv->manager_iface_proxy, + dictionary, + cancellable, + (GAsyncReadyCallback)report_kernel_event_ready, + task); + g_variant_unref (dictionary); +} + +/** + * mm_manager_report_kernel_event_sync: + * @manager: A #MMManager. + * @properties: the properties of the kernel event. + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @error: Return location for error or %NULL. + * + * Synchronously report kernel event. + * + * The calling thread is blocked until a reply is received. + * + * See mm_manager_report_kernel_event() for the asynchronous version of this method. + * + * Returns: %TRUE if the operation succeded, %FALSE if @error is set. + */ +gboolean +mm_manager_report_kernel_event_sync (MMManager *manager, + MMKernelEventProperties *properties, + GCancellable *cancellable, + GError **error) +{ + GVariant *dictionary; + gboolean result; + + g_return_val_if_fail (MM_IS_MANAGER (manager), FALSE); + + if (!ensure_modem_manager1_proxy (manager, error)) + return FALSE; + + dictionary = mm_kernel_event_properties_get_dictionary (properties); + result = (mm_gdbus_org_freedesktop_modem_manager1_call_report_kernel_event_sync ( + manager->priv->manager_iface_proxy, + dictionary, + cancellable, + error)); + g_variant_unref (dictionary); + return result; +} + +/*****************************************************************************/ + static void register_dbus_errors (void) { -- cgit v1.2.3-70-g09d2