summaryrefslogtreecommitdiff
path: root/gobject
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-09-29 14:52:42 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-09-29 14:52:42 +0000
commit2aa3d50768afc2cc34d2fa7e87263cd78fff53b4 (patch)
tree72d5a583f9b5c30f9a3eb79569c68e776f0cbae2 /gobject
parentdc5ce54a5fc8784fd79a433dfcf265dacda74e57 (diff)
Add g_type_default_interface_ref/peek/unref for accessing the default
Mon Sep 29 10:51:01 2003 Owen Taylor <otaylor@redhat.com> * gtype.[ch]: Add g_type_default_interface_ref/peek/unref for accessing the default vtable of an interface.
Diffstat (limited to 'gobject')
-rw-r--r--gobject/ChangeLog5
-rw-r--r--gobject/gtype.c63
-rw-r--r--gobject/gtype.h4
3 files changed, 72 insertions, 0 deletions
diff --git a/gobject/ChangeLog b/gobject/ChangeLog
index a21ec5700..2b5633684 100644
--- a/gobject/ChangeLog
+++ b/gobject/ChangeLog
@@ -1,3 +1,8 @@
+Mon Sep 29 10:51:01 2003 Owen Taylor <otaylor@redhat.com>
+
+ * gtype.[ch]: Add g_type_default_interface_ref/peek/unref
+ for accessing the default vtable of an interface.
+
Fri Sep 26 17:24:53 2003 Owen Taylor <otaylor@redhat.com>
* gtype.c (g_type_instance_get_private): You can
diff --git a/gobject/gtype.c b/gobject/gtype.c
index 1339b0644..0ffdb6e55 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -2486,6 +2486,69 @@ g_type_interface_peek_parent (gpointer g_iface)
return vtable;
}
+gpointer
+g_type_default_interface_ref (GType g_type)
+{
+ TypeNode *node;
+
+ G_WRITE_LOCK (&type_rw_lock);
+
+ node = lookup_type_node_I (g_type);
+ if (!node || !NODE_IS_IFACE (node) ||
+ (node->data && node->data->common.ref_count < 1))
+ {
+ G_WRITE_UNLOCK (&type_rw_lock);
+ g_warning ("cannot retrieve default vtable for invalid or non-interface type '%s'",
+ type_descriptive_name_I (g_type));
+ return NULL;
+ }
+
+ type_data_ref_Wm (node);
+
+ type_iface_ensure_dflt_vtable_Wm (node);
+
+ G_WRITE_UNLOCK (&type_rw_lock);
+
+ return node->data->iface.dflt_vtable;
+}
+
+gpointer
+g_type_default_interface_peek (GType g_type)
+{
+ TypeNode *node;
+ gpointer vtable;
+
+ node = lookup_type_node_I (g_type);
+ G_READ_LOCK (&type_rw_lock);
+ if (node && NODE_IS_IFACE (node) && node->data && node->data->iface.dflt_vtable)
+ vtable = node->data->iface.dflt_vtable;
+ else
+ vtable = NULL;
+ G_READ_UNLOCK (&type_rw_lock);
+
+ return vtable;
+}
+
+void
+g_type_default_interface_unref (gpointer g_iface)
+{
+ TypeNode *node;
+ GTypeInterface *vtable = g_iface;
+
+ g_return_if_fail (g_iface != NULL);
+
+ node = lookup_type_node_I (vtable->g_type);
+ G_WRITE_LOCK (&type_rw_lock);
+ if (node && NODE_IS_IFACE (node) &&
+ node->data->iface.dflt_vtable == g_iface &&
+ node->data->common.ref_count > 0)
+ type_data_unref_Wm (node, FALSE);
+ else
+ g_warning ("cannot unreference invalid interface default vtable for '%s'",
+ type_descriptive_name_I (vtable->g_type));
+ G_WRITE_UNLOCK (&type_rw_lock);
+}
+
G_CONST_RETURN gchar*
g_type_name (GType type)
{
diff --git a/gobject/gtype.h b/gobject/gtype.h
index c762c804a..68f52128b 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -183,6 +183,10 @@ gpointer g_type_interface_peek (gpointer instance_
GType iface_type);
gpointer g_type_interface_peek_parent (gpointer g_iface);
+gpointer g_type_default_interface_ref (GType g_type);
+gpointer g_type_default_interface_peek (GType g_type);
+void g_type_default_interface_unref (gpointer g_iface);
+
/* g_free() the returned arrays */
GType* g_type_children (GType type,
guint *n_children);