[gnome-builder/wip/chergert/perspective] object: add ide_object_notify_in_main()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/perspective] object: add ide_object_notify_in_main()
- Date: Thu, 17 Dec 2015 12:05:46 +0000 (UTC)
commit e9798c872793f7a887e40431c79c9176e77b9371
Author: Christian Hergert <chergert redhat com>
Date: Thu Dec 17 03:57:35 2015 -0800
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.
libide/ide-object.c | 40 ++++++++++++++++++++++++++++++++++++++++
libide/ide-object.h | 49 +++++++++++++++++++++++++------------------------
2 files changed, 65 insertions(+), 24 deletions(-)
---
diff --git a/libide/ide-object.c b/libide/ide-object.c
index 4c0d602..da347a7 100644
--- a/libide/ide-object.c
+++ b/libide/ide-object.c
@@ -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);
+}
diff --git a/libide/ide-object.h b/libide/ide-object.h
index a32352d..642723b 100644
--- a/libide/ide-object.h
+++ b/libide/ide-object.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]