Commit 622a92a1 authored by Christian Hergert's avatar Christian Hergert
Browse files

object: add ide_object_notify_in_main()

This helper will do a g_object_notify_by_pspec() from the main thread.
Useful for thread-safe objects that want to notify.

We should consider warning if not explicit notify.
parent 6004efc3
......@@ -573,3 +573,43 @@ ide_object_release (IdeObject *self)
ide_context_release (priv->context);
}
static gboolean
ide_object_notify_in_main_cb (gpointer data)
{
struct {
GObject *object;
GParamSpec *pspec;
} *notify = data;
g_assert (notify != NULL);
g_assert (G_IS_OBJECT (notify->object));
g_assert (notify->pspec != NULL);
g_object_notify_by_pspec (notify->object, notify->pspec);
g_object_unref (notify->object);
g_param_spec_unref (notify->pspec);
g_slice_free1 (sizeof *notify, notify);
return G_SOURCE_REMOVE;
}
void
ide_object_notify_in_main (gpointer instance,
GParamSpec *pspec)
{
struct {
GObject *object;
GParamSpec *pspec;
} *notify;
g_return_if_fail (G_IS_OBJECT (instance));
g_return_if_fail (pspec != NULL);
notify = g_slice_alloc0 (sizeof *notify);
notify->object = g_object_ref (instance);
notify->pspec = g_param_spec_ref (pspec);
g_timeout_add (0, ide_object_notify_in_main_cb, notify);
}
......@@ -38,30 +38,31 @@ struct _IdeObjectClass
IdeContext *context);
};
IdeContext *ide_object_get_context (IdeObject *self);
void ide_object_set_context (IdeObject *self,
IdeContext *context);
void ide_object_new_for_extension_async
(GType interface_gtype,
GCompareDataFunc sort_priority_func,
gpointer sort_proirity_data,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
const gchar *first_property,
...);
void ide_object_new_async (const gchar *extension_point,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
const gchar *first_property,
...);
IdeObject *ide_object_new_finish (GAsyncResult *result,
GError **error);
gboolean ide_object_hold (IdeObject *self);
void ide_object_release (IdeObject *self);
IdeContext *ide_object_get_context (IdeObject *self);
void ide_object_set_context (IdeObject *self,
IdeContext *context);
void ide_object_new_for_extension_async (GType interface_gtype,
GCompareDataFunc sort_priority_func,
gpointer sort_proirity_data,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
const gchar *first_property,
...);
void ide_object_new_async (const gchar *extension_point,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
const gchar *first_property,
...);
IdeObject *ide_object_new_finish (GAsyncResult *result,
GError **error);
gboolean ide_object_hold (IdeObject *self);
void ide_object_release (IdeObject *self);
void ide_object_notify_in_main (gpointer instance,
GParamSpec *pspec);
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