[gnome-builder] object: add ide_object_hold() and ide_object_release()



commit a5be07296f301728eaf6cf7e7413a3294bd95bb7
Author: Christian Hergert <christian hergert me>
Date:   Wed May 13 21:43:18 2015 -0700

    object: add ide_object_hold() and ide_object_release()
    
    These functions are convenience functions around ide_context_hold() and
    ide_context_release().

 libide/ide-object.c |   56 ++++++++++++++++++++++++++++++++++++++++++++++++--
 libide/ide-object.h |    4 ++-
 2 files changed, 56 insertions(+), 4 deletions(-)
---
diff --git a/libide/ide-object.c b/libide/ide-object.c
index 0c9f790..cb41313 100644
--- a/libide/ide-object.c
+++ b/libide/ide-object.c
@@ -92,11 +92,11 @@ ide_object_release_context (gpointer  data,
  * Returns: (transfer none): An #IdeContext.
  */
 IdeContext *
-ide_object_get_context (IdeObject *object)
+ide_object_get_context (IdeObject *self)
 {
-  IdeObjectPrivate *priv = ide_object_get_instance_private (object);
+  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
 
-  g_return_val_if_fail (IDE_IS_OBJECT (object), NULL);
+  g_return_val_if_fail (IDE_IS_OBJECT (self), NULL);
 
   return priv->context;
 }
@@ -363,3 +363,53 @@ ide_object_new_finish  (GAsyncResult  *result,
 
   return g_task_propagate_pointer (task, error);
 }
+
+/**
+ * ide_object_hold:
+ * @self: the #IdeObject
+ *
+ * This function will acquire a reference to the IdeContext that the object
+ * is a part of. This is useful if you are going to be doing a long running
+ * task (such as something in a thread) and want to ensure the context cannot
+ * be unloaded during your operation.
+ *
+ * You should call ide_object_release() an equivalent number of times to
+ * ensure the context may be freed afterwards.
+ */
+void
+ide_object_hold (IdeObject *self)
+{
+  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_OBJECT (self));
+
+  if (priv->context == NULL)
+    {
+      g_warning ("BUG: Cannot hold context, already disposed.");
+      return;
+    }
+
+  ide_context_hold (priv->context);
+}
+
+/**
+ * ide_object_release:
+ * @self: the #IdeObject.
+ *
+ * Releases a hold on the context previously called with ide_object_hold().
+ */
+void
+ide_object_release (IdeObject *self)
+{
+  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_OBJECT (self));
+
+  if (priv->context == NULL)
+    {
+      g_warning ("BUG: Cannot release context, already disposed.");
+      return;
+    }
+
+  ide_context_release (priv->context);
+}
diff --git a/libide/ide-object.h b/libide/ide-object.h
index c36f7a7..d1e768c 100644
--- a/libide/ide-object.h
+++ b/libide/ide-object.h
@@ -36,7 +36,7 @@ struct _IdeObjectClass
   void (*destroy) (IdeObject *self);
 };
 
-IdeContext *ide_object_get_context (IdeObject            *object);
+IdeContext *ide_object_get_context (IdeObject            *self);
 void        ide_object_new_async   (const gchar          *extension_point,
                                     int                   io_priority,
                                     GCancellable         *cancellable,
@@ -46,6 +46,8 @@ void        ide_object_new_async   (const gchar          *extension_point,
                                     ...);
 IdeObject  *ide_object_new_finish  (GAsyncResult         *result,
                                     GError              **error);
+void        ide_object_hold        (IdeObject            *self);
+void        ide_object_release     (IdeObject            *self);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]