summaryrefslogtreecommitdiff
path: root/libqmi-glib
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-09-24 16:07:06 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-09-26 09:25:05 +0200
commitd6613195a98aea78163e8118c524d25d22f70f8b (patch)
tree9b375e96b96cf53e47cf494d3f75d71e55592f35 /libqmi-glib
parent3347c00dab3a7339c2982710d9ff214eabf3c125 (diff)
message: renamed `qmi_message_tlv_add()' to `qmi_message_add_raw_tlv()'
Also swapped length and buffer variables; it no longer follows the 'TLV' name (type,length,value), but it's more consistent with other interfaces where buffer is given first and then the length.
Diffstat (limited to 'libqmi-glib')
-rw-r--r--libqmi-glib/qmi-message.c36
-rw-r--r--libqmi-glib/qmi-message.h10
2 files changed, 29 insertions, 17 deletions
diff --git a/libqmi-glib/qmi-message.c b/libqmi-glib/qmi-message.c
index 13eacce..9cc566c 100644
--- a/libqmi-glib/qmi-message.c
+++ b/libqmi-glib/qmi-message.c
@@ -509,18 +509,31 @@ qmi_message_tlv_foreach (QmiMessage *self,
}
}
+/**
+ * qmi_message_add_raw_tlv:
+ * @self: a #QmiMessage.
+ * @type: specific ID of the TLV to add.
+ * @raw: raw data buffer with the value of the TLV.
+ * @length: length of the raw data buffer.
+ * @error: return location for error or %NULL.
+ *
+ * Creates a new @type TLV with the value given in @raw, and adds it to the #QmiMessage.
+ *
+ * Returns: #TRUE if the TLV as successfully added, otherwise #FALSE is returned and @error is set.
+ */
gboolean
-qmi_message_tlv_add (QmiMessage *self,
- guint8 type,
- gsize length,
- gconstpointer value,
- GError **error)
+qmi_message_add_raw_tlv (QmiMessage *self,
+ guint8 type,
+ const guint8 *raw,
+ gsize length,
+ GError **error)
{
size_t tlv_len;
struct tlv *tlv;
- g_assert (self != NULL);
- g_assert ((length == 0) || value != NULL);
+ g_return_val_if_fail (self != NULL, FALSE);
+ g_return_val_if_fail (raw != NULL, FALSE);
+ g_return_val_if_fail (length > 0, FALSE);
/* Make sure nothing's broken to start. */
if (!qmi_message_check (self, error)) {
@@ -528,11 +541,11 @@ qmi_message_tlv_add (QmiMessage *self,
return FALSE;
}
- /* Find length of new TLV. */
+ /* Find length of new TLV */
tlv_len = sizeof (struct tlv) + length;
/* Check for overflow of message size. */
- if (qmi_message_get_qmux_length (self) + tlv_len > UINT16_MAX) {
+ if (qmi_message_get_qmux_length (self) + tlv_len > G_MAXUINT16) {
g_set_error (error,
QMI_CORE_ERROR,
QMI_CORE_ERROR_TLV_TOO_LONG,
@@ -547,9 +560,8 @@ qmi_message_tlv_add (QmiMessage *self,
/* Fill in new TLV. */
tlv = (struct tlv *)(qmi_end (self) - tlv_len);
tlv->type = type;
- tlv->length = htole16 (length);
- if (value)
- memcpy (tlv->value, value, length);
+ tlv->length = GUINT16_TO_LE (length);
+ memcpy (tlv->value, raw, length);
/* Update length fields. */
set_qmux_length (self, (guint16)(qmi_message_get_qmux_length (self) + tlv_len));
diff --git a/libqmi-glib/qmi-message.h b/libqmi-glib/qmi-message.h
index 666d766..40ab5e4 100644
--- a/libqmi-glib/qmi-message.h
+++ b/libqmi-glib/qmi-message.h
@@ -60,11 +60,11 @@ const guint8 *qmi_message_get_raw_tlv (QmiMessage *self,
guint8 type,
guint16 *length);
-gboolean qmi_message_tlv_add (QmiMessage *self,
- guint8 type,
- gsize length,
- gconstpointer value,
- GError **error);
+gboolean qmi_message_add_raw_tlv (QmiMessage *self,
+ guint8 type,
+ const guint8 *raw,
+ gsize length,
+ GError **error);
gconstpointer qmi_message_get_raw (QmiMessage *self,
gsize *length,