dbus/dbus dbus-signature.h, 1.2, 1.3 dbus-signature.c, 1.3, 1.4 dbus-message.h, 1.59, 1.60 dbus-message.c, 1.168, 1.169 dbus-marshal-recursive.h, 1.29, 1.30 dbus-marshal-recursive.c, 1.49, 1.50

Colin Walters walters at freedesktop.org
Wed May 11 11:07:24 PDT 2005


Update of /cvs/dbus/dbus/dbus
In directory gabe:/tmp/cvs-serv16312/dbus

Modified Files:
	dbus-signature.h dbus-signature.c dbus-message.h 
	dbus-message.c dbus-marshal-recursive.h 
	dbus-marshal-recursive.c 
Log Message:
2005-05-11  Colin Walters  <walters at 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.


Index: dbus-signature.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-signature.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-signature.h	9 Mar 2005 17:09:11 -0000	1.2
+++ dbus-signature.h	11 May 2005 18:07:22 -0000	1.3
@@ -50,6 +50,8 @@
 
 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);

Index: dbus-signature.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-signature.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbus-signature.c	9 Mar 2005 17:09:11 -0000	1.3
+++ dbus-signature.c	11 May 2005 18:07:22 -0000	1.4
@@ -82,6 +82,36 @@
 }
 
 /**
+ * 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.

Index: dbus-message.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- dbus-message.h	18 Jan 2005 20:42:15 -0000	1.59
+++ dbus-message.h	11 May 2005 18:07:22 -0000	1.60
@@ -150,12 +150,14 @@
                                                 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);

Index: dbus-message.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-message.c,v
retrieving revision 1.168
retrieving revision 1.169
diff -u -d -r1.168 -r1.169
--- dbus-message.c	24 Apr 2005 14:04:16 -0000	1.168
+++ dbus-message.c	11 May 2005 18:07:22 -0000	1.169
@@ -1613,6 +1613,41 @@
 }
 
 /**
+ * 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 @@
 }
 
 /**
+ * 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_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);

Index: dbus-marshal-recursive.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- dbus-marshal-recursive.h	24 Feb 2005 16:03:56 -0000	1.29
+++ dbus-marshal-recursive.h	11 May 2005 18:07:22 -0000	1.30
@@ -146,6 +146,7 @@
 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);

Index: dbus-marshal-recursive.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-marshal-recursive.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- dbus-marshal-recursive.c	9 Mar 2005 17:09:11 -0000	1.49
+++ dbus-marshal-recursive.c	11 May 2005 18:07:22 -0000	1.50
@@ -986,6 +986,21 @@
 }
 
 /**
+ * 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.



More information about the dbus-commit mailing list