X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-singletons.c;h=3084cbd6667215bf6314ae7fb2085c6daf963f5c;hp=c373988d406f6f0aa1c53b788d37658b38b50661;hb=4a97c4a2b6ba57b415de727f389f44505f032824;hpb=bf831b6566516e6b57de7a64afb732eb8686e792 diff --git a/src/modest-singletons.c b/src/modest-singletons.c index c373988..3084cbd 100644 --- a/src/modest-singletons.c +++ b/src/modest-singletons.c @@ -29,6 +29,7 @@ #include "modest-singletons.h" #include "modest-runtime.h" +#include "modest-debug.h" /* 'private'/'protected' functions */ static void modest_singletons_class_init (ModestSingletonsClass *klass); @@ -40,7 +41,6 @@ struct _ModestSingletonsPrivate { ModestConf *conf; ModestAccountMgr *account_mgr; ModestEmailClipboard *email_clipboard; - ModestTnyAccountStore *account_store; ModestCacheMgr *cache_mgr; ModestMailOperationQueue *mail_op_queue; TnyPlatformFactory *platform_fact; @@ -98,7 +98,6 @@ modest_singletons_init (ModestSingletons *obj) priv->conf = NULL; priv->account_mgr = NULL; priv->email_clipboard = NULL; - priv->account_store = NULL; priv->cache_mgr = NULL; priv->mail_op_queue = NULL; priv->platform_fact = NULL; @@ -135,12 +134,6 @@ modest_singletons_init (ModestSingletons *obj) return; } - priv->account_store = modest_tny_account_store_new (priv->account_mgr, priv->device); - if (!priv->account_store) { - g_printerr ("modest: cannot create modest tny account store instance\n"); - return; - } - priv->cache_mgr = modest_cache_mgr_new (); if (!priv->cache_mgr) { g_printerr ("modest: cannot create modest cache mgr instance\n"); @@ -166,61 +159,59 @@ modest_singletons_finalize (GObject *obj) ModestSingletonsPrivate *priv; priv = MODEST_SINGLETONS_GET_PRIVATE(obj); - - if (priv->account_store) { - modest_runtime_verify_object_last_ref(priv->account_store,""); - g_object_unref (G_OBJECT(priv->account_store)); - priv->account_store = NULL; - } - - if (priv->account_mgr) { - modest_runtime_verify_object_last_ref(priv->account_mgr,""); - g_object_unref (G_OBJECT(priv->account_mgr)); - priv->account_mgr = NULL; - } - - if (priv->email_clipboard) { - modest_runtime_verify_object_last_ref(priv->email_clipboard,""); - g_object_unref (G_OBJECT(priv->email_clipboard)); - priv->email_clipboard = NULL; + + if (priv->window_mgr) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->window_mgr,""); + g_object_unref (G_OBJECT(priv->window_mgr)); + priv->window_mgr = NULL; } - - if (priv->conf) { - modest_runtime_verify_object_last_ref(priv->conf,""); - g_object_unref (G_OBJECT(priv->conf)); - priv->conf = NULL; + + if (priv->mail_op_queue) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->mail_op_queue,""); + g_object_unref (G_OBJECT(priv->mail_op_queue)); + priv->mail_op_queue = NULL; } if (priv->cache_mgr) { - modest_runtime_verify_object_last_ref(priv->cache_mgr,""); + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->cache_mgr,""); g_object_unref (G_OBJECT(priv->cache_mgr)); priv->cache_mgr = NULL; } if (priv->device) { - modest_runtime_verify_object_last_ref(priv->device,""); + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->device,""); g_object_unref (G_OBJECT(priv->device)); priv->device = NULL; } if (priv->platform_fact) { - modest_runtime_verify_object_last_ref(priv->platform_fact,""); + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->platform_fact,""); g_object_unref (G_OBJECT(priv->platform_fact)); priv->platform_fact = NULL; } + + if (priv->email_clipboard) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->email_clipboard,""); + g_object_unref (G_OBJECT(priv->email_clipboard)); + priv->email_clipboard = NULL; + } - if (priv->mail_op_queue) { - modest_runtime_verify_object_last_ref(priv->mail_op_queue,""); - g_object_unref (G_OBJECT(priv->mail_op_queue)); - priv->mail_op_queue = NULL; + /* It is important that the account manager is uninitialized after + * the mail op queue is uninitialized because the mail op queue + * cancells any mail operations which in turn access the account + * manager (see modest_mail_operation_notify_end()). */ + if (priv->account_mgr) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->account_mgr,""); + g_object_unref (G_OBJECT(priv->account_mgr)); + priv->account_mgr = NULL; } - if (priv->window_mgr) { - modest_runtime_verify_object_last_ref(priv->window_mgr,""); - g_object_unref (G_OBJECT(priv->window_mgr)); - priv->window_mgr = NULL; + if (priv->conf) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->conf,""); + g_object_unref (G_OBJECT(priv->conf)); + priv->conf = NULL; } - + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -232,16 +223,17 @@ modest_singletons_new (void) static gboolean invoked = FALSE; if (invoked) { - g_printerr ("modest: modest_singletons_new may only be called once\n"); - g_assert (!invoked); /* abort */ - return NULL; /* g_assert may be NOP */ + g_printerr ("%s: modest: modest_singletons_new may only be called once, aborting...\n", + __FUNCTION__); + abort(); + return NULL; } self = MODEST_SINGLETONS(g_object_new(MODEST_TYPE_SINGLETONS, NULL)); priv = MODEST_SINGLETONS_GET_PRIVATE(self); /* widget_factory will still be NULL, as it is initialized lazily */ - if (!(priv->conf && priv->account_mgr && priv->email_clipboard && priv->account_store && + if (!(priv->conf && priv->account_mgr && priv->email_clipboard && priv->cache_mgr && priv->mail_op_queue && priv->device && priv->platform_fact)) { g_printerr ("modest: failed to create singletons object\n"); g_object_unref (G_OBJECT(self)); @@ -274,13 +266,6 @@ modest_singletons_get_email_clipboard (ModestSingletons *self) return MODEST_SINGLETONS_GET_PRIVATE(self)->email_clipboard; } -ModestTnyAccountStore* -modest_singletons_get_account_store (ModestSingletons *self) -{ - g_return_val_if_fail (self, NULL); - return MODEST_SINGLETONS_GET_PRIVATE(self)->account_store; -} - ModestCacheMgr* modest_singletons_get_cache_mgr (ModestSingletons *self) {