aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-12-09 17:58:20 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:33 +0100
commit62469445101babdff53d238e602d7e988dbaa0cb (patch)
treea829194c8618a15607714482851234de975ab945 /cli/mmcli.c
parentec8da67921c648dbe2e3b82c2392f7196229c914 (diff)
cli: allow option groups to force async/sync operations
Some operations are clearly asynchronous (e.g. monitoring modem state), while others are clearly synchronous (e.g. printing modem info). So just allow option groups to force the operation to be async or sync based on the detected action.
Diffstat (limited to 'cli/mmcli.c')
-rw-r--r--cli/mmcli.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/cli/mmcli.c b/cli/mmcli.c
index 7fee76f2..d51af868 100644
--- a/cli/mmcli.c
+++ b/cli/mmcli.c
@@ -144,6 +144,24 @@ mmcli_async_operation_done (void)
g_main_loop_quit (loop);
}
+void
+mmcli_force_async_operation (void)
+{
+ if (!async_flag) {
+ g_debug ("Forcing request to be run asynchronously");
+ async_flag = TRUE;
+ }
+}
+
+void
+mmcli_force_sync_operation (void)
+{
+ if (async_flag) {
+ g_debug ("Ignoring request to run asynchronously");
+ async_flag = FALSE;
+ }
+}
+
gint
main (gint argc, gchar **argv)
{
@@ -184,12 +202,9 @@ main (gint argc, gchar **argv)
exit (EXIT_FAILURE);
}
- /* Setup context for asynchronous operations */
- if (async_flag) {
- g_debug ("Running asynchronous operations...");
- loop = g_main_loop_new (NULL, FALSE);
- cancellable = g_cancellable_new ();
- }
+ /* Create requirements for async options */
+ cancellable = g_cancellable_new ();
+ loop = g_main_loop_new (NULL, FALSE);
/* Manager options? */
if (mmcli_manager_options_enabled ()) {
@@ -219,12 +234,8 @@ main (gint argc, gchar **argv)
}
/* Run loop only in async operations */
- if (async_flag) {
+ if (async_flag)
g_main_loop_run (loop);
- if (cancellable)
- g_object_unref (cancellable);
- g_main_loop_unref (loop);
- }
if (mmcli_manager_options_enabled ()) {
mmcli_manager_shutdown ();
@@ -232,6 +243,8 @@ main (gint argc, gchar **argv)
mmcli_modem_shutdown ();
}
+ g_object_unref (cancellable);
+ g_main_loop_unref (loop);
g_object_unref (connection);
return EXIT_SUCCESS;