summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-message.c
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@codefactory.se>2003-02-24 19:04:13 +0000
committerAnders Carlsson <andersca@codefactory.se>2003-02-24 19:04:13 +0000
commitc8769e0b1dde3f1c4ad40cd10dd89c284ecc672b (patch)
tree12d9e757f2ec9bb678114dfbcac28c3a05263f66 /dbus/dbus-message.c
parent2f38c959212d98e2194139daa9120fda37415b4f (diff)
2003-02-24 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-internals.c: (_dbus_type_to_string): * dbus/dbus-marshal.c: (_dbus_marshal_get_arg_end_pos), (_dbus_marshal_validate_arg): * dbus/dbus-message-builder.c: (_dbus_message_data_load): * dbus/dbus-message.c: (dbus_message_append_args_valist), (dbus_message_append_boolean), (dbus_message_append_boolean_array), (dbus_message_get_args_valist), (dbus_message_iter_get_boolean), (dbus_message_iter_get_int32), (dbus_message_iter_get_uint32), (dbus_message_iter_get_double), (dbus_message_iter_get_boolean_array), (message_iter_test): * dbus/dbus-message.h: * dbus/dbus-protocol.h: * doc/dbus-specification.sgml: * test/data/valid-messages/lots-of-arguments.message: Add support for boolean and boolean array types.
Diffstat (limited to 'dbus/dbus-message.c')
-rw-r--r--dbus/dbus-message.c156
1 files changed, 151 insertions, 5 deletions
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index 7feee745..0d664916 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -1049,6 +1049,9 @@ dbus_message_append_args_valist (DBusMessage *message,
case DBUS_TYPE_NIL:
if (!dbus_message_append_nil (message))
goto enomem;
+ case DBUS_TYPE_BOOLEAN:
+ if (!dbus_message_append_boolean (message, va_arg (var_args, dbus_bool_t)))
+ goto enomem;
case DBUS_TYPE_INT32:
if (!dbus_message_append_int32 (message, va_arg (var_args, dbus_int32_t)))
goto enomem;
@@ -1065,6 +1068,18 @@ dbus_message_append_args_valist (DBusMessage *message,
if (!dbus_message_append_string (message, va_arg (var_args, const char *)))
goto enomem;
break;
+ case DBUS_TYPE_BOOLEAN_ARRAY:
+ {
+ int len;
+ unsigned char *data;
+
+ data = va_arg (var_args, unsigned char *);
+ len = va_arg (var_args, int);
+
+ if (!dbus_message_append_boolean_array (message, data, len))
+ goto enomem;
+ }
+ break;
case DBUS_TYPE_INT32_ARRAY:
{
int len;
@@ -1157,6 +1172,31 @@ dbus_message_append_nil (DBusMessage *message)
}
/**
+ * Appends a boolean value to the message
+ *
+ * @param message the message
+ * @param value the boolean value
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_boolean (DBusMessage *message,
+ unsigned char value)
+{
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BOOLEAN))
+ return FALSE;
+
+ if (!_dbus_string_append_byte (&message->body, (value != FALSE)))
+ {
+ _dbus_string_shorten (&message->body, 1);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* Appends a 32 bit signed integer to the message.
*
* @param message the message
@@ -1257,6 +1297,33 @@ dbus_message_append_string (DBusMessage *message,
}
/**
+ * Appends a boolean array to the message.
+ *
+ * @param message the message
+ * @param value the array
+ * @param len the length of the array
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_append_boolean_array (DBusMessage *message,
+ unsigned char *value,
+ int len)
+{
+ _dbus_assert (!message->locked);
+
+ if (!_dbus_string_append_byte (&message->body, DBUS_TYPE_BOOLEAN_ARRAY))
+ return FALSE;
+
+ if (!_dbus_marshal_byte_array (&message->body, message->byte_order, value, len))
+ {
+ _dbus_string_shorten (&message->body, 1);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* Appends a 32 bit signed integer array to the message.
*
* @param message the message
@@ -1472,6 +1539,17 @@ dbus_message_get_args_valist (DBusMessage *message,
switch (spec_type)
{
+ case DBUS_TYPE_NIL:
+ break;
+ case DBUS_TYPE_BOOLEAN:
+ {
+ unsigned char *ptr;
+
+ ptr = va_arg (var_args, unsigned char *);
+
+ *ptr = dbus_message_iter_get_boolean (iter);
+ break;
+ }
case DBUS_TYPE_INT32:
{
dbus_int32_t *ptr;
@@ -1515,6 +1593,20 @@ dbus_message_get_args_valist (DBusMessage *message,
break;
}
+ case DBUS_TYPE_BOOLEAN_ARRAY:
+ {
+ unsigned char **ptr;
+ int *len;
+
+ ptr = va_arg (var_args, unsigned char **);
+ len = va_arg (var_args, int *);
+
+ if (!dbus_message_iter_get_boolean_array (iter, ptr, len))
+ return DBUS_RESULT_NO_MEMORY;
+
+ break;
+ }
+
case DBUS_TYPE_INT32_ARRAY:
{
dbus_int32_t **ptr;
@@ -1740,7 +1832,7 @@ dbus_message_iter_get_arg_type (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* a string value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the string
*/
@@ -1754,17 +1846,41 @@ dbus_message_iter_get_string (DBusMessageIter *iter)
}
/**
+ * Returns the boolean value that an iterator may point to.
+ * Note that you need to check that the iterator points to
+ * a boolean value before using this function.
+ *
+ * @see dbus_message_iter_get_arg_type
+ * @param iter the message iter
+ * @returns the string
+ */
+unsigned char
+dbus_message_iter_get_boolean (DBusMessageIter *iter)
+{
+ unsigned char value;
+
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BOOLEAN);
+
+ value = _dbus_string_get_byte (&iter->message->body, iter->pos + 1);
+ iter->pos += 2;
+
+ return value;
+}
+
+/**
* Returns the 32 bit signed integer value that an iterator may point to.
* Note that you need to check that the iterator points to
* an integer value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the integer
*/
int
dbus_message_iter_get_int32 (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_INT32);
+
return _dbus_demarshal_int32 (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
@@ -1774,13 +1890,15 @@ dbus_message_iter_get_int32 (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* an unsigned integer value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the integer
*/
int
dbus_message_iter_get_uint32 (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_UINT32);
+
return _dbus_demarshal_uint32 (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
@@ -1790,18 +1908,46 @@ dbus_message_iter_get_uint32 (DBusMessageIter *iter)
* Note that you need to check that the iterator points to
* a string value before using this function.
*
- * @see dbus_message_iter_get_field_type
+ * @see dbus_message_iter_get_arg_type
* @param iter the message iter
* @returns the double
*/
double
dbus_message_iter_get_double (DBusMessageIter *iter)
{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_DOUBLE);
+
return _dbus_demarshal_double (&iter->message->body, iter->message->byte_order,
iter->pos + 1, NULL);
}
/**
+ * Returns the boolean array that the iterator may point to. Note that
+ * you need to check that the iterator points to an array of the
+ * correct type prior to using this function.
+ *
+ * @param iter the iterator
+ * @param value return location for the array
+ * @param len return location for the array length
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+dbus_message_iter_get_boolean_array (DBusMessageIter *iter,
+ unsigned char **value,
+ int *len)
+{
+ _dbus_assert (dbus_message_iter_get_arg_type (iter) == DBUS_TYPE_BOOLEAN_ARRAY);
+
+ *value = _dbus_demarshal_byte_array (&iter->message->body, iter->message->byte_order,
+ iter->pos + 1, NULL, len);
+
+ if (!*value)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+/**
* Returns the 32 bit signed integer array that the iterator may point
* to. Note that you need to check that the iterator points to an
* array of the correct type prior to using this function.
@@ -2668,7 +2814,7 @@ message_iter_test (DBusMessage *message)
if (dbus_message_iter_get_arg_type (iter) != DBUS_TYPE_UINT32)
_dbus_assert_not_reached ("Argument type isn't int32");
- if (dbus_message_iter_get_int32 (iter) != 0xedd1e)
+ if (dbus_message_iter_get_uint32 (iter) != 0xedd1e)
_dbus_assert_not_reached ("Unsigned integers differ");
if (!dbus_message_iter_next (iter))