summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-05-30 13:03:59 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-07-03 16:08:57 +0200
commitd2dc319a73a5266e3cbf97a60de36b1b69a75e56 (patch)
treefb8902297acf8553c8dc427be4d6d7f24eb3beb7
parentd27b80e302a0db7998c861edb622c1ae24155fd5 (diff)
cli: new `--dms-get-model' action
-rw-r--r--cli/qmicli-dms.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/cli/qmicli-dms.c b/cli/qmicli-dms.c
index 6df9172..a717517 100644
--- a/cli/qmicli-dms.c
+++ b/cli/qmicli-dms.c
@@ -44,6 +44,7 @@ static Context *ctx;
static gboolean get_ids_flag;
static gboolean get_capabilities_flag;
static gboolean get_manufacturer_flag;
+static gboolean get_model_flag;
static gboolean noop_flag;
static GOptionEntry entries[] = {
@@ -59,6 +60,10 @@ static GOptionEntry entries[] = {
"Get manufacturer",
NULL
},
+ { "dms-get-model", 0, 0, G_OPTION_ARG_NONE, &get_model_flag,
+ "Get model",
+ NULL
+ },
{ "dms-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag,
"Just allocate or release a DMS client. Use with `--client-no-release-cid' and/or `--client-cid'",
NULL
@@ -93,6 +98,7 @@ qmicli_dms_options_enabled (void)
n_actions = (get_ids_flag +
get_capabilities_flag +
get_manufacturer_flag +
+ get_model_flag +
noop_flag);
if (n_actions > 1) {
@@ -267,6 +273,44 @@ get_manufacturer_ready (QmiClientDms *client,
qmi_message_dms_get_manufacturer_output_unref (output);
shutdown (TRUE);
}
+
+static void
+get_model_ready (QmiClientDms *client,
+ GAsyncResult *res)
+{
+ const gchar *str = NULL;
+ QmiMessageDmsGetModelOutput *output;
+ GError *error = NULL;
+
+ output = qmi_client_dms_get_model_finish (client, res, &error);
+ if (!output) {
+ g_printerr ("error: operation failed: %s\n", error->message);
+ g_error_free (error);
+ shutdown (FALSE);
+ return;
+ }
+
+ if (!qmi_message_dms_get_model_output_get_result (output, &error)) {
+ g_printerr ("error: couldn't get model: %s\n", error->message);
+ g_error_free (error);
+ qmi_message_dms_get_model_output_unref (output);
+ shutdown (FALSE);
+ return;
+ }
+
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+
+ qmi_message_dms_get_model_output_get_model (output, &str, NULL);
+
+ g_print ("[%s] Device model retrieved:\n"
+ "\tModel: '%s'\n",
+ qmi_device_get_path_display (ctx->device),
+ VALIDATE_UNKNOWN (str));
+
+ qmi_message_dms_get_model_output_unref (output);
+ shutdown (TRUE);
+}
static gboolean
noop_cb (gpointer unused)
{
@@ -322,6 +366,18 @@ qmicli_dms_run (QmiDevice *device,
return;
}
+ /* Request to get model? */
+ if (get_model_flag) {
+ g_debug ("Asynchronously getting model...");
+ qmi_client_dms_get_model (ctx->client,
+ NULL,
+ 10,
+ ctx->cancellable,
+ (GAsyncReadyCallback)get_model_ready,
+ NULL);
+ return;
+ }
+
/* Just client allocate/release? */
if (noop_flag) {
g_idle_add (noop_cb, NULL);