Commit a5be0729 authored by Christian Hergert's avatar Christian Hergert
Browse files

object: add ide_object_hold() and ide_object_release()

These functions are convenience functions around ide_context_hold() and
ide_context_release().
parent 653dcd7f
......@@ -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);
}
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment