aboutsummaryrefslogtreecommitdiff
path: root/src/mm-context.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2016-09-28 18:49:08 +0200
committerAleksander Morgado <aleksander@aleksander.es>2016-09-29 15:43:05 +0200
commitc4a584416ab4af81b6cae653625c78f9158de1e6 (patch)
treeb76526a1b1eed1abc11a4a740b4e7c55261be54d /src/mm-context.c
parentaa4577dfb9b5a7863a4939ec2409eae392e2fc0c (diff)
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
Diffstat (limited to 'src/mm-context.c')
-rw-r--r--src/mm-context.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/mm-context.c b/src/mm-context.c
index df8d07c7..cf8025bc 100644
--- a/src/mm-context.c
+++ b/src/mm-context.c
@@ -26,6 +26,8 @@ static const gchar *log_level;
static const gchar *log_file;
static gboolean show_ts;
static gboolean rel_ts;
+static const gchar *initial_kernel_events;
+static gboolean no_auto_scan;
static const GOptionEntry entries[] = {
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag, "Print version", NULL },
@@ -34,6 +36,8 @@ static const GOptionEntry entries[] = {
{ "log-file", 0, 0, G_OPTION_ARG_FILENAME, &log_file, "Path to log file", "[PATH]" },
{ "timestamps", 0, 0, G_OPTION_ARG_NONE, &show_ts, "Show timestamps in log output", NULL },
{ "relative-timestamps", 0, 0, G_OPTION_ARG_NONE, &rel_ts, "Use relative timestamps (from MM start)", NULL },
+ { "no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &no_auto_scan, "Don't auto-scan looking for devices", NULL },
+ { "initial-kernel-events", 0, 0, G_OPTION_ARG_FILENAME, &initial_kernel_events, "Path to initial kernel events file (requires --no-auto-scan)", "[PATH]" },
{ NULL }
};
@@ -67,17 +71,27 @@ mm_context_get_relative_timestamps (void)
return rel_ts;
}
+const gchar *
+mm_context_get_initial_kernel_events (void)
+{
+ return initial_kernel_events;
+}
+
+gboolean
+mm_context_get_no_auto_scan (void)
+{
+ return no_auto_scan;
+}
+
/*****************************************************************************/
/* Test context */
static gboolean test_session;
-static gboolean test_no_auto_scan;
static gboolean test_enable;
static gchar *test_plugin_dir;
static const GOptionEntry test_entries[] = {
{ "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session, "Run in session DBus", NULL },
- { "test-no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &test_no_auto_scan, "Don't auto-scan looking for devices", NULL },
{ "test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable, "Enable the Test interface in the daemon", NULL },
{ "test-plugin-dir", 0, 0, G_OPTION_ARG_FILENAME, &test_plugin_dir, "Path to look for plugins", "[PATH]" },
{ NULL }
@@ -104,12 +118,6 @@ mm_context_get_test_session (void)
}
gboolean
-mm_context_get_test_no_auto_scan (void)
-{
- return test_no_auto_scan;
-}
-
-gboolean
mm_context_get_test_enable (void)
{
return test_enable;
@@ -149,7 +157,7 @@ mm_context_init (gint argc,
g_option_context_add_group (ctx, test_get_option_group ());
if (!g_option_context_parse (ctx, &argc, &argv, &error)) {
- g_warning ("%s\n", error->message);
+ g_warning ("error: %s", error->message);
g_error_free (error);
exit (1);
}
@@ -166,4 +174,10 @@ mm_context_init (gint argc,
/* If just version requested, print and exit */
if (version_flag)
print_version ();
+
+ /* Initial kernel events processing may only be used if autoscan is disabled */
+ if (!no_auto_scan && initial_kernel_events) {
+ g_warning ("error: --initial-kernel-events must be used only if --no-auto-scan is also used");
+ exit (1);
+ }
}