diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-08-17 18:26:06 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:25 +0100 |
commit | 7b0903cc57f0d67c7fac26527d3d8d3f8d66068b (patch) | |
tree | 4b4f3501a25ad50869c3b9228adc1977e869216a | |
parent | f58409e7c26a9c43010c51197150ad405bb22007 (diff) |
cli: add commands to request a new scan
-rw-r--r-- | cli/main.c | 60 |
1 files changed, 59 insertions, 1 deletions
@@ -43,6 +43,7 @@ static gboolean version_flag; static gboolean async_flag; static gboolean list_modems_flag; static gboolean monitor_modems_flag; +static gboolean scan_modems_flag; static GOptionEntry entries[] = { { "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag, @@ -61,6 +62,10 @@ static GOptionEntry entries[] = { "List available modems and monitor additions and removals", NULL }, + { "scan-modems", 's', 0, G_OPTION_ARG_NONE, &scan_modems_flag, + "Request to re-scan looking for modems", + NULL + }, { NULL } }; @@ -99,6 +104,40 @@ print_version_and_exit (void) } static void +scan_devices_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("couldn't request to scan devices: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully requested to scan devices\n"); +} + +static void +scan_devices_ready (MMManager *manager, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_manager_scan_devices_finish (manager, + result, + &error); + scan_devices_process_reply (operation_result, error); + + if (cancellable) { + g_object_unref (cancellable); + cancellable = NULL; + } + if (!keep_loop) + g_main_loop_quit (loop); +} + +static void enumerate_devices_process_reply (const GStrv paths, const GError *error) { @@ -171,6 +210,15 @@ asynchronous (MMManager *manager) /* Setup global cancellable */ cancellable = g_cancellable_new (); + /* Request to scan modems? */ + if (scan_modems_flag) { + mm_manager_scan_devices_async (manager, + cancellable, + (GAsyncReadyCallback)scan_devices_ready, + NULL); + return; + } + /* Request to monitor modems? */ if (monitor_modems_flag) { g_signal_connect (manager, @@ -200,6 +248,15 @@ synchronous (MMManager *manager) g_debug ("Running synchronous operations..."); + /* Request to scan modems? */ + if (scan_modems_flag) { + gboolean result; + + result = mm_manager_scan_devices (manager, &error); + scan_devices_process_reply (result, error); + return; + } + /* Request to list modems? */ if (list_modems_flag) { GStrv paths; @@ -216,7 +273,8 @@ ensure_single_action (void) { guint n_actions; - n_actions = (list_modems_flag + + n_actions = (scan_modems_flag + + list_modems_flag + monitor_modems_flag); if (n_actions == 0) |