evolution-data-server r9687 - in branches/gnome-2-24/addressbook: . libebook



Author: abharath
Date: Fri Oct 17 08:26:04 2008
New Revision: 9687
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9687&view=rev

Log:
2008-10-17  Milan Crha  <mcrha redhat com>

       ** Part of fix for bug #364542

       * libebook/e-book.c: (e_book_new_op),
        (e_book_get_current_sync_op):
       Do set opid to 0 for sync operations, thus we will find it later.
       * libebook/e-book.h: (e_book_cancel_async_op):
       * libebook/e-book.c: (e_book_cancel_async_op), (do_cancel),
       (e_book_cancel): Be able to cancel async op too (at least any).


Modified:
   branches/gnome-2-24/addressbook/ChangeLog
   branches/gnome-2-24/addressbook/libebook/e-book.c
   branches/gnome-2-24/addressbook/libebook/e-book.h

Modified: branches/gnome-2-24/addressbook/libebook/e-book.c
==============================================================================
--- branches/gnome-2-24/addressbook/libebook/e-book.c	(original)
+++ branches/gnome-2-24/addressbook/libebook/e-book.c	Fri Oct 17 08:26:04 2008
@@ -176,7 +176,10 @@
 	op->flag = e_flag_new ();
 
 	op->synchronous = sync;
-	op->opid = book->priv->current_op_id++;
+	if (sync)
+		op->opid = 0;
+	else
+		op->opid = book->priv->current_op_id++;
 
 	g_hash_table_insert (book->priv->id_to_op,
 			     &op->opid, op);
@@ -194,9 +197,7 @@
 static EBookOp*
 e_book_get_current_sync_op (EBook *book)
 {
-	guint32 opid = 0;
-	return (EBookOp*)g_hash_table_lookup (book->priv->id_to_op,
-					      &opid);
+	return e_book_get_op (book, 0);
 }
 
 static void
@@ -2487,6 +2488,47 @@
 	g_mutex_unlock (book->priv->mutex);
 }
 
+static gboolean
+do_cancel (EBook *book, GError **error, EBookOp *op, const char *func_name)
+{
+	EBookStatus status;
+	gboolean rv;
+	CORBA_Environment ev;
+	
+	if (op == NULL) {
+		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_COULD_NOT_CANCEL,
+			     _("%s: there is no current operation"), func_name);
+		return FALSE;
+	}
+
+	status = GNOME_Evolution_Addressbook_Book_cancelOperation(book->priv->corba_book, &ev);
+
+	if (ev._major != CORBA_NO_EXCEPTION) {
+
+		CORBA_exception_free (&ev);
+
+		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION,
+			     _("CORBA exception making \"%s\" call"),
+			     "Book::cancelOperation");
+		return FALSE;
+	}
+
+	CORBA_exception_free (&ev);
+
+	if (status == E_BOOK_ERROR_OK) {
+		op->status = E_BOOK_ERROR_CANCELLED;
+		e_flag_set (op->flag);
+		rv = TRUE;
+	}
+	else {
+		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_COULD_NOT_CANCEL,
+			     _("%s: could not cancel"), func_name);
+		rv = FALSE;
+	}
+
+	return rv;
+}
+
 /**
  * e_book_cancel:
  * @book: an #EBook
@@ -2509,51 +2551,43 @@
 	       GError **error)
 {
 	EBookOp *op;
-	EBookStatus status;
-	gboolean rv;
-	CORBA_Environment ev;
 
 	e_return_error_if_fail (book && E_IS_BOOK (book),       E_BOOK_ERROR_INVALID_ARG, FALSE);
 
 	g_mutex_lock (book->priv->mutex);
-
-	if (e_book_get_current_sync_op (book) == NULL) {
-		g_mutex_unlock (book->priv->mutex);
-		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_COULD_NOT_CANCEL,
-			     _("%s: there is no current operation"), "e_book_cacnel");
-		return FALSE;
-	}
-
 	op = e_book_get_current_sync_op (book);
-
 	g_mutex_unlock (book->priv->mutex);
 
-	status = GNOME_Evolution_Addressbook_Book_cancelOperation(book->priv->corba_book, &ev);
+	return do_cancel (book, error, op, "e_book_cancel");
+}
 
-	if (ev._major != CORBA_NO_EXCEPTION) {
+/**
+ * e_book_cancel_async_op:
+ * Similar to above e_book_cancel function, only cancels last, still running,
+ * asynchronous operation.
+ **/
+gboolean
+e_book_cancel_async_op (EBook *book, GError **error)
+{
+	EBookOp *op;
+	guint32 opid;
 
-		CORBA_exception_free (&ev);
+	e_return_error_if_fail (book && E_IS_BOOK (book),       E_BOOK_ERROR_INVALID_ARG, FALSE);
 
-		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_CORBA_EXCEPTION,
-			     _("CORBA exception making \"%s\" call"),
-			     "Book::cancelOperation");
-		return FALSE;
-	}
+	g_mutex_lock (book->priv->mutex);
 
-	CORBA_exception_free (&ev);
+	/* find nearest unfinished async op to cancel */
+	op = NULL;
+	for (opid = book->priv->current_op_id; opid > 0 && !op; opid--) {
+		op = e_book_get_op (book, opid);
 
-	if (status == E_BOOK_ERROR_OK) {
-		op->status = E_BOOK_ERROR_CANCELLED;
-		e_flag_set (op->flag);
-		rv = TRUE;
-	}
-	else {
-		g_set_error (error, E_BOOK_ERROR, E_BOOK_ERROR_COULD_NOT_CANCEL,
-			     _("%s: could not cancel"), "e_book_cancel");
-		rv = FALSE;
+		if (op && op->synchronous)
+			op = NULL;
 	}
 
-	return rv;
+	g_mutex_unlock (book->priv->mutex);
+
+	return do_cancel (book, error, op, "e_book_cancel_async_op");
 }
 
 

Modified: branches/gnome-2-24/addressbook/libebook/e-book.h
==============================================================================
--- branches/gnome-2-24/addressbook/libebook/e-book.h	(original)
+++ branches/gnome-2-24/addressbook/libebook/e-book.h	Fri Oct 17 08:26:04 2008
@@ -241,6 +241,9 @@
 gboolean    e_book_cancel                  (EBook   *book,
 					    GError **error);
 
+gboolean    e_book_cancel_async_op	   (EBook   *book,
+					    GError **error);
+
 /* Identity */
 gboolean    e_book_get_self                (EContact **contact, EBook **book, GError **error);
 gboolean    e_book_set_self                (EBook *book, EContact *contact, GError **error);



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