[PATCH v3 3/5] qmi-codegen: add support for gdouble
Thomas Weißschuh
thomas at t-8ch.de
Thu Feb 22 22:43:18 UTC 2018
---
build-aux/qmi-codegen/VariableInteger.py | 4 ++--
build-aux/qmi-codegen/utils.py | 5 +---
.../libqmi-glib/libqmi-glib-common.sections | 1 +
src/libqmi-glib/qmi-message.c | 27 ++++++++++++++++++++++
src/libqmi-glib/qmi-message.h | 26 +++++++++++++++++++++
5 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index ecfb1b8..a335e47 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -30,7 +30,7 @@ Variable type for signed/unsigned Integers and floating point numbers:
'guint32', 'gint32'
'guint64', 'gint64'
'guint-sized'
- 'gfloat'
+ 'gfloat', 'gdouble'
"""
class VariableInteger(Variable):
@@ -183,7 +183,7 @@ class VariableInteger(Variable):
common_format = '%" G_GINT32_FORMAT "'
elif self.private_format == 'gint64':
common_format = '%" G_GINT64_FORMAT "'
- elif self.private_format == 'gfloat':
+ elif self.private_format in ('gfloat', 'gdouble'):
common_format = '%f'
translations = { 'lp' : line_prefix,
diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py
index a4044dd..5e6fee7 100644
--- a/build-aux/qmi-codegen/utils.py
+++ b/build-aux/qmi-codegen/utils.py
@@ -239,10 +239,7 @@ def format_is_signed_integer(fmt):
Returns True if the given format corresponds to a basic floating point type
"""
def format_is_float(fmt):
- if fmt == 'gfloat':
- return True
- else:
- return False
+ return fmt in ('gfloat', 'gdouble')
"""
diff --git a/docs/reference/libqmi-glib/libqmi-glib-common.sections b/docs/reference/libqmi-glib/libqmi-glib-common.sections
index bc088e7..228a38c 100644
--- a/docs/reference/libqmi-glib/libqmi-glib-common.sections
+++ b/docs/reference/libqmi-glib/libqmi-glib-common.sections
@@ -1148,6 +1148,7 @@ qmi_message_tlv_read_guint64
qmi_message_tlv_read_gint64
qmi_message_tlv_read_sized_guint
qmi_message_tlv_read_gfloat
+qmi_message_tlv_read_gdouble
qmi_message_tlv_read_string
qmi_message_tlv_read_fixed_size_string
<SUBSECTION RAW TLVs>
diff --git a/src/libqmi-glib/qmi-message.c b/src/libqmi-glib/qmi-message.c
index 65a18bb..751eb33 100644
--- a/src/libqmi-glib/qmi-message.c
+++ b/src/libqmi-glib/qmi-message.c
@@ -1180,6 +1180,33 @@ qmi_message_tlv_read_gfloat (QmiMessage *self,
return TRUE;
}
+gboolean
+qmi_message_tlv_read_gdouble (QmiMessage *self,
+ gsize tlv_offset,
+ gsize *offset,
+ QmiEndian endian,
+ gdouble *out,
+ GError **error)
+{
+ const guint8 *ptr;
+
+ g_return_val_if_fail (self != NULL, FALSE);
+ g_return_val_if_fail (offset != NULL, FALSE);
+ g_return_val_if_fail (out != NULL, FALSE);
+
+ if (!(ptr = tlv_error_if_read_overflow (self, tlv_offset, *offset, 8, error)))
+ return FALSE;
+
+ /* Yeah, do this for now */
+ memcpy (out, ptr, 8);
+ if (endian == QMI_ENDIAN_BIG)
+ *out = __QMI_GDOUBLE_FROM_BE (*out);
+ else
+ *out = __QMI_GDOUBLE_FROM_LE (*out);
+ *offset = *offset + 8;
+ return TRUE;
+}
+
gboolean
qmi_message_tlv_read_string (QmiMessage *self,
gsize tlv_offset,
diff --git a/src/libqmi-glib/qmi-message.h b/src/libqmi-glib/qmi-message.h
index 9f502c9..7ac4b8c 100644
--- a/src/libqmi-glib/qmi-message.h
+++ b/src/libqmi-glib/qmi-message.h
@@ -855,6 +855,32 @@ gboolean qmi_message_tlv_read_gfloat (QmiMessage *self,
gfloat *out,
GError **error);
+/**
+ * qmi_message_tlv_read_gdouble:
+ * @self: a #QmiMessage.
+ * @tlv_offset: offset that was returned by qmi_message_tlv_read_init().
+ * @offset: address of a the offset within the TLV value.
+ * @endian: target endianness, swapped from host byte order if necessary.
+ * @out: return location for the read #gdouble.
+ * @error: return location for error or %NULL.
+ *
+ * Reads a 64-bit floating-point number from the TLV.
+ *
+ * @offset needs to point to a valid @gsize specifying the index to start
+ * reading from within the TLV value (0 for the first item). If the variable
+ * is successfully read, @offset will be updated to point past the read item.
+ *
+ * Returns: %TRUE if the variable is successfully read, otherwise %FALSE is returned and @error is set.
+ *
+ * Since: 1.22
+ */
+gboolean qmi_message_tlv_read_gdouble (QmiMessage *self,
+ gsize tlv_offset,
+ gsize *offset,
+ QmiEndian endian,
+ gdouble *out,
+ GError **error);
+
/**
* qmi_message_tlv_read_string:
* @self: a #QmiMessage.
--
2.16.2
More information about the libqmi-devel
mailing list