[evolution-data-server] EBackend: Add a read-only "main-context" property.



commit cb7847ee3ff97995c349de658e56b99ffee6e176
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Feb 22 09:05:03 2013 -0500

    EBackend: Add a read-only "main-context" property.
    
    This is the GMainContext on which to attach backend event sources.
    
    New functions:
    
        e_backend_ref_main_context()

 .../reference/libebackend/libebackend-sections.txt |    1 +
 libebackend/e-backend.c                            |   48 ++++++++++++++++++++
 libebackend/e-backend.h                            |    1 +
 3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libebackend/libebackend-sections.txt 
b/docs/reference/libebackend/libebackend-sections.txt
index 81e59b2..763a0a3 100644
--- a/docs/reference/libebackend/libebackend-sections.txt
+++ b/docs/reference/libebackend/libebackend-sections.txt
@@ -79,6 +79,7 @@ e_backend_set_online
 e_backend_get_source
 e_backend_ref_connectable
 e_backend_set_connectable
+e_backend_ref_main_context
 e_backend_authenticate_sync
 e_backend_authenticate
 e_backend_authenticate_finish
diff --git a/libebackend/e-backend.c b/libebackend/e-backend.c
index 2181098..608f4d2 100644
--- a/libebackend/e-backend.c
+++ b/libebackend/e-backend.c
@@ -57,6 +57,7 @@ struct _EBackendPrivate {
        GMutex property_lock;
        ESource *source;
        EUserPrompter *prompter;
+       GMainContext *main_context;
        GSocketConnectable *connectable;
        gboolean online;
 
@@ -75,6 +76,7 @@ struct _AsyncContext {
 enum {
        PROP_0,
        PROP_CONNECTABLE,
+       PROP_MAIN_CONTEXT,
        PROP_ONLINE,
        PROP_SOURCE,
        PROP_USER_PROMPTER
@@ -301,6 +303,12 @@ backend_get_property (GObject *object,
                                E_BACKEND (object)));
                        return;
 
+               case PROP_MAIN_CONTEXT:
+                       g_value_take_boxed (
+                               value, e_backend_ref_main_context (
+                               E_BACKEND (object)));
+                       return;
+
                case PROP_ONLINE:
                        g_value_set_boolean (
                                value, e_backend_get_online (
@@ -342,6 +350,11 @@ backend_dispose (GObject *object)
                priv->network_changed_timeout_id = 0;
        }
 
+       if (priv->main_context != NULL) {
+               g_main_context_unref (priv->main_context);
+               priv->main_context = NULL;
+       }
+
        g_clear_object (&priv->source);
        g_clear_object (&priv->prompter);
        g_clear_object (&priv->connectable);
@@ -521,6 +534,18 @@ e_backend_class_init (EBackendClass *class)
 
        g_object_class_install_property (
                object_class,
+               PROP_MAIN_CONTEXT,
+               g_param_spec_boxed (
+                       "main-context",
+                       "Main Context",
+                       "The main loop context on "
+                       "which to attach event sources",
+                       G_TYPE_MAIN_CONTEXT,
+                       G_PARAM_READABLE |
+                       G_PARAM_STATIC_STRINGS));
+
+       g_object_class_install_property (
+               object_class,
                PROP_ONLINE,
                g_param_spec_boolean (
                        "online",
@@ -563,6 +588,7 @@ e_backend_init (EBackend *backend)
 
        backend->priv = E_BACKEND_GET_PRIVATE (backend);
        backend->priv->prompter = e_user_prompter_new ();
+       backend->priv->main_context = g_main_context_ref_thread_default ();
 
        g_mutex_init (&backend->priv->property_lock);
        g_mutex_init (&backend->priv->network_monitor_cancellable_lock);
@@ -730,6 +756,28 @@ e_backend_set_connectable (EBackend *backend,
 }
 
 /**
+ * e_backend_ref_main_context:
+ * @backend: an #EBackend
+ *
+ * Returns the #GMainContext on which event sources for @backend are to
+ * be attached.
+ *
+ * The returned #GMainContext is referenced for thread-safety and must be
+ * unreferenced with g_main_context_unref() when finished with it.
+ *
+ * Returns: (transfer full): a #GMainContext
+ *
+ * Since: 3.8
+ **/
+GMainContext *
+e_backend_ref_main_context (EBackend *backend)
+{
+       g_return_val_if_fail (E_IS_BACKEND (backend), NULL);
+
+       return g_main_context_ref (backend->priv->main_context);
+}
+
+/**
  * e_backend_authenticate_sync:
  * @backend: an #EBackend
  * @auth: an #ESourceAuthenticator
diff --git a/libebackend/e-backend.h b/libebackend/e-backend.h
index b99527a..74e7e8d 100644
--- a/libebackend/e-backend.h
+++ b/libebackend/e-backend.h
@@ -100,6 +100,7 @@ GSocketConnectable *
                e_backend_ref_connectable       (EBackend *backend);
 void           e_backend_set_connectable       (EBackend *backend,
                                                 GSocketConnectable *connectable);
+GMainContext * e_backend_ref_main_context      (EBackend *backend);
 gboolean       e_backend_authenticate_sync     (EBackend *backend,
                                                 ESourceAuthenticator *auth,
                                                 GCancellable *cancellable,


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