[PATCH 1/4] libqmi-glib: add GDOUBLE_FROM_LE

Thomas Weißschuh thomas at t-8ch.de
Sun Jan 28 15:50:38 UTC 2018


Lifted from Gstreamer gstutils.h v1.12.4.

This is need to support gdouble values in the QMI LOC service.
---
 .../libqmi-glib/libqmi-glib-common.sections        |  6 ++
 src/libqmi-glib/qmi-utils.h                        | 73 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections b/docs/reference/libqmi-glib/libqmi-glib-common.sections
index bc088e7..f74a9ca 100644
--- a/docs/reference/libqmi-glib/libqmi-glib-common.sections
+++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections
@@ -1208,6 +1208,12 @@ qmi_utils_write_gint64_to_buffer
 qmi_utils_write_sized_guint_to_buffer
 qmi_utils_write_string_to_buffer
 qmi_utils_write_fixed_size_string_to_buffer
+<SUBSECTION Byteorder>
+GDOUBLE_FROM_BE
+GDOUBLE_FROM_LE
+GDOUBLE_SWAP_LE_BE
+GDOUBLE_TO_BE
+GDOUBLE_TO_LE
 </SECTION>
 
 <SECTION>
diff --git a/src/libqmi-glib/qmi-utils.h b/src/libqmi-glib/qmi-utils.h
index 4fd5199..03af9ca 100644
--- a/src/libqmi-glib/qmi-utils.h
+++ b/src/libqmi-glib/qmi-utils.h
@@ -20,6 +20,10 @@
  *
  * Copyright (C) 2012-2015 Dan Williams <dcbw at redhat.com>
  * Copyright (C) 2012-2017 Aleksander Morgado <aleksander at aleksander.es>
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega at cse.ogi.edu>
+ * Copyright (C) 2000 Wim Taymans <wtay at chello.be>
+ * Copyright (C) 2002 Thomas Vander Stichele <thomas at apestaart.org>
+
  */
 
 #ifndef _LIBQMI_GLIB_QMI_UTILS_H_
@@ -653,6 +657,75 @@ G_GNUC_INTERNAL
 gchar *__qmi_utils_get_driver (const gchar *cdc_wdm_path);
 #endif
 
+#ifndef GDOUBLE_FROM_LE
+/**
+ * GDOUBLE_SWAP_LE_BE:
+ * @in: input value
+ *
+ * Swap byte order of a 64-bit floating point value (double).
+ *
+ * Returns: @in byte-swapped.
+ */
+static inline gdouble
+GDOUBLE_SWAP_LE_BE(gdouble in)
+{
+  union
+  {
+    guint64 i;
+    gdouble d;
+  } u;
+
+  u.d = in;
+  u.i = GUINT64_SWAP_LE_BE (u.i);
+  return u.d;
+}
+
+/**
+ * GDOUBLE_TO_LE:
+ * @val: value
+ *
+ * Convert 64-bit floating point value (double) from native byte order into
+ * little endian byte order.
+ */
+/**
+ * GDOUBLE_TO_BE:
+ * @val: value
+ *
+ * Convert 64-bit floating point value (double) from native byte order into
+ * big endian byte order.
+ */
+/**
+ * GDOUBLE_FROM_LE:
+ * @val: value
+ *
+ * Convert 64-bit floating point value (double) from little endian byte order
+ * into native byte order.
+ */
+/**
+ * GDOUBLE_FROM_BE:
+ * @val: value
+ *
+ * Convert 64-bit floating point value (double) from big endian byte order
+ * into native byte order.
+ */
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+#define GDOUBLE_TO_LE(val)   ((gdouble) (val))
+#define GDOUBLE_TO_BE(val)   (GDOUBLE_SWAP_LE_BE (val))
+
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+#define GDOUBLE_TO_LE(val)   (GDOUBLE_SWAP_LE_BE (val))
+#define GDOUBLE_TO_BE(val)   ((gdouble) (val))
+
+#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+#error unknown ENDIAN type
+#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
+
+#define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
+#define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
+
+#endif /* !defined(GFLOAT_FROM_LE) */
+
 G_END_DECLS
 
 #endif /* _LIBQMI_GLIB_QMI_UTILS_H_ */
-- 
2.16.1



More information about the libqmi-devel mailing list