[Telepathy-commits] [telepathy-glib/master] dbus: add tp_g_value_slice_new_bytes() etc.
Simon McVittie
simon.mcvittie at collabora.co.uk
Wed Mar 4 08:02:13 PST 2009
The versions for byte-arrays have a slight inconsistency in the signature
of ..._new_bytes so that bytes from non-GArray data structures can be
copied in.
The versions for object paths check that the object path is non-NULL and
valid.
---
telepathy-glib/dbus.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++
telepathy-glib/dbus.h | 6 +++
2 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/telepathy-glib/dbus.c b/telepathy-glib/dbus.c
index 28a109e..e7a42ca 100644
--- a/telepathy-glib/dbus.c
+++ b/telepathy-glib/dbus.c
@@ -1229,6 +1229,121 @@ tp_dbus_daemon_class_init (TpDBusDaemonClass *klass)
/**
+ * tp_g_value_slice_new_bytes:
+ * @bytes: location of an array of bytes to be copied (this may be %NULL
+ * if and only if length is 0)
+ * @length: number of bytes to copy
+ *
+ * Slice-allocate a #GValue containing a byte-array, using
+ * tp_g_value_slice_new_boxed(). This function is convenient to use when
+ * constructing hash tables from string to #GValue, for example.
+ *
+ * Returns: a #GValue of type %DBUS_TYPE_G_UCHAR_ARRAY whose value is a copy
+ * of @length bytes from @bytes, to be freed with tp_g_value_slice_free() or
+ * g_slice_free()
+ *
+ * Since: 0.7.UNRELEASED
+ */
+GValue *
+tp_g_value_slice_new_bytes (gconstpointer bytes,
+ gsize length)
+{
+ GArray *arr;
+
+ g_return_val_if_fail (length == 0 || bytes != NULL, NULL);
+ arr = g_array_sized_new (FALSE, FALSE, 1, length);
+
+ if (length > 0)
+ g_array_append_vals (arr, bytes, length);
+
+ return tp_g_value_slice_new_take_boxed (DBUS_TYPE_G_UCHAR_ARRAY, arr);
+}
+
+/**
+ * tp_g_value_slice_new_take_bytes:
+ * @bytes: a non-NULL #GArray of guchar, ownership of which will be taken by
+ * the #GValue
+ *
+ * Slice-allocate a #GValue containing @bytes, using
+ * tp_g_value_slice_new_boxed(). This function is convenient to use when
+ * constructing hash tables from string to #GValue, for example.
+ *
+ * Returns: a #GValue of type %DBUS_TYPE_G_UCHAR_ARRAY whose value is
+ * @bytes, to be freed with tp_g_value_slice_free() or
+ * g_slice_free()
+ *
+ * Since: 0.7.UNRELEASED
+ */
+GValue *
+tp_g_value_slice_new_take_bytes (GArray *bytes)
+{
+ g_return_val_if_fail (bytes != NULL, NULL);
+ return tp_g_value_slice_new_take_boxed (DBUS_TYPE_G_UCHAR_ARRAY, bytes);
+}
+
+/**
+ * tp_g_value_slice_new_object_path:
+ * @path: a valid D-Bus object path which will be copied
+ *
+ * Slice-allocate a #GValue containing an object path, using
+ * tp_g_value_slice_new_boxed(). This function is convenient to use when
+ * constructing hash tables from string to #GValue, for example.
+ *
+ * Returns: a #GValue of type %DBUS_TYPE_G_OBJECT_PATH whose value is a copy
+ * of @path, to be freed with tp_g_value_slice_free() or g_slice_free()
+ *
+ * Since: 0.7.UNRELEASED
+ */
+GValue *
+tp_g_value_slice_new_object_path (const gchar *path)
+{
+ g_return_val_if_fail (tp_dbus_check_valid_object_path (path, NULL), NULL);
+ return tp_g_value_slice_new_boxed (DBUS_TYPE_G_OBJECT_PATH, path);
+}
+
+/**
+ * tp_g_value_slice_new_static_object_path:
+ * @path: a valid D-Bus object path which must remain valid forever
+ *
+ * Slice-allocate a #GValue containing an object path, using
+ * tp_g_value_slice_new_static_boxed(). This function is convenient to use when
+ * constructing hash tables from string to #GValue, for example.
+ *
+ * Returns: a #GValue of type %DBUS_TYPE_G_OBJECT_PATH whose value is @path,
+ * to be freed with tp_g_value_slice_free() or g_slice_free()
+ *
+ * Since: 0.7.UNRELEASED
+ */
+GValue *
+tp_g_value_slice_new_static_object_path (const gchar *path)
+{
+ g_return_val_if_fail (tp_dbus_check_valid_object_path (path, NULL), NULL);
+ return tp_g_value_slice_new_static_boxed (DBUS_TYPE_G_OBJECT_PATH, path);
+}
+
+/**
+ * tp_g_value_slice_new_take_object_path:
+ * @path: a valid D-Bus object path which will be freed with g_free() by the
+ * returned #GValue (the caller must own it before calling this function, but
+ * no longer owns it after this function returns)
+ *
+ * Slice-allocate a #GValue containing an object path, using
+ * tp_g_value_slice_new_take_boxed(). This function is convenient to use when
+ * constructing hash tables from string to #GValue, for example.
+ *
+ * Returns: a #GValue of type %DBUS_TYPE_G_OBJECT_PATH whose value is @path,
+ * to be freed with tp_g_value_slice_free() or g_slice_free()
+ *
+ * Since: 0.7.UNRELEASED
+ */
+GValue *
+tp_g_value_slice_new_take_object_path (gchar *path)
+{
+ g_return_val_if_fail (tp_dbus_check_valid_object_path (path, NULL), NULL);
+ return tp_g_value_slice_new_take_boxed (DBUS_TYPE_G_OBJECT_PATH, path);
+}
+
+/**
* tp_asv_get_boolean:
* @asv: A GHashTable where the keys are strings and the values are GValues
* @key: The key to look up
diff --git a/telepathy-glib/dbus.h b/telepathy-glib/dbus.h
index 3be2bee..e94796c 100644
--- a/telepathy-glib/dbus.h
+++ b/telepathy-glib/dbus.h
@@ -88,6 +88,12 @@ gboolean tp_dbus_check_valid_member_name (const gchar *name,
gboolean tp_dbus_check_valid_object_path (const gchar *path,
GError **error);
+GValue *tp_g_value_slice_new_bytes (gconstpointer bytes, gsize length);
+GValue *tp_g_value_slice_new_take_bytes (GArray *bytes);
+GValue *tp_g_value_slice_new_object_path (const gchar *path);
+GValue *tp_g_value_slice_new_static_object_path (const gchar *path);
+GValue *tp_g_value_slice_new_take_object_path (gchar *path);
+
#define tp_asv_size(asv) _tp_asv_size_inline (asv)
static inline guint
--
1.5.6.5
More information about the telepathy-commits
mailing list