Changeset 3711

Show
Ignore:
Timestamp:
07/01/08 17:33:35
Author:
jdapena
Message:

* libtinymail-camel/camel-lite/camel/camel-provider.[ch]:

        • Now providers offer a new shutdown handler, that will be
          called on shutting down camel.

* libtinymail-camel/camel-lite/camel/camel.c:

        • Use the providers shutdown handler on shutting down camel.

* libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-provider.c:

        • Implement new provider shutdown handler, to kill the login delay
          threads on shutting down tinymail.

* libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.[ch]:

        • New method to kill the login delay thread. This is used to kill
          the thread on shutting down tinymail.

* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-provider.c:

        • Set as NULL the default shutdown handler.

* libtinymail-camel/tny-camel-pop-store-account.c:

        • Manage properly the internal inbox reference to avoid leaking it.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-camel/camel-lite/camel/camel-provider.c

    r3385 r3711  
    270270} 
    271271 
     272void camel_provider_shutdown (CamelProvider *provider) 
     273{ 
     274        if (provider->shutdown) { 
     275                provider->shutdown ((CamelObject *) provider); 
     276        } 
     277} 
     278 
     279void camel_provider_shutdown_all (void) 
     280{ 
     281        GList *providers_list; 
     282        GList *node; 
     283 
     284        providers_list = camel_provider_list (FALSE); 
     285        for (node = providers_list; node != NULL; node = g_list_next (node)) { 
     286                CamelProvider *provider = (CamelProvider *) node->data; 
     287                camel_provider_shutdown (provider); 
     288        } 
     289        g_list_free (providers_list); 
     290} 
     291 
    272292static gint 
    273293provider_compare (gconstpointer a, gconstpointer b) 
  • trunk/libtinymail-camel/camel-lite/camel/camel-provider.h

    r2950 r3711  
    145145 
    146146typedef int (*CamelProviderAutoDetectFunc) (CamelURL *url, GHashTable **auto_detected, CamelException *ex); 
     147typedef void (*CamelProviderShutdownFunc) (CamelObject *provider); 
     148 
    147149 
    148150typedef struct { 
     
    209211        const char *license_file; 
    210212 
     213        /* Shutdown function. Will be called in camel_shutdown. 
     214         */ 
     215        CamelProviderShutdownFunc shutdown; 
     216 
    211217        /* Private to the provider */ 
    212218        void *priv; 
     
    225231void camel_provider_load(const char *path, CamelException *ex); 
    226232void camel_provider_register(CamelProvider *provider); 
     233void camel_provider_shutdown (CamelProvider *provider); 
     234void camel_provider_shutdown_all (void); 
    227235GList *camel_provider_list(gboolean load); 
    228236CamelProvider *camel_provider_get(const char *url_string, CamelException *ex); 
  • trunk/libtinymail-camel/camel-lite/camel/camel.c

    r3705 r3711  
    5454        if (!initialised) 
    5555                return; 
     56 
     57        camel_provider_shutdown_all (); 
    5658 
    5759        initialised = FALSE; 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-provider.c

    r2950 r3711  
    114114        imap_provider.authtypes = g_list_prepend (imap_provider.authtypes, &camel_imap_password_authtype); 
    115115        imap_provider.translation_domain = GETTEXT_PACKAGE; 
     116        imap_provider.shutdown = NULL; 
    116117 
    117118        camel_provider_register(&imap_provider); 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-provider.c

    r2950 r3711  
    9090}; 
    9191 
     92static void 
     93pop3_shutdown (CamelProvider *provider) 
     94{ 
     95        camel_pop3_store_kill_threads (); 
     96} 
     97 
    9298void 
    9399camel_provider_module_init(void) 
     
    106112        pop3_provider.authtypes = g_list_prepend(pop3_provider.authtypes, &camel_pop3_password_authtype); 
    107113        pop3_provider.translation_domain = GETTEXT_PACKAGE; 
     114        pop3_provider.shutdown = pop3_shutdown; 
    108115 
    109116        camel_provider_register(&pop3_provider); 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c

    r3688 r3711  
    8484 
    8585static CamelStoreClass *parent_class = NULL; 
     86static GMutex *wait_for_login_mutex = NULL; 
     87static GCond *wait_for_login_cond = NULL; 
     88static GList *wait_for_login_threads = NULL; 
    8689 
    8790static void finalize (CamelObject *object); 
     
    162165 
    163166        if (store->engine == NULL) { 
    164                 g_static_rec_mutex_lock (store->eng_lock); 
     167                g_static_rec_mutex_unlock (store->eng_lock); 
    165168                return TRUE; 
    166169        } 
     
    175178        } 
    176179 
     180        g_static_rec_mutex_unlock (store->eng_lock); 
     181 
    177182        g_timeout_add (20000, unref_it, store->engine); 
    178183        store->engine = NULL; 
    179         g_static_rec_mutex_unlock (store->eng_lock); 
    180184 
    181185        /* camel_object_unref((CamelObject *)store->engine); */ 
     
    404408        g_static_rec_mutex_unlock (store->eng_lock); 
    405409 
     410        g_mutex_lock (wait_for_login_mutex); 
    406411        while (!killed) { 
    407  
    408                 sleep (login_delay); 
    409  
     412                GTimeVal tv_delay = {0, 0}; 
     413 
     414                tv_delay.tv_sec = login_delay; 
     415 
     416                g_cond_timed_wait (wait_for_login_cond, wait_for_login_mutex, &tv_delay); 
     417 
     418                if (!store->engine) { 
     419                        break; 
     420                } 
    410421 
    411422                if (!store->is_refreshing) { 
     
    423434 
    424435        camel_object_unref (store); 
     436        wait_for_login_threads = g_list_append (wait_for_login_threads, store->login_delay_thread); 
     437        g_mutex_unlock (wait_for_login_mutex); 
    425438        return NULL; 
    426439} 
     
    921934camel_pop3_store_prepare (CamelStore *store) 
    922935{ 
     936        CamelPOP3Store *pstore = (CamelPOP3Store *) store; 
    923937        camel_object_ref (store); 
    924         g_thread_create (wait_for_login_delay, store, FALSE, NULL); 
     938        g_mutex_lock (wait_for_login_mutex); 
     939        pstore->login_delay_thread = g_thread_create (wait_for_login_delay, store, TRUE, NULL); 
     940        g_mutex_unlock (wait_for_login_mutex); 
    925941} 
    926942 
     
    10201036 
    10211037        g_timeout_add (20000, unref_it, store->engine); 
    1022         /* camel_object_unref((CamelObject *)store->engine); */ 
    10231038        store->engine = NULL; 
    1024  
    10251039        //g_static_rec_mutex_unlock (store->eng_lock); 
    10261040 
     
    12001214} 
    12011215 
     1216void 
     1217camel_pop3_store_kill_threads (void) 
     1218{ 
     1219        GThread *thread_to_join; 
     1220        g_mutex_lock (wait_for_login_mutex); 
     1221        while (wait_for_login_threads) { 
     1222                thread_to_join = wait_for_login_threads->data; 
     1223                g_cond_broadcast (wait_for_login_cond); 
     1224                g_mutex_unlock (wait_for_login_mutex); 
     1225                g_thread_join (thread_to_join); 
     1226                g_mutex_lock (wait_for_login_mutex); 
     1227                wait_for_login_threads = g_list_remove (wait_for_login_threads, thread_to_join); 
     1228        } 
     1229        g_mutex_unlock (wait_for_login_mutex); 
     1230} 
     1231 
    12021232static void 
    12031233camel_pop3_store_class_init (CamelPOP3StoreClass *camel_pop3_store_class) 
     
    12111241 
    12121242        parent_class = CAMEL_STORE_CLASS (camel_type_get_global_classfuncs (camel_disco_store_get_type ())); 
     1243        wait_for_login_mutex = g_mutex_new (); 
     1244        wait_for_login_cond = g_cond_new (); 
     1245        wait_for_login_threads = NULL; 
    12131246 
    12141247        /* virtual method overload */ 
     
    12561289        store->uidl_lock = g_new0 (GStaticRecMutex, 1); 
    12571290        g_static_rec_mutex_init (store->uidl_lock); 
     1291        store->login_delay_thread = NULL; 
    12581292 
    12591293        return; 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.h

    r3044 r3711  
    5454        gpointer book; 
    5555        guint login_delay; 
     56        GThread *login_delay_thread; 
    5657 
    5758        GPtrArray *uids; 
     
    7980 
    8081void camel_pop3_store_destroy_lists (CamelPOP3Store *pop3_store); 
     82void camel_pop3_store_kill_threads (void); 
    8183 
    8284G_END_DECLS 
  • trunk/libtinymail-camel/tny-camel-pop-store-account.c

    r3666 r3711  
    9696        if (self && TNY_IS_CAMEL_STORE_ACCOUNT (self)) { 
    9797                TnyCamelStoreAccountPriv *priv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (self); 
     98                TnyCamelPopStoreAccountPriv *ppriv = TNY_CAMEL_POP_STORE_ACCOUNT_GET_PRIVATE (self); 
    9899                g_static_rec_mutex_lock (priv->factory_lock); 
    99100                priv->managed_folders = g_list_remove_all (priv->managed_folders, folder); 
    100101                g_static_rec_mutex_unlock (priv->factory_lock); 
     102                if (ppriv->inbox == folder) { 
     103                        ppriv->inbox = NULL; 
     104                } 
    101105        } 
    102106} 
     
    116120                g_object_weak_ref (G_OBJECT (ppriv->inbox), (GWeakNotify) notify_factory_del, self); 
    117121                priv->managed_folders = g_list_prepend (priv->managed_folders, ppriv->inbox); 
     122        } else { 
     123                g_object_ref (ppriv->inbox); 
    118124        } 
    119125 
    120126        g_static_rec_mutex_unlock (priv->factory_lock); 
    121127 
    122         return (TnyFolder *) g_object_ref (ppriv->inbox)
     128        return (TnyFolder *) ppriv->inbox
    123129} 
    124130 
     
    142148{ 
    143149        TnyCamelPopStoreAccountPriv *priv = TNY_CAMEL_POP_STORE_ACCOUNT_GET_PRIVATE (object); 
    144  
    145         if (priv->inbox) 
    146                 g_object_unref (priv->inbox); 
    147150 
    148151        g_mutex_free (priv->lock);