Changeset 3623

Show
Ignore:
Timestamp:
04/24/08 19:56:39
Author:
pvanhoof
Message:

2008-04-24 Philip Van Hoof <pvanhoof@gnome.org>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r3618 r3623  
     12008-04-24  Philip Van Hoof <pvanhoof@gnome.org> 
     2 
     3        * Rmeoved all synchronous API usage in TnyCamelSendQueue 
     4 
    152008-04-24  Sergio Villar Senin  <svillar@igalia.com> 
    26 
  • trunk/libtinymail-camel/tny-camel-send-queue.c

    r3621 r3623  
    391391} 
    392392 
     393 
     394 
     395typedef struct { 
     396        TnyFolder *from, *to; 
     397        TnyList *list; 
     398        GError **err; 
     399 
     400        GCond* condition; 
     401        gboolean had_callback; 
     402        GMutex *mutex; 
     403 
     404} TransferSync; 
     405 
     406static void  
     407transfer_async (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data) 
     408{ 
     409        TransferSync *info = (TransferSync *) user_data; 
     410 
     411        if (err && info->err) 
     412                *info->err = g_error_copy (err); 
     413 
     414        g_mutex_lock (info->mutex); 
     415        g_cond_broadcast (info->condition); 
     416        info->had_callback = TRUE; 
     417        g_mutex_unlock (info->mutex); 
     418} 
     419 
     420static void 
     421transfer_sync (TnyFolder *from, TnyList *list, TnyFolder *to, gboolean delete_originals, GError **err) 
     422{ 
     423        TransferSync *info = g_slice_new0 (TransferSync); 
     424 
     425        info->mutex = g_mutex_new (); 
     426        info->condition = g_cond_new (); 
     427        info->had_callback = FALSE; 
     428 
     429        info->from = g_object_ref (from); 
     430        info->to = g_object_ref (from); 
     431        info->list = g_object_ref (list); 
     432        info->err = err; 
     433 
     434        tny_folder_transfer_msgs_async (info->from, info->list, info->to,  
     435                delete_originals, transfer_async, NULL, info); 
     436 
     437        g_mutex_lock (info->mutex); 
     438        if (!info->had_callback) 
     439                g_cond_wait (info->condition, info->mutex); 
     440        g_mutex_unlock (info->mutex); 
     441 
     442        g_mutex_free (info->mutex); 
     443        g_cond_free (info->condition); 
     444 
     445        g_object_unref (info->from); 
     446        g_object_unref (info->to); 
     447        g_object_unref (info->list); 
     448        g_slice_free (TransferSync, info); 
     449} 
     450 
     451 
     452typedef struct { 
     453        TnyFolder *folder; 
     454        TnyHeader *header; 
     455        TnyMsg *msg; 
     456        GError **err; 
     457 
     458        GCond* condition; 
     459        gboolean had_callback; 
     460        GMutex *mutex; 
     461 
     462} GetSync; 
     463 
     464static void  
     465get_async (TnyFolder *folder, gboolean cancelled, TnyMsg *msg, GError *err, gpointer user_data) 
     466{ 
     467        GetSync *info = (GetSync *) user_data; 
     468 
     469        if (err && info->err) 
     470                *info->err = g_error_copy (err); 
     471 
     472        if (msg) 
     473                info->msg = g_object_ref (msg); 
     474 
     475        g_mutex_lock (info->mutex); 
     476        g_cond_broadcast (info->condition); 
     477        info->had_callback = TRUE; 
     478        g_mutex_unlock (info->mutex); 
     479} 
     480 
     481static TnyMsg* 
     482get_sync (TnyFolder *folder, TnyHeader *header, GError **err) 
     483{ 
     484        GetSync *info = g_slice_new0 (GetSync); 
     485        TnyMsg *retval = NULL; 
     486 
     487        info->mutex = g_mutex_new (); 
     488        info->condition = g_cond_new (); 
     489        info->had_callback = FALSE; 
     490 
     491        info->folder = g_object_ref (folder); 
     492        info->header = g_object_ref (header); 
     493        info->err = err; 
     494 
     495        tny_folder_get_msg_async (info->folder, info->header,  
     496                get_async, NULL, info); 
     497 
     498        g_mutex_lock (info->mutex); 
     499        if (!info->had_callback) 
     500                g_cond_wait (info->condition, info->mutex); 
     501        g_mutex_unlock (info->mutex); 
     502 
     503        g_mutex_free (info->mutex); 
     504        g_cond_free (info->condition); 
     505 
     506        if (info->msg) 
     507                retval = g_object_ref (info->msg); 
     508 
     509        g_object_unref (info->folder); 
     510        g_object_unref (info->header); 
     511        g_object_unref (info->msg); 
     512 
     513        g_slice_free (GetSync, info); 
     514        return retval; 
     515} 
     516 
     517 
     518 
     519 
     520typedef struct { 
     521        TnyFolder *folder; 
     522        GError **err; 
     523 
     524        GCond* condition; 
     525        gboolean had_callback; 
     526        GMutex *mutex; 
     527 
     528} SyncSync; 
     529 
     530static void  
     531sync_async (TnyFolder *folder, gboolean cancelled, GError *err, gpointer user_data) 
     532{ 
     533        SyncSync *info = (SyncSync *) user_data; 
     534 
     535        if (err && info->err) 
     536                *info->err = g_error_copy (err); 
     537 
     538        g_mutex_lock (info->mutex); 
     539        g_cond_broadcast (info->condition); 
     540        info->had_callback = TRUE; 
     541        g_mutex_unlock (info->mutex); 
     542} 
     543 
     544static void 
     545sync_sync (TnyFolder *self, gboolean expunge, GError **err) 
     546{ 
     547        SyncSync *info = g_slice_new0 (SyncSync); 
     548 
     549        info->mutex = g_mutex_new (); 
     550        info->condition = g_cond_new (); 
     551        info->had_callback = FALSE; 
     552 
     553        info->folder = g_object_ref (self); 
     554        info->err = err; 
     555 
     556        tny_folder_sync_async (info->folder, expunge, sync_async, NULL, info); 
     557 
     558        g_mutex_lock (info->mutex); 
     559        if (!info->had_callback) 
     560                g_cond_wait (info->condition, info->mutex); 
     561        g_mutex_unlock (info->mutex); 
     562 
     563        g_mutex_free (info->mutex); 
     564        g_cond_free (info->condition); 
     565 
     566        g_object_unref (info->folder); 
     567        g_slice_free (SyncSync, info); 
     568} 
     569 
    393570static gpointer 
    394571thread_main (gpointer data) 
     
    522699 
    523700                        tny_list_prepend (hassent, G_OBJECT (header)); 
    524                         msg = tny_folder_get_msg (info->outbox, header, &err); 
     701                        msg = get_sync (info->outbox, header, &err); 
    525702 
    526703                        /* Emits msg-sending signal to inform a new msg is being sent */ 
     
    554731                                { 
    555732                                        GError *newerr = NULL; 
     733                                        GError *serr = NULL; 
    556734                                        priv->cur_i = i; 
    557735                                        tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN); 
    558736                                        tny_header_set_flag (header, TNY_HEADER_FLAG_ANSWERED); 
    559                                         tny_folder_transfer_msgs (info->outbox, hassent, info->sentbox, TRUE, &newerr); 
     737                                        sync_sync (info->outbox, TRUE, &serr); 
     738                                        if (serr) 
     739                                                g_error_free (serr); 
     740                                        transfer_sync (info->outbox, hassent, info->sentbox, TRUE, &newerr); 
    560741                                        if (newerr != NULL) { 
    561742                                                emit_error (self, header, msg, newerr, i, priv->total);