CamelSession: Add camel_session_idle_add().
authorMatthew Barnes <mbarnes@redhat.com>
Sat, 19 May 2012 13:08:11 +0000 (09:08 -0400)
committerMatthew Barnes <mbarnes@redhat.com>
Sat, 19 May 2012 13:08:11 +0000 (09:08 -0400)
Schedules an idle callback on CamelSession's GMainContext.

camel/camel-session.c
camel/camel-session.h
docs/reference/camel/camel-sections.txt

index d45994f..57d060a 100644 (file)
@@ -1361,6 +1361,59 @@ camel_session_set_junk_filter (CamelSession *session,
 }
 
 /**
+ * camel_session_idle_add:
+ * @session: a #CamelSession
+ * @priority: the priority of the idle source
+ * @function: a function to call
+ * @data: data to pass to @function
+ * @notify: function to call when the idle is removed, or %NULL
+ *
+ * Adds a function to be called whenever there are no higher priority events
+ * pending.  If @function returns %FALSE it is automatically removed from the
+ * list of event sources and will not be called again.
+ *
+ * This internally creates a main loop source using g_idle_source_new()
+ * and attaches it to @session's own #CamelSession:main-context using
+ * g_source_attach().
+ *
+ * The @priority is typically in the range between %G_PRIORITY_DEFAULT_IDLE
+ * and %G_PRIORITY_HIGH_IDLE.
+ *
+ * Returns: the ID (greater than 0) of the event source
+ *
+ * Since: 3.6
+ **/
+guint
+camel_session_idle_add (CamelSession *session,
+                        gint priority,
+                        GSourceFunc function,
+                        gpointer data,
+                        GDestroyNotify notify)
+{
+       GMainContext *main_context;
+       GSource *source;
+       guint source_id;
+
+       g_return_val_if_fail (CAMEL_IS_SESSION (session), 0);
+       g_return_val_if_fail (function != NULL, 0);
+
+       main_context = camel_session_get_main_context (session);
+
+       source = g_idle_source_new ();
+
+       if (priority != G_PRIORITY_DEFAULT_IDLE)
+               g_source_set_priority (source, priority);
+
+       g_source_set_callback (source, function, data, notify);
+
+       source_id = g_source_attach (source, main_context);
+
+       g_source_unref (source);
+
+       return source_id;
+}
+
+/**
  * camel_session_submit_job:
  * @session: a #CamelSession
  * @callback: a #CamelSessionCallback
index b03ec78..776fd6a 100644 (file)
@@ -225,6 +225,11 @@ void               camel_session_set_junk_filter   (CamelSession *session,
 gboolean       camel_session_get_check_junk    (CamelSession *session);
 void           camel_session_set_check_junk    (CamelSession *session,
                                                 gboolean check_junk);
+guint          camel_session_idle_add          (CamelSession *session,
+                                                gint priority,
+                                                GSourceFunc function,
+                                                gpointer data,
+                                                GDestroyNotify notify);
 void           camel_session_submit_job        (CamelSession *session,
                                                 CamelSessionCallback callback,
                                                 gpointer user_data,
index e7afd25..4e9c4b0 100644 (file)
@@ -2026,6 +2026,7 @@ camel_session_get_check_junk
 camel_session_set_check_junk
 camel_session_get_junk_filter
 camel_session_set_junk_filter
+camel_session_idle_add
 CamelSessionCallback
 camel_session_submit_job
 camel_session_get_network_available