diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/qmicli/qmicli-dms.c | 31 | ||||
-rw-r--r-- | src/qmicli/qmicli-helpers.c | 25 | ||||
-rw-r--r-- | src/qmicli/qmicli-helpers.h | 3 | ||||
-rw-r--r-- | src/qmicli/qmicli-nas.c | 31 | ||||
-rw-r--r-- | src/qmicli/qmicli-uim.c | 31 | ||||
-rw-r--r-- | src/qmicli/qmicli-voice.c | 31 | ||||
-rw-r--r-- | src/qmicli/qmicli-wda.c | 31 | ||||
-rw-r--r-- | src/qmicli/qmicli-wds.c | 32 | ||||
-rw-r--r-- | src/qmicli/qmicli-wms.c | 32 | ||||
-rw-r--r-- | src/qmicli/test/test-helpers.c | 34 |
10 files changed, 106 insertions, 175 deletions
diff --git a/src/qmicli/qmicli-dms.c b/src/qmicli/qmicli-dms.c index 13b6a39..6f259f9 100644 --- a/src/qmicli/qmicli-dms.c +++ b/src/qmicli/qmicli-dms.c @@ -2996,7 +2996,7 @@ get_supported_messages_ready (QmiClientDms *client, QmiMessageDmsGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_dms_get_supported_messages_finish (client, res, &error); if (!output) { @@ -3017,30 +3017,11 @@ get_supported_messages_ready (QmiClientDms *client, g_print ("[%s] Successfully got supported DMS messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_dms_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_dms_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_dms_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-helpers.c b/src/qmicli/qmicli-helpers.c index c6911c6..32d5f49 100644 --- a/src/qmicli/qmicli-helpers.c +++ b/src/qmicli/qmicli-helpers.c @@ -389,3 +389,28 @@ qmicli_read_uint_from_string (const gchar *str, } return FALSE; } + +gchar * +qmicli_get_supported_messages_list (const guint8 *data, + gsize len) +{ + GString *str = NULL; + + if (len > 0 && data) { + guint bytearray_i; + + for (bytearray_i = 0; bytearray_i < len; bytearray_i++) { + guint bit_i; + + for (bit_i = 0; bit_i < 8; bit_i++) { + if (data[bytearray_i] & (1 << bit_i)) { + if (!str) + str = g_string_new (""); + g_string_append_printf (str, "\t0x%04X\n", (guint16) (bit_i + (8 * bytearray_i))); + } + } + } + } + + return (str ? g_string_free (str, FALSE) : g_strdup ("\tnone\n")); +} diff --git a/src/qmicli/qmicli-helpers.h b/src/qmicli/qmicli-helpers.h index 72f8825..864afd9 100644 --- a/src/qmicli/qmicli-helpers.h +++ b/src/qmicli/qmicli-helpers.h @@ -55,4 +55,7 @@ gboolean qmicli_read_non_empty_string (const gchar *str, gboolean qmicli_read_uint_from_string (const gchar *str, guint *out); +gchar *qmicli_get_supported_messages_list (const guint8 *data, + gsize len); + #endif /* __QMICLI_H__ */ diff --git a/src/qmicli/qmicli-nas.c b/src/qmicli/qmicli-nas.c index b97a568..16aa89f 100644 --- a/src/qmicli/qmicli-nas.c +++ b/src/qmicli/qmicli-nas.c @@ -2763,7 +2763,7 @@ get_supported_messages_ready (QmiClientNas *client, QmiMessageNasGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_nas_get_supported_messages_finish (client, res, &error); if (!output) { @@ -2784,30 +2784,11 @@ get_supported_messages_ready (QmiClientNas *client, g_print ("[%s] Successfully got supported NAS messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_nas_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_nas_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_nas_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-uim.c b/src/qmicli/qmicli-uim.c index d3e912f..7268a9e 100644 --- a/src/qmicli/qmicli-uim.c +++ b/src/qmicli/qmicli-uim.c @@ -145,7 +145,7 @@ get_supported_messages_ready (QmiClientUim *client, QmiMessageUimGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_uim_get_supported_messages_finish (client, res, &error); if (!output) { @@ -166,30 +166,11 @@ get_supported_messages_ready (QmiClientUim *client, g_print ("[%s] Successfully got supported UIM messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_uim_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_uim_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_uim_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-voice.c b/src/qmicli/qmicli-voice.c index 33b27a4..95730e8 100644 --- a/src/qmicli/qmicli-voice.c +++ b/src/qmicli/qmicli-voice.c @@ -259,7 +259,7 @@ get_supported_messages_ready (QmiClientVoice *client, QmiMessageVoiceGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_voice_get_supported_messages_finish (client, res, &error); if (!output) { @@ -280,30 +280,11 @@ get_supported_messages_ready (QmiClientVoice *client, g_print ("[%s] Successfully got supported VOICE messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_voice_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_voice_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_voice_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-wda.c b/src/qmicli/qmicli-wda.c index 3ecdf42..76793d6 100644 --- a/src/qmicli/qmicli-wda.c +++ b/src/qmicli/qmicli-wda.c @@ -326,7 +326,7 @@ get_supported_messages_ready (QmiClientWda *client, QmiMessageWdaGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_wda_get_supported_messages_finish (client, res, &error); if (!output) { @@ -347,30 +347,11 @@ get_supported_messages_ready (QmiClientWda *client, g_print ("[%s] Successfully got supported WDA messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_wda_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_wda_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_wda_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-wds.c b/src/qmicli/qmicli-wds.c index aba7f0d..4705530 100644 --- a/src/qmicli/qmicli-wds.c +++ b/src/qmicli/qmicli-wds.c @@ -31,6 +31,7 @@ #include <libqmi-glib.h> #include "qmicli.h" +#include "qmicli-helpers.h" /* Context */ typedef struct { @@ -862,7 +863,7 @@ get_supported_messages_ready (QmiClientWds *client, QmiMessageWdsGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_wds_get_supported_messages_finish (client, res, &error); if (!output) { @@ -883,30 +884,11 @@ get_supported_messages_ready (QmiClientWds *client, g_print ("[%s] Successfully got supported WDS messages:\n", qmi_device_get_path_display (ctx->device)); - if (qmi_message_wds_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_wds_get_supported_messages_output_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_wds_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/qmicli-wms.c b/src/qmicli/qmicli-wms.c index 4c58274..9cc7943 100644 --- a/src/qmicli/qmicli-wms.c +++ b/src/qmicli/qmicli-wms.c @@ -31,6 +31,7 @@ #include <libqmi-glib.h> #include "qmicli.h" +#include "qmicli-helpers.h" /* Context */ typedef struct { @@ -126,7 +127,7 @@ get_supported_messages_ready (QmiClientWms *client, QmiMessageWmsGetSupportedMessagesOutput *output; GError *error = NULL; GArray *bytearray = NULL; - GString *str = NULL; + gchar *str; output = qmi_client_wms_get_supported_messages_finish (client, res, &error); if (!output) { @@ -147,30 +148,11 @@ get_supported_messages_ready (QmiClientWms *client, 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_get_list (output, &bytearray, NULL); + str = qmicli_get_supported_messages_list (bytearray ? (const guint8 *)bytearray->data : NULL, + bytearray ? bytearray->len : 0); + g_print ("%s", str); + g_free (str); qmi_message_wms_get_supported_messages_output_unref (output); shutdown (TRUE); diff --git a/src/qmicli/test/test-helpers.c b/src/qmicli/test/test-helpers.c index 824ed3e..cfdfefd 100644 --- a/src/qmicli/test/test-helpers.c +++ b/src/qmicli/test/test-helpers.c @@ -112,6 +112,37 @@ test_helpers_raw_printable_4 (void) g_array_unref (array); } +static void +test_helpers_supported_messages_list (void) +{ + const guint8 bytearray[] = { + 0x03, 0x00, 0x00, 0xC0 + }; + const gchar *expected_str = + "\t0x0000\n" /* 0 dec */ + "\t0x0001\n" /* 1 dec */ + "\t0x001E\n" /* 30 dec */ + "\t0x001F\n"; /* 31 dec */ + gchar *str; + + str = qmicli_get_supported_messages_list (bytearray, G_N_ELEMENTS (bytearray)); + g_assert (str); + g_assert_cmpstr (str, ==, expected_str); + g_free (str); +} + +static void +test_helpers_supported_messages_list_none (void) +{ + const gchar *expected_str = "\tnone\n"; + gchar *str; + + str = qmicli_get_supported_messages_list (NULL, 0); + g_assert (str); + g_assert_cmpstr (str, ==, expected_str); + g_free (str); +} + int main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); @@ -121,5 +152,8 @@ int main (int argc, char **argv) g_test_add_func ("/qmicli/helpers/raw-printable/3", test_helpers_raw_printable_3); g_test_add_func ("/qmicli/helpers/raw-printable/4", test_helpers_raw_printable_4); + g_test_add_func ("/qmicli/helpers/supported-message-list", test_helpers_supported_messages_list); + g_test_add_func ("/qmicli/helpers/supported-message-list/none", test_helpers_supported_messages_list_none); + return g_test_run (); } |