Commit 61411a06 authored by Colin Walters's avatar Colin Walters

2005-05-11 Colin Walters <walters@verbum.org>

	* dbus/dbus-signature.c (dbus_signature_iter_get_signature):
	New function, returns signature string for signature iter.
	* dbus/dbus-signature.h: Prototype it.
	* dbus/dbus-message.c (dbus_message_iter_get_signature):
	New function, returns signature string for message iter.
	(dbus_message_iter_get_array_len): New function, returns
	length of array.
	(dbus_message_iter_get_fixed_array): Fix assertion; this
	function should be used when the iter is pointing to the
	contents of an array
	* dbus/dbus-message.h: Prototypes.
	* dbus/dbus-marshal-recursive.c (_dbus_type_reader_get_array_length):
	New function; returns length of an array.
	* dbus/dbus-marshal-recursive.h: Prototype it.
parent ca01b211
......@@ -985,6 +985,21 @@ _dbus_type_reader_read_basic (const DBusTypeReader *reader,
#endif
}
/**
* Returns the number of values remaining in the current array reader.
*
* @param reader the reader to read from
* @returns the number of elements remaining in the array
*/
int
_dbus_type_reader_get_array_length (const DBusTypeReader *reader)
{
_dbus_assert (!reader->klass->types_only);
_dbus_assert (reader->klass == &array_reader_class);
return array_reader_get_array_len (reader);
}
/**
* Reads a block of fixed-length basic values, from the current point
* in an array to the end of the array. Does not work for arrays of
......
......@@ -146,6 +146,7 @@ int _dbus_type_reader_get_element_type (const DBusTypeReader *
int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
void *value);
int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
void *value,
int *n_elements);
......
......@@ -1612,6 +1612,41 @@ dbus_message_iter_recurse (DBusMessageIter *iter,
_dbus_type_reader_recurse (&real->u.reader, &real_sub->u.reader);
}
/**
* Returns the current signature of a message iterator. This
* is useful primarily for dealing with variants; one can
* recurse into a variant and determine the signature of
* the variant's value.
*
* @param iter the message iterator
* @returns the contained signature, or NULL if out of memory
*/
char *
dbus_message_iter_get_signature (DBusMessageIter *iter)
{
const DBusString *sig;
DBusString retstr;
char *ret;
int start, len;
DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
_dbus_return_val_if_fail (_dbus_message_iter_check (real), NULL);
if (!_dbus_string_init (&retstr))
return NULL;
_dbus_type_reader_get_signature (&real->u.reader, &sig,
&start, &len);
if (!_dbus_string_append_len (&retstr,
_dbus_string_get_const_data (sig) + start,
len))
return NULL;
if (!_dbus_string_steal_data (&retstr, &ret))
return NULL;
_dbus_string_free (&retstr);
return ret;
}
/**
* Reads a basic-typed value from the message iterator.
* Basic types are the non-containers such as integer and string.
......@@ -1660,6 +1695,22 @@ dbus_message_iter_get_basic (DBusMessageIter *iter,
value);
}
/**
* Returns the number of elements in the array;
*
* @param iter the iterator
* @returns the number of elements in the array
*/
int
dbus_message_iter_get_array_len (DBusMessageIter *iter)
{
DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
_dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
return _dbus_type_reader_get_array_length (&real->u.reader);
}
/**
* Reads a block of fixed-length values from the message iterator.
* Fixed-length values are those basic types that are not string-like,
......@@ -1686,7 +1737,7 @@ dbus_message_iter_get_fixed_array (DBusMessageIter *iter,
_dbus_return_if_fail (_dbus_message_iter_check (real));
_dbus_return_if_fail (value != NULL);
_dbus_return_if_fail (dbus_type_is_fixed (_dbus_type_reader_get_element_type (&real->u.reader)));
_dbus_return_if_fail (dbus_type_is_fixed (_dbus_type_reader_get_current_type (&real->u.reader)));
_dbus_type_reader_read_fixed_multi (&real->u.reader,
value, n_elements);
......
......@@ -150,12 +150,14 @@ dbus_bool_t dbus_message_iter_init (DBusMessage *message,
DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
char* dbus_message_iter_get_signature (DBusMessageIter *iter);
int dbus_message_iter_get_arg_type (DBusMessageIter *iter);
int dbus_message_iter_get_element_type (DBusMessageIter *iter);
void dbus_message_iter_recurse (DBusMessageIter *iter,
DBusMessageIter *sub);
void dbus_message_iter_get_basic (DBusMessageIter *iter,
void *value);
int dbus_message_iter_get_array_len (DBusMessageIter *iter);
void dbus_message_iter_get_fixed_array (DBusMessageIter *iter,
void *value,
int *n_elements);
......
......@@ -81,6 +81,36 @@ dbus_signature_iter_get_current_type (const DBusSignatureIter *iter)
return _dbus_first_type_in_signature_c_str (real_iter->pos, 0);
}
/**
* Returns the full type signature represented by the current
* iterator as a C string.
*
* @param iter pointer to an iterator
* @returns current signature; or NULL on OOM. Should be freed with #dbus_free
*/
char *
dbus_signature_iter_get_signature (const DBusSignatureIter *iter)
{
DBusSignatureRealIter *real_iter = (DBusSignatureRealIter *) iter;
DBusString str;
char *ret;
int pos;
if (!_dbus_string_init (&str))
return NULL;
pos = 0;
_dbus_type_signature_next (real_iter->pos, &pos);
if (!_dbus_string_append_len (&str, real_iter->pos, pos))
return NULL;
if (!_dbus_string_steal_data (&str, &ret))
ret = NULL;
_dbus_string_free (&str);
return ret;
}
/**
* Convenience function for returning the element type of an array;
* This function allows you to avoid initializing a sub-iterator and
......
......@@ -50,6 +50,8 @@ void dbus_signature_iter_init (DBusSignatureIter *i
int dbus_signature_iter_get_current_type (const DBusSignatureIter *iter);
char * dbus_signature_iter_get_signature (const DBusSignatureIter *iter);
int dbus_signature_iter_get_element_type (const DBusSignatureIter *iter);
dbus_bool_t dbus_signature_iter_next (DBusSignatureIter *iter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment