Add g_type_default_interface_ref/peek/unref for accessing the default
authorOwen Taylor <otaylor@redhat.com>
Mon, 29 Sep 2003 14:52:42 +0000 (14:52 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Mon, 29 Sep 2003 14:52:42 +0000 (14:52 +0000)
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.

gobject/ChangeLog
gobject/gtype.c
gobject/gtype.h

index a21ec5700235c4fe8c08e7b78061769314ed5f19..2b56336846488243cd7dbb0db53d6f73b36a6943 100644 (file)
@@ -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
index 1339b0644f547802a844a4e85d4623f32351b111..0ffdb6e554594abed75b583d51c8391c3705151e 100644 (file)
@@ -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)
 {
index c762c804a1a60a0ed4b40f22566d19208151fe7c..68f52128baf0e0e66f7f08ce0f30651f098a5866 100644 (file)
@@ -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);