From 0cdb293452cb62830326e465e521830914b705bf Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 27 Dec 2011 16:35:49 +0100 Subject: cli: new `simple-disconnect' command This command doesn't expect any argument, it will disconnect all available bearers. You can disconnect specific bearers using `--bearer' and `--disconnect'. --- cli/mmcli-modem-simple.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) (limited to 'cli/mmcli-modem-simple.c') diff --git a/cli/mmcli-modem-simple.c b/cli/mmcli-modem-simple.c index a8adb457..63299228 100644 --- a/cli/mmcli-modem-simple.c +++ b/cli/mmcli-modem-simple.c @@ -44,12 +44,17 @@ static Context *ctx; /* Options */ static gchar *connect_str; +static gboolean disconnect_flag; static GOptionEntry entries[] = { { "simple-connect", 0, 0, G_OPTION_ARG_STRING, &connect_str, "Run full connection sequence.", "[\"key=value,...\"]" }, + { "simple-disconnect", 0, 0, G_OPTION_ARG_NONE, &disconnect_flag, + "Disconnect all connected bearers.", + NULL + }, { NULL } }; @@ -77,7 +82,8 @@ mmcli_modem_simple_options_enabled (void) if (checked) return !!n_actions; - n_actions = (!!connect_str); + n_actions = (!!connect_str + + disconnect_flag); if (n_actions > 1) { g_printerr ("error: too many Simple actions requested\n"); @@ -144,6 +150,33 @@ connect_ready (MMModemSimple *modem_simple, mmcli_async_operation_done (); } +static void +disconnect_process_reply (gboolean result, + const GError *error) +{ + if (!result) { + g_printerr ("error: couldn't disconnect all bearers in the modem: '%s'\n", + error ? error->message : "unknown error"); + exit (EXIT_FAILURE); + } + + g_print ("successfully disconnected all bearers in the modem\n"); +} + +static void +disconnect_ready (MMModemSimple *modem_simple, + GAsyncResult *result, + gpointer nothing) +{ + gboolean operation_result; + GError *error = NULL; + + operation_result = mm_modem_simple_disconnect_finish (modem_simple, result, &error); + disconnect_process_reply (operation_result, error); + + mmcli_async_operation_done (); +} + static void get_modem_ready (GObject *source, GAsyncResult *result, @@ -174,6 +207,18 @@ get_modem_ready (GObject *source, return; } + /* Request to disconnect all bearers in the modem? */ + if (disconnect_flag) { + g_debug ("Asynchronously disconnecting all bearers in the modem..."); + + mm_modem_simple_disconnect (ctx->modem_simple, + NULL, + ctx->cancellable, + (GAsyncReadyCallback)disconnect_ready, + NULL); + return; + } + g_warn_if_reached (); } @@ -197,7 +242,7 @@ mmcli_modem_simple_run_asynchronous (GDBusConnection *connection, void mmcli_modem_simple_run_synchronous (GDBusConnection *connection) { - /* GError *error = NULL; */ + GError *error = NULL; /* Initialize context */ ctx = g_new0 (Context, 1); @@ -209,5 +254,19 @@ mmcli_modem_simple_run_synchronous (GDBusConnection *connection) if (connect_str) g_assert_not_reached (); + /* Request to disconnect all bearers in the modem? */ + if (disconnect_flag) { + gboolean result; + + g_debug ("Asynchronously disconnecting all bearers in the modem..."); + + result = mm_modem_simple_disconnect_sync (ctx->modem_simple, + NULL, + NULL, + &error); + disconnect_process_reply (result, error); + return; + } + g_warn_if_reached (); } -- cgit v1.2.3-70-g09d2