dbus/dbus dbus-message-util.c,1.7,1.8 dbus-message.c,1.162,1.163
Havoc Pennington
hp at freedesktop.org
Thu Feb 10 15:17:29 PST 2005
Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv19867/dbus
Modified Files:
dbus-message-util.c dbus-message.c
Log Message:
2005-02-10 Havoc Pennington <hp at redhat.com>
* dbus/dbus-message-util.c (verify_test_message): tests for string
array
* dbus/dbus-message.c (dbus_message_append_args_valist): add
support for arrays of string/signature/path
Index: dbus-message-util.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message-util.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbus-message-util.c 6 Feb 2005 04:21:57 -0000 1.7
+++ dbus-message-util.c 10 Feb 2005 23:17:27 -0000 1.8
@@ -733,6 +733,8 @@
int our_byte_array_len;
const dbus_bool_t *our_boolean_array = (void*)0xdeadbeef;
int our_boolean_array_len;
+ char **our_string_array;
+ int our_string_array_len;
dbus_message_iter_init (message, &iter);
@@ -767,6 +769,8 @@
&our_byte_array, &our_byte_array_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN,
&our_boolean_array, &our_boolean_array_len,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array, &our_string_array_len,
0))
{
_dbus_warn ("error: %s - %s\n", error.name,
@@ -874,6 +878,17 @@
our_boolean_array[4] != FALSE)
_dbus_assert_not_reached ("bool array had wrong values");
+ if (our_string_array_len != 4)
+ _dbus_assert_not_reached ("string array was wrong length");
+
+ if (strcmp (our_string_array[0], "Foo") != 0 ||
+ strcmp (our_string_array[1], "bar") != 0 ||
+ strcmp (our_string_array[2], "") != 0 ||
+ strcmp (our_string_array[3], "woo woo woo woo") != 0)
+ _dbus_assert_not_reached ("string array had wrong values");
+
+ dbus_free_string_array (our_string_array);
+
if (dbus_message_iter_next (&iter))
_dbus_assert_not_reached ("Didn't reach end of arguments");
}
@@ -1080,6 +1095,8 @@
_DBUS_N_ELEMENTS (our_byte_array),
DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN,
_DBUS_N_ELEMENTS (our_boolean_array),
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
+ _DBUS_N_ELEMENTS (our_string_array),
DBUS_TYPE_INVALID);
i = 0;
@@ -1112,7 +1129,9 @@
sig[i++] = DBUS_TYPE_BYTE;
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_BOOLEAN;
- sig[i++] = DBUS_TYPE_INVALID;
+ sig[i++] = DBUS_TYPE_ARRAY;
+ sig[i++] = DBUS_TYPE_STRING;
+ sig[i++] = DBUS_TYPE_INVALID;
_dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- dbus-message.c 10 Feb 2005 04:36:23 -0000 1.162
+++ dbus-message.c 10 Feb 2005 23:17:27 -0000 1.163
@@ -1180,6 +1180,9 @@
* The last argument to this function must be #DBUS_TYPE_INVALID,
* marking the end of the argument list.
*
+ * String/signature/path arrays should be passed in as "const char***
+ * address_of_array" and "int n_elements"
+ *
* @todo support DBUS_TYPE_STRUCT and DBUS_TYPE_VARIANT and complex arrays
*
* @todo If this fails due to lack of memory, the message is hosed and
@@ -1252,26 +1255,11 @@
else if (type == DBUS_TYPE_ARRAY)
{
int element_type;
- const DBusBasicValue **value;
- int n_elements;
DBusMessageIter array;
char buf[2];
element_type = va_arg (var_args, int);
-
-#ifndef DBUS_DISABLE_CHECKS
- if (!_dbus_type_is_fixed (element_type))
- {
- _dbus_warn ("arrays of %s can't be appended with %s for now\n",
- _dbus_type_to_string (element_type),
- _DBUS_FUNCTION_NAME);
- goto failed;
- }
-#endif
-
- value = va_arg (var_args, const DBusBasicValue**);
- n_elements = va_arg (var_args, int);
-
+
buf[0] = element_type;
buf[1] = '\0';
if (!dbus_message_iter_open_container (&iter,
@@ -1279,12 +1267,52 @@
buf,
&array))
goto failed;
+
+ if (_dbus_type_is_fixed (element_type))
+ {
+ const DBusBasicValue **value;
+ int n_elements;
- if (!dbus_message_iter_append_fixed_array (&array,
- element_type,
- value,
- n_elements))
- goto failed;
+ value = va_arg (var_args, const DBusBasicValue**);
+ n_elements = va_arg (var_args, int);
+
+ if (!dbus_message_iter_append_fixed_array (&array,
+ element_type,
+ value,
+ n_elements))
+ goto failed;
+ }
+ else if (element_type == DBUS_TYPE_STRING ||
+ element_type == DBUS_TYPE_SIGNATURE ||
+ element_type == DBUS_TYPE_OBJECT_PATH)
+ {
+ const char ***value_p;
+ const char **value;
+ int n_elements;
+ int i;
+
+ value_p = va_arg (var_args, const char***);
+ n_elements = va_arg (var_args, int);
+
+ value = *value_p;
+
+ i = 0;
+ while (i < n_elements)
+ {
+ if (!dbus_message_iter_append_basic (&array,
+ element_type,
+ &value[i]))
+ goto failed;
+ ++i;
+ }
+ }
+ else
+ {
+ _dbus_warn ("arrays of %s can't be appended with %s for now\n",
+ _dbus_type_to_string (element_type),
+ _DBUS_FUNCTION_NAME);
+ goto failed;
+ }
if (!dbus_message_iter_close_container (&iter, &array))
goto failed;
@@ -1318,7 +1346,8 @@
* In addition to those types, arrays of string, object path, and
* signature are supported; but these are returned as allocated memory
* and must be freed with dbus_free_string_array(), while the other
- * types are returned as const references.
+ * types are returned as const references. To get a string array
+ * pass in "char ***array_location" and "int *n_elements"
*
* The variable argument list should contain the type of the argument
* followed by a pointer to where the value should be stored. The list
More information about the dbus-commit
mailing list