aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Moya <rodrigo@ximian.com>2002-05-02 21:31:16 +0800
committerRodrigo Moya <rodrigo@src.gnome.org>2002-05-02 21:31:16 +0800
commitf570ce28bf08593baca5012bf74d2227992aa5fb (patch)
tree4a485e758958ca71119f7244766191f5649bb7d5
parent15866e29c0a0c3bc943bb4929ef25dc68f5d4002 (diff)
downloadgsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar.gz
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar.bz2
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar.lz
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar.xz
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.tar.zst
gsoc2013-evolution-f570ce28bf08593baca5012bf74d2227992aa5fb.zip
refactored a bit, to not do things in idle loops.
2002-05-02 Rodrigo Moya <rodrigo@ximian.com> * pcs/query.c: refactored a bit, to not do things in idle loops. svn path=/trunk/; revision=16662
-rw-r--r--calendar/ChangeLog4
-rw-r--r--calendar/pcs/query.c159
2 files changed, 80 insertions, 83 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 26bf984892..cd619ce7e8 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,7 @@
+2002-05-02 Rodrigo Moya <rodrigo@ximian.com>
+
+ * pcs/query.c: refactored a bit, to not do things in idle loops.
+
2002-05-01 JP Rosevear <jpr@ximian.com>
* gui/print.c (print_day_details): modify the start and end hours
diff --git a/calendar/pcs/query.c b/calendar/pcs/query.c
index d3fc773ff9..35f1dc17aa 100644
--- a/calendar/pcs/query.c
+++ b/calendar/pcs/query.c
@@ -61,8 +61,8 @@ struct _QueryPrivate {
char *sexp;
ESExp *esexp;
- /* Idle handler ID for asynchronous queries and the current state */
- guint idle_id;
+ /* Timeout handler ID for asynchronous queries and current state of the query */
+ guint timeout_id;
QueryState state;
/* List of UIDs that we still have to process */
@@ -125,7 +125,7 @@ query_init (Query *query)
priv->ql = CORBA_OBJECT_NIL;
priv->sexp = NULL;
- priv->idle_id = 0;
+ priv->timeout_id = 0;
priv->state = QUERY_WAIT_FOR_BACKEND;
priv->pending_uids = NULL;
@@ -198,9 +198,9 @@ query_destroy (GtkObject *object)
priv->esexp = NULL;
}
- if (priv->idle_id) {
- g_source_remove (priv->idle_id);
- priv->idle_id = 0;
+ if (priv->timeout_id) {
+ g_source_remove (priv->timeout_id);
+ priv->timeout_id = 0;
}
if (priv->pending_uids) {
@@ -1063,8 +1063,6 @@ parse_sexp (Query *query)
priv = query->priv;
- g_assert (priv->state == QUERY_START_PENDING);
-
/* Compile the query string */
priv->esexp = create_sexp (query);
@@ -1179,91 +1177,72 @@ match_component (Query *query, const char *uid,
e_sexp_result_free (priv->esexp, result);
}
-/* Processes a single component that is queued in the list */
+/* Processes all components that are queued in the list */
static gboolean
-process_component_cb (gpointer data)
+process_components_cb (gpointer data)
{
Query *query;
QueryPrivate *priv;
char *uid;
GList *l;
+ CORBA_Environment ev;
query = QUERY (data);
priv = query->priv;
- /* No more components? */
-
- if (!priv->pending_uids) {
- CORBA_Environment ev;
-
- g_assert (priv->n_pending == 0);
+ g_source_remove (priv->timeout_id);
+ priv->timeout_id = 0;
- priv->idle_id = 0;
- priv->state = QUERY_DONE;
-
- CORBA_exception_init (&ev);
- GNOME_Evolution_Calendar_QueryListener_notifyQueryDone (
- priv->ql,
- GNOME_Evolution_Calendar_QueryListener_SUCCESS,
- "",
- &ev);
-
- if (BONOBO_EX (&ev))
- g_message ("process_component_cb(): Could not notify the listener of "
- "a finished query");
-
- CORBA_exception_free (&ev);
-
- return FALSE;
- }
+ while (priv->pending_uids) {
+ g_assert (priv->n_pending > 0);
- g_assert (priv->n_pending > 0);
+ /* Fetch the component */
- /* Fetch the component */
+ l = priv->pending_uids;
+ priv->pending_uids = g_list_remove_link (priv->pending_uids, l);
+ priv->n_pending--;
- l = priv->pending_uids;
- priv->pending_uids = g_list_remove_link (priv->pending_uids, l);
- priv->n_pending--;
+ g_assert ((priv->pending_uids && priv->n_pending != 0)
+ || (!priv->pending_uids && priv->n_pending == 0));
- g_assert ((priv->pending_uids && priv->n_pending != 0)
- || (!priv->pending_uids && priv->n_pending == 0));
+ uid = l->data;
+ g_assert (uid != NULL);
- uid = l->data;
- g_assert (uid != NULL);
+ g_list_free_1 (l);
- g_list_free_1 (l);
+ bonobo_object_ref (BONOBO_OBJECT (query));
- bonobo_object_ref (BONOBO_OBJECT (query));
+ match_component (query, uid,
+ TRUE,
+ priv->pending_total - priv->n_pending,
+ priv->pending_total);
- match_component (query, uid,
- TRUE,
- priv->pending_total - priv->n_pending,
- priv->pending_total);
+ bonobo_object_unref (BONOBO_OBJECT (query));
- bonobo_object_unref (BONOBO_OBJECT (query));
+ g_free (uid);
- g_free (uid);
+ /* run the main loop, for not blocking */
+ if (gtk_events_pending ())
+ gtk_main_iteration ();
+ }
- return TRUE;
-}
+ /* notify listener that the query ended */
+ priv->state = QUERY_DONE;
-/* Populates the query with pending UIDs so that they can be processed
- * asynchronously.
- */
-static void
-populate_query (Query *query)
-{
- QueryPrivate *priv;
+ CORBA_exception_init (&ev);
+ GNOME_Evolution_Calendar_QueryListener_notifyQueryDone (
+ priv->ql,
+ GNOME_Evolution_Calendar_QueryListener_SUCCESS,
+ "",
+ &ev);
- priv = query->priv;
- g_assert (priv->idle_id == 0);
- g_assert (priv->state == QUERY_START_PENDING);
+ if (BONOBO_EX (&ev))
+ g_message ("start_query(): Could not notify the listener of "
+ "a finished query");
- priv->pending_uids = cal_backend_get_uids (priv->backend, CALOBJ_TYPE_ANY);
- priv->pending_total = g_list_length (priv->pending_uids);
- priv->n_pending = priv->pending_total;
+ CORBA_exception_free (&ev);
- priv->idle_id = g_idle_add (process_component_cb, query);
+ return FALSE;
}
/* Callback used when a component changes in the backend */
@@ -1306,26 +1285,23 @@ backend_obj_removed_cb (CalBackend *backend, const char *uid, gpointer data)
bonobo_object_unref (BONOBO_OBJECT (query));
}
-/* Idle handler for starting a query */
-static gboolean
-start_query_cb (gpointer data)
+/* Actually starts the query */
+static void
+start_query (Query *query)
{
- Query *query;
QueryPrivate *priv;
- query = QUERY (data);
priv = query->priv;
- g_assert (priv->state == QUERY_START_PENDING);
-
- priv->idle_id = 0;
-
if (!parse_sexp (query))
- return FALSE;
+ return;
/* Populate the query with UIDs so that we can process them asynchronously */
- populate_query (query);
+ priv->state = QUERY_IN_PROGRESS;
+ priv->pending_uids = cal_backend_get_uids (priv->backend, CALOBJ_TYPE_ANY);
+ priv->pending_total = g_list_length (priv->pending_uids);
+ priv->n_pending = priv->pending_total;
gtk_signal_connect (GTK_OBJECT (priv->backend), "obj_updated",
GTK_SIGNAL_FUNC (backend_obj_updated_cb),
@@ -1334,7 +1310,26 @@ start_query_cb (gpointer data)
GTK_SIGNAL_FUNC (backend_obj_removed_cb),
query);
- priv->state = QUERY_IN_PROGRESS;
+ priv->timeout_id = g_timeout_add (100, (GSourceFunc) process_components_cb, query);
+}
+
+/* Idle handler for starting a query */
+static gboolean
+start_query_cb (gpointer data)
+{
+ Query *query;
+ QueryPrivate *priv;
+
+ query = QUERY (data);
+ priv = query->priv;
+
+ g_source_remove (priv->timeout_id);
+ priv->timeout_id = 0;
+
+ if (priv->state == QUERY_START_PENDING) {
+ priv->state = QUERY_IN_PROGRESS;
+ start_query (query);
+ }
return FALSE;
}
@@ -1358,9 +1353,8 @@ backend_opened_cb (CalBackend *backend, CalBackendOpenStatus status, gpointer da
if (status == CAL_BACKEND_OPEN_SUCCESS) {
g_assert (cal_backend_is_loaded (backend));
- g_assert (priv->idle_id == 0);
- priv->idle_id = g_idle_add (start_query_cb, query);
+ priv->timeout_id = g_timeout_add (100, (GSourceFunc) start_query_cb, query);
}
}
@@ -1418,8 +1412,7 @@ query_construct (Query *query,
if (cal_backend_is_loaded (priv->backend)) {
priv->state = QUERY_START_PENDING;
- g_assert (priv->idle_id == 0);
- priv->idle_id = g_idle_add (start_query_cb, query);
+ priv->timeout_id = g_timeout_add (100, (GSourceFunc) start_query_cb, query);
} else
gtk_signal_connect (GTK_OBJECT (priv->backend), "opened",
GTK_SIGNAL_FUNC (backend_opened_cb),