aboutsummaryrefslogtreecommitdiffstats
path: root/cli/qmicli-wds.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-05-10 19:30:32 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-03 16:08:51 +0200
commit65ecb72d17907fb88c037200300c02d7ca9315f1 (patch)
tree2a7f99cb08643490c92d82f50b7baf289d7b1723 /cli/qmicli-wds.c
parent85e6c2449e7bbce3497fcee83b4f4b327272d80f (diff)
downloadexternal_libqmi-65ecb72d17907fb88c037200300c02d7ca9315f1.zip
external_libqmi-65ecb72d17907fb88c037200300c02d7ca9315f1.tar.gz
external_libqmi-65ecb72d17907fb88c037200300c02d7ca9315f1.tar.bz2
cli,wds: new `--wds-follow-network' switch
When `--wds-start-network' is run along with `--wds-follow-network', the connection will be opened and kept tracked as long as it is alive. Once the modem gets disconnected, the `qmicli' process will end. When `--wds-start-network' is NOT run with `--wds-follow-network', the program will exit immediately. In this case, the user should keep track of the printed packet data handle and should also not release the CID; so that she can then issue a `--wds-stop-network' command with the proper CID and packet data handle.
Diffstat (limited to 'cli/qmicli-wds.c')
-rw-r--r--cli/qmicli-wds.c80
1 files changed, 63 insertions, 17 deletions
diff --git a/cli/qmicli-wds.c b/cli/qmicli-wds.c
index 97fa5ec..380f46c 100644
--- a/cli/qmicli-wds.c
+++ b/cli/qmicli-wds.c
@@ -47,6 +47,8 @@ static Context *ctx;
/* Options */
static gboolean start_network_flag;
+static gboolean follow_network_flag;
+static gchar *stop_network_str;
static gboolean get_packet_service_status_flag;
static gboolean get_data_bearer_technology_flag;
static gboolean get_current_data_bearer_technology_flag;
@@ -56,6 +58,14 @@ static GOptionEntry entries[] = {
"Start network",
NULL
},
+ { "wds-follow-network", 0, 0, G_OPTION_ARG_NONE, &follow_network_flag,
+ "Follow the network status until disconnected. Use with `--wds-start-network'",
+ NULL
+ },
+ { "wds-stop-network", 0, 0, G_OPTION_ARG_STRING, &stop_network_str,
+ "Stop network",
+ "[Packet data handle]"
+ },
{ "wds-get-packet-service-status", 0, 0, G_OPTION_ARG_NONE, &get_packet_service_status_flag,
"Get packet service status",
NULL
@@ -96,6 +106,7 @@ qmicli_wds_options_enabled (void)
return !!n_actions;
n_actions = (start_network_flag +
+ !!stop_network_str +
get_packet_service_status_flag +
get_data_bearer_technology_flag +
get_current_data_bearer_technology_flag);
@@ -103,6 +114,10 @@ qmicli_wds_options_enabled (void)
if (n_actions > 1) {
g_printerr ("error: too many WDS actions requested\n");
exit (EXIT_FAILURE);
+ } else if (n_actions == 0 &&
+ follow_network_flag) {
+ g_printerr ("error: `--wds-follow-network' must be used with `--wds-start-network'\n");
+ exit (EXIT_FAILURE);
}
checked = TRUE;
@@ -164,18 +179,11 @@ stop_network_ready (QmiClientWds *client,
}
static void
-network_cancelled (GCancellable *cancellable)
+internal_stop_network (GCancellable *cancellable,
+ guint32 packet_data_handle)
{
QmiWdsStopNetworkInput *input;
- ctx->network_started_id = 0;
-
- /* Remove the timeout right away */
- if (ctx->packet_status_timeout_id) {
- g_source_remove (ctx->packet_status_timeout_id);
- ctx->packet_status_timeout_id = 0;
- }
-
input = qmi_wds_stop_network_input_new ();
qmi_wds_stop_network_input_set_packet_data_handle (input, ctx->packet_data_handle);
@@ -190,6 +198,23 @@ network_cancelled (GCancellable *cancellable)
}
static void
+network_cancelled (GCancellable *cancellable)
+{
+ QmiWdsStopNetworkInput *input;
+
+ ctx->network_started_id = 0;
+
+ /* Remove the timeout right away */
+ if (ctx->packet_status_timeout_id) {
+ g_source_remove (ctx->packet_status_timeout_id);
+ ctx->packet_status_timeout_id = 0;
+ }
+
+ g_print ("Network cancelled... releasing resources\n");
+ internal_stop_network (cancellable, ctx->packet_data_handle);
+}
+
+static void
timeout_get_packet_service_status_ready (QmiClientWds *client,
GAsyncResult *res)
{
@@ -270,15 +295,20 @@ start_network_ready (QmiClientWds *client,
qmi_device_get_path_display (ctx->device),
(guint)ctx->packet_data_handle);
- g_print ("\nCtrl+C will stop the network\n");
- ctx->network_started_id = g_cancellable_connect (ctx->cancellable,
- G_CALLBACK (network_cancelled),
- NULL,
- NULL);
+ if (follow_network_flag) {
+ g_print ("\nCtrl+C will stop the network\n");
+ ctx->network_started_id = g_cancellable_connect (ctx->cancellable,
+ G_CALLBACK (network_cancelled),
+ NULL,
+ NULL);
- ctx->packet_status_timeout_id = g_timeout_add_seconds (20,
- (GSourceFunc)packet_status_timeout,
- NULL);
+ ctx->packet_status_timeout_id = g_timeout_add_seconds (20,
+ (GSourceFunc)packet_status_timeout,
+ NULL);
+ } else {
+ /* Nothing else to do */
+ shutdown ();
+ }
qmi_wds_start_network_output_unref (output);
}
@@ -502,6 +532,22 @@ qmicli_wds_run (QmiDevice *device,
return;
}
+ /* Request to stop network? */
+ if (stop_network_str) {
+ guint32 packet_data_handle;
+
+ packet_data_handle = atoi (stop_network_str);
+ if (!packet_data_handle) {
+ g_printerr ("error: invalid packet data handle given '%s'\n",
+ stop_network_str);
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("Asynchronously stopping network...");
+ internal_stop_network (ctx->cancellable, packet_data_handle);
+ return;
+ }
+
/* Request to get packet service status? */
if (get_packet_service_status_flag) {
g_debug ("Asynchronously getting packet service status...");