EBackend: Add a read-only "main-context" property.
authorMatthew Barnes <mbarnes@redhat.com>
Fri, 22 Feb 2013 14:05:03 +0000 (09:05 -0500)
committerMatthew Barnes <mbarnes@redhat.com>
Fri, 22 Feb 2013 14:05:03 +0000 (09:05 -0500)
This is the GMainContext on which to attach backend event sources.

New functions:

    e_backend_ref_main_context()

docs/reference/libebackend/libebackend-sections.txt
libebackend/e-backend.c
libebackend/e-backend.h

index 81e59b2..763a0a3 100644 (file)
@@ -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
index 2181098..608f4d2 100644 (file)
@@ -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
index b99527a..74e7e8d 100644 (file)
@@ -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,