[gnome-builder/wip/gtk4-port: 843/1774] libide/core: add helper to check if object is ready




commit a58e03d84f2b7e9ce62ed2c9b9a7e4b0b4e8bd2b
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 2 17:31:09 2022 -0700

    libide/core: add helper to check if object is ready
    
    This can be used to short-circuit for cases where we might be in shutdown
    and help ensure that we don't continue doing work.

 src/libide/core/ide-object.c | 29 +++++++++++++++++++++++++++++
 src/libide/core/ide-object.h |  3 +++
 2 files changed, 32 insertions(+)
---
diff --git a/src/libide/core/ide-object.c b/src/libide/core/ide-object.c
index 13e24cee9..5268428f3 100644
--- a/src/libide/core/ide-object.c
+++ b/src/libide/core/ide-object.c
@@ -1370,3 +1370,32 @@ ide_object_log (gpointer        instance,
       va_end (args);
     }
 }
+
+gboolean
+ide_object_check_ready (IdeObject  *self,
+                        GError    **error)
+{
+  IdeObjectPrivate *priv = ide_object_get_instance_private (self);
+  g_autoptr(IdeObject) root = NULL;
+
+  if (self == NULL ||
+      priv->in_destruction ||
+      priv->destroyed)
+    goto failure;
+
+  if (!(root = ide_object_ref_root (self)))
+    goto failure;
+
+  if (!IDE_IS_CONTEXT (root))
+    goto failure;
+
+  return TRUE;
+
+failure:
+  g_set_error (error,
+               G_IO_ERROR,
+               G_IO_ERROR_CANCELLED,
+               "Operation cancelled or in shutdown");
+
+  return FALSE;
+}
diff --git a/src/libide/core/ide-object.h b/src/libide/core/ide-object.h
index 3591ca365..700de7750 100644
--- a/src/libide/core/ide-object.h
+++ b/src/libide/core/ide-object.h
@@ -149,6 +149,9 @@ void          ide_object_log                    (gpointer            instance,
                                                  const gchar        *domain,
                                                  const gchar        *format,
                                                  ...) G_GNUC_PRINTF (4, 5);
+IDE_AVAILABLE_IN_ALL
+gboolean      ide_object_check_ready            (IdeObject          *self,
+                                                 GError            **error);
 
 #ifdef __cplusplus
 #define ide_object_message(instance, format, ...) ide_object_log(instance, G_LOG_LEVEL_MESSAGE, 
G_LOG_DOMAIN, format __VA_OPT__(,) __VA_ARGS__)


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