aboutsummaryrefslogtreecommitdiff
path: root/cli/mmcli-modem.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2011-08-20 13:12:27 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:26 +0100
commit5de1ae6a4fd2681147babb0e5fc0cfb3a502ad40 (patch)
tree5a3f2dea8a9e6e4ffb986e6895f287bbbc443677 /cli/mmcli-modem.c
parent9a6bb0bb196bce46d355d02fd635788308c0d73e (diff)
cli: add command to monitor modem state
Diffstat (limited to 'cli/mmcli-modem.c')
-rw-r--r--cli/mmcli-modem.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
index 13220d3f..a79739e6 100644
--- a/cli/mmcli-modem.c
+++ b/cli/mmcli-modem.c
@@ -37,6 +37,7 @@ typedef struct {
/* Input options */
gchar *modem_str;
gboolean info_flag;
+ gboolean monitor_state_flag;
/* The modem proxy */
MMModem *modem;
} Context;
@@ -51,6 +52,10 @@ static GOptionEntry entries[] = {
"Get information of a given modem",
NULL
},
+ { "monitor-state", 'f', 0, G_OPTION_ARG_NONE, &ctxt.monitor_state_flag,
+ "Monitor state of a given modem",
+ NULL
+ },
{ NULL }
};
@@ -75,7 +80,8 @@ mmcli_modem_options_enabled (void)
{
guint n_actions;
- n_actions = (ctxt.info_flag);
+ n_actions = (ctxt.info_flag +
+ ctxt.monitor_state_flag);
if (n_actions > 1) {
g_printerr ("error: too many modem actions requested\n");
@@ -228,6 +234,22 @@ get_state_string (MMModemState state)
return NULL;
}
+static const gchar *
+get_state_reason_string (MMModemStateReason reason)
+{
+ switch (reason) {
+ case MM_MODEM_STATE_REASON_NONE:
+ return "None or unknown";
+ case MM_MODEM_STATE_REASON_USER_REQUESTED:
+ return "User request";
+ case MM_MODEM_STATE_REASON_SUSPEND:
+ return "Suspend";
+ }
+
+ g_warn_if_reached ();
+ return NULL;
+}
+
static void
get_info_process_reply (gboolean result,
const GError *error,
@@ -358,12 +380,23 @@ get_info_ready (MMModem *modem,
mmcli_async_operation_done ();
}
+static void
+state_changed (MMModem *modem,
+ MMModemState old_state,
+ MMModemState new_state,
+ MMModemStateReason reason)
+{
+ g_print ("State changed: '%s' --> '%s' (Reason: %s)\n",
+ get_state_string (old_state),
+ get_state_string (new_state),
+ get_state_reason_string (reason));
+ fflush (stdout);
+}
+
gboolean
mmcli_modem_run_asynchronous (GDBusConnection *connection,
GCancellable *cancellable)
{
- gboolean keep_loop = FALSE;
-
/* Initialize context */
init (connection);
@@ -373,7 +406,23 @@ mmcli_modem_run_asynchronous (GDBusConnection *connection,
cancellable,
(GAsyncReadyCallback)get_info_ready,
NULL);
- return keep_loop;
+ return FALSE;
+ }
+
+ /* Request to monitor modems? */
+ if (ctxt.monitor_state_flag) {
+ MMModemState current;
+
+ g_signal_connect (ctxt.modem,
+ "state-changed",
+ G_CALLBACK (state_changed),
+ NULL);
+
+ current = mm_modem_get_state (ctxt.modem);
+ g_print ("Initial state: '%s'\n", get_state_string (current));
+
+ /* We need to keep the loop */
+ return TRUE;
}
g_warn_if_reached ();
@@ -385,6 +434,11 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
{
GError *error = NULL;
+ if (ctxt.monitor_state_flag) {
+ g_printerr ("error: monitoring state cannot be done synchronously\n");
+ exit (EXIT_FAILURE);
+ }
+
/* Initialize context */
init (connection);