wms: implement 'Get Supported Messages'

This commit is contained in:
Aleksander Morgado 2015-02-25 14:52:52 +01:00
parent f864133f8e
commit 18694ee79a
3 changed files with 93 additions and 1 deletions

View File

@ -110,6 +110,22 @@
"format" : "guint8",
"public-format" : "gboolean" } ] },
// *********************************************************************************
{ "name" : "Get Supported Messages",
"type" : "Message",
"service" : "WMS",
"id" : "0x001E",
"version" : "1.12",
"output" : [ { "common-ref" : "Operation Result" },
{ "name" : "List",
"id" : "0x10",
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" },
"prerequisites" : [ { "common-ref" : "Success" } ] } ] },
// *********************************************************************************
{ "name" : "Raw Send",
"type" : "Message",

View File

@ -194,6 +194,7 @@
<xi:include href="xml/qmi-message-wms-set-routes.xml"/>
<xi:include href="xml/qmi-message-wms-get-routes.xml"/>
<xi:include href="xml/qmi-message-wms-send-from-memory-storage.xml"/>
<xi:include href="xml/qmi-message-wms-get-supported-messages.xml"/>
</section>
</chapter>

View File

@ -41,10 +41,15 @@ typedef struct {
static Context *ctx;
/* Options */
static gboolean get_supported_messages_flag;
static gboolean reset_flag;
static gboolean noop_flag;
static GOptionEntry entries[] = {
{ "wms-get-supported-messages", 0, 0, G_OPTION_ARG_NONE, &get_supported_messages_flag,
"Get supported messages",
NULL
},
{ "wms-reset", 0, 0, G_OPTION_ARG_NONE, &reset_flag,
"Reset the service state",
NULL
@ -80,7 +85,8 @@ qmicli_wms_options_enabled (void)
if (checked)
return !!n_actions;
n_actions = (reset_flag +
n_actions = (get_supported_messages_flag +
reset_flag +
noop_flag);
if (n_actions > 1) {
@ -113,6 +119,63 @@ shutdown (gboolean operation_status)
qmicli_async_operation_done (operation_status);
}
static void
get_supported_messages_ready (QmiClientWms *client,
GAsyncResult *res)
{
QmiMessageWmsGetSupportedMessagesOutput *output;
GError *error = NULL;
GArray *bytearray = NULL;
GString *str = NULL;
output = qmi_client_wms_get_supported_messages_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_wms_get_supported_messages_output_get_result (output, &error)) {
g_printerr ("error: couldn't get supported WMS messages: %s\n", error->message);
g_error_free (error);
qmi_message_wms_get_supported_messages_output_unref (output);
shutdown (FALSE);
return;
}
g_print ("[%s] Successfully got supported WMS messages:\n",
qmi_device_get_path_display (ctx->device));
if (qmi_message_wms_get_supported_messages_output_get_list (output, &bytearray, NULL)) {
guint bytearray_i;
for (bytearray_i = 0; bytearray_i < bytearray->len; bytearray_i++) {
guint bit_i;
guint8 bytevalue;
bytevalue = g_array_index (bytearray, guint8, bytearray_i);
for (bit_i = 0; bit_i < 8; bit_i++) {
if (bytevalue & (1 << bit_i)) {
if (!str)
str = g_string_new ("");
g_string_append_printf (str, "\t0x%04X\n", (bit_i + (8 * bytearray_i)));
}
}
}
}
if (str) {
g_print ("%s", str->str);
g_string_free (str, TRUE);
} else
g_print ("\tnone\n");
qmi_message_wms_get_supported_messages_output_unref (output);
shutdown (TRUE);
}
static void
reset_ready (QmiClientWms *client,
GAsyncResult *res)
@ -161,6 +224,18 @@ qmicli_wms_run (QmiDevice *device,
ctx->client = g_object_ref (client);
ctx->cancellable = g_object_ref (cancellable);
/* Request to list supported messages? */
if (get_supported_messages_flag) {
g_debug ("Asynchronously getting supported WMS messages...");
qmi_client_wms_get_supported_messages (ctx->client,
NULL,
10,
ctx->cancellable,
(GAsyncReadyCallback)get_supported_messages_ready,
NULL);
return;
}
/* Request to reset WMS service? */
if (reset_flag) {
g_debug ("Asynchronously resetting WMS service...");