diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-06-11 13:51:12 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-06-11 13:51:12 +0800 |
commit | cccb986f3791577f3a0e27a31c48bb7424d73a19 (patch) | |
tree | 04a47a5758ae3fd8967a692e3ea0c5e8924baf6d /addressbook/backend/ebook/e-book.c | |
parent | efa9a6294d55c0c9f857e1c26390898c84ce0784 (diff) | |
download | gsoc2013-evolution-cccb986f3791577f3a0e27a31c48bb7424d73a19.tar.gz gsoc2013-evolution-cccb986f3791577f3a0e27a31c48bb7424d73a19.tar.zst gsoc2013-evolution-cccb986f3791577f3a0e27a31c48bb7424d73a19.zip |
Added this function to put a response back into the queue.
2001-06-11 Christopher James Lahey <clahey@ximian.com>
* backend/ebook/e-book-listener.c, backend/ebook/e-book-listener.h
(e_book_listener_unpop_response): Added this function to put a
response back into the queue.
* backend/ebook/e-book.c (e_book_check_listener_queue,
e_book_queue_op): Handle the case where the op hasn't been queued
yet when we get the response. In this case we unpop the response.
Also, when queueing an op, we check to see if there are any
responses waiting.
svn path=/trunk/; revision=10179
Diffstat (limited to 'addressbook/backend/ebook/e-book.c')
-rw-r--r-- | addressbook/backend/ebook/e-book.c | 140 |
1 files changed, 83 insertions, 57 deletions
diff --git a/addressbook/backend/ebook/e-book.c b/addressbook/backend/ebook/e-book.c index a5231f8303..5217d6ef90 100644 --- a/addressbook/backend/ebook/e-book.c +++ b/addressbook/backend/ebook/e-book.c @@ -64,6 +64,8 @@ typedef struct { EBookViewListener *listener; } EBookOp; +static gboolean check_listener_queue_idle (gpointer closure); + /* * Local response queue management. */ @@ -75,6 +77,8 @@ e_book_queue_op (EBook *book, { EBookOp *op; + g_print ("Queue Op\n"); + op = g_new0 (EBookOp, 1); op->tag = book->priv->op_tag++; op->active = TRUE; @@ -85,6 +89,11 @@ e_book_queue_op (EBook *book, book->priv->pending_ops = g_list_append (book->priv->pending_ops, op); + if (e_book_listener_check_pending (book->priv->listener)) { + gtk_object_ref (GTK_OBJECT (book)); + g_idle_add (check_listener_queue_idle, book); + } + return op->tag; } @@ -94,6 +103,8 @@ e_book_pop_op (EBook *book) GList *popped; EBookOp *op; + g_print ("Pop Op\n"); + if (book->priv->pending_ops == NULL) return NULL; @@ -126,7 +137,7 @@ e_book_cancel_op (EBook *book, guint tag) return cancelled; } -static void +static gboolean e_book_do_response_create_card (EBook *book, EBookListenerResponse *resp) { @@ -135,18 +146,17 @@ e_book_do_response_create_card (EBook *book, op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_create_card: Cannot find operation " - "in local op queue!\n"); - return; + return FALSE; } if (op->cb) ((EBookIdCallback) op->cb) (book, resp->status, resp->id, op->closure); g_free (resp->id); g_free (op); + return TRUE; } -static void +static gboolean e_book_do_response_generic (EBook *book, EBookListenerResponse *resp) { @@ -155,17 +165,17 @@ e_book_do_response_generic (EBook *book, op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_generic: Cannot find operation " - "in local op queue!\n"); + return FALSE; } if (op->cb) ((EBookCallback) op->cb) (book, resp->status, op->closure); g_free (op); + return TRUE; } -static void +static gboolean e_book_do_response_get_cursor (EBook *book, EBookListenerResponse *resp) { @@ -176,9 +186,7 @@ e_book_do_response_get_cursor (EBook *book, op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_get_cursor: Cannot find operation " - "in local op queue!\n"); - return; + return FALSE; } cursor = e_card_cursor_new(resp->cursor); @@ -207,11 +215,12 @@ e_book_do_response_get_cursor (EBook *book, gtk_object_unref(GTK_OBJECT(cursor)); g_free (op); + return TRUE; } -static void +static gboolean e_book_do_response_get_view (EBook *book, EBookListenerResponse *resp) { @@ -222,9 +231,7 @@ e_book_do_response_get_view (EBook *book, op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_get_view: Cannot find operation " - "in local op queue!\n"); - return; + return FALSE; } book_view = e_book_view_new(resp->book_view, op->listener); @@ -257,9 +264,10 @@ e_book_do_response_get_view (EBook *book, bonobo_object_unref(BONOBO_OBJECT(op->listener)); g_free (op); + return TRUE; } -static void +static gboolean e_book_do_response_get_changes (EBook *book, EBookListenerResponse *resp) { @@ -270,9 +278,7 @@ e_book_do_response_get_changes (EBook *book, op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_get_changes: Cannot find operation " - "in local op queue!\n"); - return; + return FALSE; } book_view = e_book_view_new (resp->book_view, op->listener); @@ -302,30 +308,53 @@ e_book_do_response_get_changes (EBook *book, bonobo_object_unref(BONOBO_OBJECT(op->listener)); g_free (op); + return TRUE; } -static void +static gboolean e_book_do_response_open (EBook *book, EBookListenerResponse *resp) { EBookOp *op; + op = e_book_pop_op (book); + + if (op == NULL) { + return FALSE; + } + if (resp->status == E_BOOK_STATUS_SUCCESS) { book->priv->corba_book = resp->book; book->priv->load_state = URILoaded; } + if (op->cb) + ((EBookCallback) op->cb) (book, resp->status, op->closure); + g_free (op); + return TRUE; +} + +static gboolean +e_book_do_response_get_supported_fields (EBook *book, + EBookListenerResponse *resp) +{ + EBookOp *op; + op = e_book_pop_op (book); if (op == NULL) { - g_warning ("e_book_do_response_open: Cannot find operation " - "in local op queue!\n"); - return; + return FALSE; + } + + if (op->cb) { + if (op->active) + ((EBookFieldsCallback) op->cb) (book, resp->status, resp->fields, op->closure); + else + ((EBookFieldsCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); } - if (op->cb) - ((EBookCallback) op->cb) (book, resp->status, op->closure); g_free (op); + return TRUE; } static void @@ -354,30 +383,6 @@ e_book_do_writable_event (EBook *book, resp->writable); } -static void -e_book_do_response_get_supported_fields (EBook *book, - EBookListenerResponse *resp) -{ - EBookOp *op; - - op = e_book_pop_op (book); - - if (op == NULL) { - g_warning ("e_book_do_response_get_supported_fields: Cannot find operation " - "in local op queue!\n"); - return; - } - - if (op->cb) { - if (op->active) - ((EBookFieldsCallback) op->cb) (book, resp->status, resp->fields, op->closure); - else - ((EBookFieldsCallback) op->cb) (book, E_BOOK_STATUS_CANCELLED, NULL, op->closure); - } - - g_free (op); -} - /* * Reading notices out of the EBookListener's queue. */ @@ -385,6 +390,7 @@ static void e_book_check_listener_queue (EBookListener *listener, EBook *book) { EBookListenerResponse *resp; + gboolean handled = FALSE; resp = e_book_listener_pop_response (listener); @@ -393,46 +399,66 @@ e_book_check_listener_queue (EBookListener *listener, EBook *book) switch (resp->op) { case CreateCardResponse: - e_book_do_response_create_card (book, resp); + handled = e_book_do_response_create_card (book, resp); break; case RemoveCardResponse: case ModifyCardResponse: case AuthenticationResponse: - e_book_do_response_generic (book, resp); + handled = e_book_do_response_generic (book, resp); break; case GetCursorResponse: - e_book_do_response_get_cursor (book, resp); + handled = e_book_do_response_get_cursor (book, resp); break; case GetBookViewResponse: - e_book_do_response_get_view(book, resp); + handled = e_book_do_response_get_view(book, resp); break; case GetChangesResponse: - e_book_do_response_get_changes(book, resp); + handled = e_book_do_response_get_changes(book, resp); break; case OpenBookResponse: - e_book_do_response_open (book, resp); + handled = e_book_do_response_open (book, resp); break; case GetSupportedFieldsResponse: - e_book_do_response_get_supported_fields (book, resp); + handled = e_book_do_response_get_supported_fields (book, resp); break; case OpenProgressEvent: e_book_do_progress_event (book, resp); + handled = TRUE; break; case LinkStatusEvent: e_book_do_link_event (book, resp); + handled = TRUE; break; case WritableStatusEvent: e_book_do_writable_event (book, resp); + handled = TRUE; break; default: g_error ("EBook: Unknown operation %d in listener queue!\n", resp->op); + handled = TRUE; + break; } - g_free (resp); + if (handled) + g_free (resp); + else + e_book_listener_unpop_response (listener, resp); } +static gboolean +check_listener_queue_idle (gpointer closure) +{ + EBook *book = closure; + if (!GTK_OBJECT_DESTROYED (GTK_OBJECT (book))) { + e_book_check_listener_queue (book->priv->listener, book); + } + gtk_object_unref (GTK_OBJECT (book)); + return FALSE; +} + + /** * e_book_load_uri: */ |