[PATCH 1/3] libmbim-glib: turn __mbim_utils_str_hex into public method
Ben Chan
benchan at chromium.org
Thu Jul 27 06:30:23 UTC 2017
__mbim_utils_str_hex is a useful utility method for returning a
hexadecimal string representation of a sequence of bytes in memory. This
patch turns it a public method 'mbim_utils_str_hex' provided by
libmbim-glib, which will be later used by mbimcli.
---
.../libmbim-glib/libmbim-glib-common.sections | 1 +
src/libmbim-glib/mbim-device.c | 14 +++++++-------
src/libmbim-glib/mbim-utils.c | 19 ++++++++++++++++---
src/libmbim-glib/mbim-utils.h | 7 ++++---
src/libmbim-glib/test/test-message-builder.c | 4 ++--
src/libmbim-glib/test/test-message-parser.c | 4 ++--
6 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/docs/reference/libmbim-glib/libmbim-glib-common.sections b/docs/reference/libmbim-glib/libmbim-glib-common.sections
index a4c3120..f07926c 100644
--- a/docs/reference/libmbim-glib/libmbim-glib-common.sections
+++ b/docs/reference/libmbim-glib/libmbim-glib-common.sections
@@ -553,6 +553,7 @@ mbim_status_error_get_type
<FILE>mbim-utils</FILE>
mbim_utils_get_traces_enabled
mbim_utils_set_traces_enabled
+mbim_utils_str_hex
</SECTION>
<SECTION>
diff --git a/src/libmbim-glib/mbim-device.c b/src/libmbim-glib/mbim-device.c
index 612ffe1..15c4910 100644
--- a/src/libmbim-glib/mbim-device.c
+++ b/src/libmbim-glib/mbim-device.c
@@ -495,9 +495,9 @@ process_message (MbimDevice *self,
if (mbim_utils_get_traces_enabled ()) {
gchar *printable;
- printable = __mbim_utils_str_hex (((GByteArray *)message)->data,
- ((GByteArray *)message)->len,
- ':');
+ printable = mbim_utils_str_hex (((GByteArray *)message)->data,
+ ((GByteArray *)message)->len,
+ ':');
g_debug ("[%s] Received message...%s\n"
">>>>>> RAW:\n"
">>>>>> length = %u\n"
@@ -1812,7 +1812,7 @@ device_send (MbimDevice *self,
if (mbim_utils_get_traces_enabled ()) {
gchar *printable;
- printable = __mbim_utils_str_hex (raw_message, raw_message_len, ':');
+ printable = mbim_utils_str_hex (raw_message, raw_message_len, ':');
g_debug ("[%s] Sent message...\n"
"<<<<<< RAW:\n"
"<<<<<< length = %u\n"
@@ -1847,9 +1847,9 @@ device_send (MbimDevice *self,
gchar *printable_fh;
gchar *printable_d;
- printable_h = __mbim_utils_str_hex (&fragments[i].header, sizeof (fragments[i].header), ':');
- printable_fh = __mbim_utils_str_hex (&fragments[i].fragment_header, sizeof (fragments[i].fragment_header), ':');
- printable_d = __mbim_utils_str_hex (fragments[i].data, fragments[i].data_length, ':');
+ printable_h = mbim_utils_str_hex (&fragments[i].header, sizeof (fragments[i].header), ':');
+ printable_fh = mbim_utils_str_hex (&fragments[i].fragment_header, sizeof (fragments[i].fragment_header), ':');
+ printable_d = mbim_utils_str_hex (fragments[i].data, fragments[i].data_length, ':');
g_debug ("[%s] Sent fragment (%u)...\n"
"<<<<<< RAW:\n"
"<<<<<< length = %u\n"
diff --git a/src/libmbim-glib/mbim-utils.c b/src/libmbim-glib/mbim-utils.c
index a7541ae..b971991 100644
--- a/src/libmbim-glib/mbim-utils.c
+++ b/src/libmbim-glib/mbim-utils.c
@@ -40,10 +40,23 @@
/*****************************************************************************/
+/**
+ * mbim_utils_str_hex:
+ * @mem: start of the memory location to read bytes from.
+ * @size: number of bytes to read from memory.
+ * @ delimiter: character to delimit hexadecimal octets in the result string.
+ *
+ * Creates a string of hexadecimal octets, delimited by @delimiter, for each of
+ * the @size byte from the memory location starting at @mem. If @size is 0, it
+ * returns #NULL.
+ *
+ * Returns: (transfer full): a string of delimited hexadecimal octets, or #NULL
+ * if @size is 0. The return value should be freed with g_free().
+ */
gchar *
-__mbim_utils_str_hex (gconstpointer mem,
- gsize size,
- gchar delimiter)
+mbim_utils_str_hex (gconstpointer mem,
+ gsize size,
+ gchar delimiter)
{
const guint8 *data = mem;
gsize i;
diff --git a/src/libmbim-glib/mbim-utils.h b/src/libmbim-glib/mbim-utils.h
index ee5632f..590d704 100644
--- a/src/libmbim-glib/mbim-utils.h
+++ b/src/libmbim-glib/mbim-utils.h
@@ -36,12 +36,13 @@ G_BEGIN_DECLS
gboolean mbim_utils_get_traces_enabled (void);
void mbim_utils_set_traces_enabled (gboolean enabled);
+gchar *mbim_utils_str_hex (gconstpointer mem,
+ gsize size,
+ gchar delimiter);
+
/* Other private methods */
#if defined (LIBMBIM_GLIB_COMPILATION)
-gchar *__mbim_utils_str_hex (gconstpointer mem,
- gsize size,
- gchar delimiter);
gboolean __mbim_user_allowed (uid_t uid,
GError **error);
#endif
diff --git a/src/libmbim-glib/test/test-message-builder.c b/src/libmbim-glib/test/test-message-builder.c
index 18fd29d..d522929 100644
--- a/src/libmbim-glib/test/test-message-builder.c
+++ b/src/libmbim-glib/test/test-message-builder.c
@@ -38,8 +38,8 @@ test_message_trace (const guint8 *computed,
gchar *message_str;
gchar *expected_str;
- message_str = __mbim_utils_str_hex (computed, computed_size, ':');
- expected_str = __mbim_utils_str_hex (expected, expected_size, ':');
+ message_str = mbim_utils_str_hex (computed, computed_size, ':');
+ expected_str = mbim_utils_str_hex (expected, expected_size, ':');
/* Dump all message contents */
g_print ("\n"
diff --git a/src/libmbim-glib/test/test-message-parser.c b/src/libmbim-glib/test/test-message-parser.c
index a71c8c5..d364818 100644
--- a/src/libmbim-glib/test/test-message-parser.c
+++ b/src/libmbim-glib/test/test-message-parser.c
@@ -36,8 +36,8 @@ test_message_trace (const guint8 *computed,
gchar *message_str;
gchar *expected_str;
- message_str = __mbim_utils_str_hex (computed, computed_size, ':');
- expected_str = __mbim_utils_str_hex (expected, expected_size, ':');
+ message_str = mbim_utils_str_hex (computed, computed_size, ':');
+ expected_str = mbim_utils_str_hex (expected, expected_size, ':');
/* Dump all message contents */
g_print ("\n"
--
2.14.0.rc0.400.g1c36432dff-goog
More information about the libmbim-devel
mailing list