diff options
author | Colin Walters <walters@verbum.org> | 2005-05-11 18:07:22 +0000 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2005-05-11 18:07:22 +0000 |
commit | 61411a061c09def43687153e6c734ff27b7fd556 (patch) | |
tree | 486ef0556c8c5cd6bfd572b8a746f21c19f272a8 /dbus | |
parent | ca01b211125953bdada46b16729e156a3c365a79 (diff) |
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.
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-marshal-recursive.c | 15 | ||||
-rw-r--r-- | dbus/dbus-marshal-recursive.h | 1 | ||||
-rw-r--r-- | dbus/dbus-message.c | 53 | ||||
-rw-r--r-- | dbus/dbus-message.h | 2 | ||||
-rw-r--r-- | dbus/dbus-signature.c | 30 | ||||
-rw-r--r-- | dbus/dbus-signature.h | 2 |
6 files changed, 102 insertions, 1 deletions
diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c index 6fcbd623..1427a803 100644 --- a/dbus/dbus-marshal-recursive.c +++ b/dbus/dbus-marshal-recursive.c @@ -986,6 +986,21 @@ _dbus_type_reader_read_basic (const DBusTypeReader *reader, } /** + * 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 * string or container types. diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h index 779e449a..328741ac 100644 --- a/dbus/dbus-marshal-recursive.h +++ b/dbus/dbus-marshal-recursive.h @@ -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); diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c index 8a9014ca..d9a5234f 100644 --- a/dbus/dbus-message.c +++ b/dbus/dbus-message.c @@ -1613,6 +1613,41 @@ dbus_message_iter_recurse (DBusMessageIter *iter, } /** + * 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. * @@ -1661,6 +1696,22 @@ dbus_message_iter_get_basic (DBusMessageIter *iter, } /** + * 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, * such as integers, bool, double. The block read will be from the @@ -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); diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h index 421ed6ba..6124e253 100644 --- a/dbus/dbus-message.h +++ b/dbus/dbus-message.h @@ -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); diff --git a/dbus/dbus-signature.c b/dbus/dbus-signature.c index 7cbae7c2..7118bd25 100644 --- a/dbus/dbus-signature.c +++ b/dbus/dbus-signature.c @@ -82,6 +82,36 @@ dbus_signature_iter_get_current_type (const DBusSignatureIter *iter) } /** + * 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 * getting its current type. diff --git a/dbus/dbus-signature.h b/dbus/dbus-signature.h index fd64ed11..2da19c4d 100644 --- a/dbus/dbus-signature.h +++ b/dbus/dbus-signature.h @@ -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); |