[evolution-mapi] Changes for MonitorNotification which is now non-blocking and takes a callback for cancellation.



commit c58d013880efd65f2751ff58a5eaf6a51321dab1
Author: Johnny Jacob <johnnyjacob gmail com>
Date:   Mon Dec 21 16:47:38 2009 +0530

    Changes for  MonitorNotification which is now non-blocking and takes a callback for cancellation.

 src/camel/camel-mapi-notifications.c           |   17 ++++++++++++++---
 src/libexchangemapi/exchange-mapi-connection.c |    4 ++--
 src/libexchangemapi/exchange-mapi-connection.h |    2 +-
 3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/src/camel/camel-mapi-notifications.c b/src/camel/camel-mapi-notifications.c
index 846c2ec..a06ff2e 100644
--- a/src/camel/camel-mapi-notifications.c
+++ b/src/camel/camel-mapi-notifications.c
@@ -221,8 +221,9 @@ static CamelSessionThreadOps mapi_push_notification_ops = {
 	mapi_push_notification_listener_close,
 };
 
+/*Of type mapi_notify_continue_callback_t*/
 static gint
-mapi_notifications_continue_check (void)
+mapi_notifications_continue_check (gpointer data)
 {
 	if (camel_operation_cancel_check(NULL) || (camel_application_is_exiting == TRUE))
 		return 1;
@@ -235,19 +236,29 @@ mapi_push_notification_listener (CamelSession *session, CamelSessionThreadMsg *m
 {
 	struct mapi_push_notification_msg *m = (struct mapi_push_notification_msg *)msg;
 	CamelMapiStore *mapi_store = (CamelMapiStore *) m->event_data;
+	struct mapi_notify_continue_callback_data *cb_data = g_new0 (struct mapi_notify_continue_callback_data, 1);
+
+	/* Timeout for select in MonitorNotification*/
+	cb_data->tv.tv_sec = 2;
+	cb_data->tv.tv_usec = 0;
+
+	/* API would consult us if we want to continue with processing events*/
+	cb_data->callback = mapi_notifications_continue_check;
+	cb_data->data = NULL;
 
 	CAMEL_SERVICE_REC_LOCK (mapi_store, connect_lock);
+
 	if (exchange_mapi_events_init ()) {
 		exchange_mapi_events_subscribe (0, m->event_options, m->event_mask,
 						&m->connection,	mapi_notifications_filter,
 						m->event_data);
 
 		CAMEL_SERVICE_REC_UNLOCK (mapi_store, connect_lock);
-		/* Need a better API for canceling this operation*/
-		exchange_mapi_events_monitor (mapi_notifications_continue_check);
+		exchange_mapi_events_monitor (cb_data); /*Blocking call. Don't hold locks here*/
 	} else 
 		CAMEL_SERVICE_REC_UNLOCK (mapi_store, connect_lock);
 
+	g_free (cb_data);
 }
 
 static void
diff --git a/src/libexchangemapi/exchange-mapi-connection.c b/src/libexchangemapi/exchange-mapi-connection.c
index d2fc441..51654a7 100644
--- a/src/libexchangemapi/exchange-mapi-connection.c
+++ b/src/libexchangemapi/exchange-mapi-connection.c
@@ -3059,10 +3059,10 @@ exchange_mapi_events_unsubscribe (mapi_object_t *obj, guint32 connection)
 
 /* Note : Blocking infinite loop. */
 gboolean
-exchange_mapi_events_monitor (mapi_notify_continue_callback_t check)
+exchange_mapi_events_monitor (struct mapi_notify_continue_callback_data *cb_data)
 {
 	enum MAPISTATUS	retval;
-	retval = MonitorNotification (global_mapi_session, NULL, check);
+	retval = MonitorNotification (global_mapi_session, NULL, cb_data);
 	return retval;
 }
 
diff --git a/src/libexchangemapi/exchange-mapi-connection.h b/src/libexchangemapi/exchange-mapi-connection.h
index b31892c..258e516 100644
--- a/src/libexchangemapi/exchange-mapi-connection.h
+++ b/src/libexchangemapi/exchange-mapi-connection.h
@@ -218,7 +218,7 @@ typedef gboolean (*exchange_check_continue) (void);
 
 gboolean exchange_mapi_events_init ();
 
-gboolean exchange_mapi_events_monitor (exchange_check_continue check);
+gboolean exchange_mapi_events_monitor (struct mapi_notify_continue_callback_data *cb_data);
 
 void exchange_mapi_events_monitor_close ();
 



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