diff options
-rw-r--r-- | build-aux/qmi-codegen/VariableInteger.py | 29 | ||||
-rw-r--r-- | build-aux/qmi-codegen/utils.py | 6 | ||||
-rw-r--r-- | libqmi-glib/qmi-utils.c | 64 | ||||
-rw-r--r-- | libqmi-glib/qmi-utils.h | 14 |
4 files changed, 103 insertions, 10 deletions
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py index 9705e3d..5c28933 100644 --- a/build-aux/qmi-codegen/VariableInteger.py +++ b/build-aux/qmi-codegen/VariableInteger.py @@ -24,7 +24,7 @@ from Variable import Variable """ Variable type for signed/unsigned Integers -('guint8', 'gint8', 'guint16', 'gint16', 'guint32', 'gint32' formats) +('guint8', 'gint8', 'guint16', 'gint16', 'guint32', 'gint32', 'guint64', 'gint64' formats) """ class VariableInteger(Variable): @@ -105,16 +105,29 @@ class VariableInteger(Variable): """ - Get the integer as a printable string. Given that we support max 32-bit - integers, it is safe to cast all them to standard integers when printing. + Get the integer as a printable string. """ def emit_get_printable(self, f, line_prefix, printable, buffer_name, buffer_len): - if utils.format_is_unsigned_integer(self.private_format): + common_format = '' + common_cast = '' + if self.private_format == 'guint8': common_format = '%u' - common_cast = 'guint' - else: + common_cast = '(guint)' + elif self.private_format == 'guint16': + common_format = '%" G_GUINT16_FORMAT "' + elif self.private_format == 'guint32': + common_format = '%" G_GUINT32_FORMAT "' + elif self.private_format == 'guint64': + common_format = '%" G_GUINT64_FORMAT "' + elif self.private_format == 'gint8': common_format = '%d' - common_cast = 'gint' + common_cast = '(gint)' + elif self.private_format == 'gint16': + common_format = '%" G_GINT16_FORMAT "' + elif self.private_format == 'gint32': + common_format = '%" G_GINT32_FORMAT "' + elif self.private_format == 'gint64': + common_format = '%" G_GINT64_FORMAT "' translations = { 'lp' : line_prefix, 'private_format' : self.private_format, @@ -135,7 +148,7 @@ class VariableInteger(Variable): '${lp} &${buffer_len},\n' '${lp} &tmp);\n' '\n' - '${lp} g_string_append_printf (${printable}, "${common_format}", (${common_cast})tmp);\n' + '${lp} g_string_append_printf (${printable}, "${common_format}", ${common_cast}tmp);\n' '${lp}}\n') f.write(string.Template(template).substitute(translations)) diff --git a/build-aux/qmi-codegen/utils.py b/build-aux/qmi-codegen/utils.py index a6e2363..239e03b 100644 --- a/build-aux/qmi-codegen/utils.py +++ b/build-aux/qmi-codegen/utils.py @@ -171,7 +171,8 @@ Returns True if the given format corresponds to a basic unsigned integer type def format_is_unsigned_integer(fmt): if fmt == 'guint8' or \ fmt == 'guint16' or \ - fmt == 'guint32': + fmt == 'guint32' or \ + fmt == 'guint64': return True else: return False @@ -183,7 +184,8 @@ Returns True if the given format corresponds to a basic signed integer type def format_is_signed_integer(fmt): if fmt == 'gint8' or \ fmt == 'gint16' or \ - fmt == 'gint32': + fmt == 'gint32' or \ + fmt == 'gint64': return True else: return False diff --git a/libqmi-glib/qmi-utils.c b/libqmi-glib/qmi-utils.c index d1e50f0..0e99469 100644 --- a/libqmi-glib/qmi-utils.c +++ b/libqmi-glib/qmi-utils.c @@ -158,6 +158,38 @@ qmi_utils_read_gint32_from_buffer (guint8 **buffer, } void +qmi_utils_read_guint64_from_buffer (guint8 **buffer, + guint16 *buffer_size, + guint64 *out) +{ + g_assert (out != NULL); + g_assert (buffer != NULL); + g_assert (buffer_size != NULL); + g_assert (*buffer_size >= 8); + + *out = GUINT64_FROM_LE (*((guint64 *)&((*buffer)[0]))); + + *buffer = &((*buffer)[8]); + *buffer_size = (*buffer_size) - 8; +} + +void +qmi_utils_read_gint64_from_buffer (guint8 **buffer, + guint16 *buffer_size, + gint64 *out) +{ + g_assert (out != NULL); + g_assert (buffer != NULL); + g_assert (buffer_size != NULL); + g_assert (*buffer_size >= 8); + + *out = GUINT64_FROM_LE (*((guint64 *)&((*buffer)[0]))); + + *buffer = &((*buffer)[8]); + *buffer_size = (*buffer_size) - 8; +} + +void qmi_utils_write_guint8_to_buffer (guint8 **buffer, guint16 *buffer_size, guint8 *in) @@ -254,6 +286,38 @@ qmi_utils_write_gint32_to_buffer (guint8 **buffer, } void +qmi_utils_write_guint64_to_buffer (guint8 **buffer, + guint16 *buffer_size, + guint64 *in) +{ + g_assert (in != NULL); + g_assert (buffer != NULL); + g_assert (buffer_size != NULL); + g_assert (*buffer_size >= 8); + + *((guint64 *)(&((*buffer)[0]))) = GUINT64_TO_LE (*in); + + *buffer = &((*buffer)[8]); + *buffer_size = (*buffer_size) - 8; +} + +void +qmi_utils_write_gint64_to_buffer (guint8 **buffer, + guint16 *buffer_size, + gint64 *in) +{ + g_assert (in != NULL); + g_assert (buffer != NULL); + g_assert (buffer_size != NULL); + g_assert (*buffer_size >= 8); + + *((gint64 *)(&((*buffer)[0]))) = GINT64_TO_LE (*in); + + *buffer = &((*buffer)[8]); + *buffer_size = (*buffer_size) - 8; +} + +void qmi_utils_read_string_from_buffer (guint8 **buffer, guint16 *buffer_size, gboolean length_prefix, diff --git a/libqmi-glib/qmi-utils.h b/libqmi-glib/qmi-utils.h index 7c098a0..8feda22 100644 --- a/libqmi-glib/qmi-utils.h +++ b/libqmi-glib/qmi-utils.h @@ -57,6 +57,13 @@ void qmi_utils_read_gint32_from_buffer (guint8 **buffer, guint16 *buffer_size, gint32 *out); +void qmi_utils_read_guint64_from_buffer (guint8 **buffer, + guint16 *buffer_size, + guint64 *out); +void qmi_utils_read_gint64_from_buffer (guint8 **buffer, + guint16 *buffer_size, + gint64 *out); + void qmi_utils_write_guint8_to_buffer (guint8 **buffer, guint16 *buffer_size, guint8 *in); @@ -78,6 +85,13 @@ void qmi_utils_write_gint32_to_buffer (guint8 **buffer, guint16 *buffer_size, gint32 *in); +void qmi_utils_write_guint64_to_buffer (guint8 **buffer, + guint16 *buffer_size, + guint64 *in); +void qmi_utils_write_gint64_to_buffer (guint8 **buffer, + guint16 *buffer_size, + gint64 *in); + /* Reading/Writing string variables */ void qmi_utils_read_string_from_buffer (guint8 **buffer, |