From: Dirk-Jan C. Binnema Date: Wed, 14 Feb 2007 09:12:37 +0000 (+0000) Subject: * all: X-Git-Tag: git_migration_finished~4054 X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=27eb32137472bfe15e7126baafe581f097817413;p=modest * all: - add singletons for device and platform fact pmo-trunk-r827 --- diff --git a/src/modest-runtime.c b/src/modest-runtime.c index c4bbdc8..0a30c00 100644 --- a/src/modest-runtime.c +++ b/src/modest-runtime.c @@ -234,6 +234,16 @@ modest_runtime_get_mail_operation_queue (void) +TnyDevice* +modest_runtime_get_device (void) +{ + g_return_val_if_fail (_singletons, NULL); + return modest_singletons_get_device (_singletons); +} + + + + ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account) { diff --git a/src/modest-runtime.h b/src/modest-runtime.h index c081ac5..5e4d0f6 100644 --- a/src/modest-runtime.h +++ b/src/modest-runtime.h @@ -114,7 +114,7 @@ ModestRuntimeDebugFlags modest_runtime_get_debug_flags (void) G_GNUC_CONST; * * get the ModestConf singleton instance * - * Returns: the ModestConf singleton + * Returns: the ModestConf singleton. This should NOT be unref'd. **/ ModestConf* modest_runtime_get_conf (void); @@ -124,7 +124,7 @@ ModestConf* modest_runtime_get_conf (void); * * get the ModestAccountMgr singleton instance * - * Returns: the ModestAccountMgr singleton + * Returns: the ModestAccountMgr singleton. This should NOT be unref'd. **/ ModestAccountMgr* modest_runtime_get_account_mgr (void); @@ -133,7 +133,7 @@ ModestAccountMgr* modest_runtime_get_account_mgr (void); * * get the ModestTnyAccountStore singleton instance * - * Returns: the ModestTnyAccountStore singleton + * Returns: the ModestTnyAccountStore singleton. This should NOT be unref'd. **/ ModestTnyAccountStore* modest_runtime_get_account_store (void); @@ -143,17 +143,29 @@ ModestTnyAccountStore* modest_runtime_get_account_store (void); * * get the ModestCacheMgr singleton instance * - * Returns: the ModestCacheMgr singleton + * Returns: the ModestCacheMgr singleton. This should NOT be unref'd. **/ ModestCacheMgr* modest_runtime_get_cache_mgr (void); + +/** + * modest_runtime_get_cache_mgr: + * + * get the TnyDevice singleton instance + * + * Returns: the TnyDevice singleton. This should NOT be unref'd. + **/ +TnyDevice* modest_runtime_get_device (void); + + + /** * modest_runtime_get_mail_operation_queue: * * get the #ModestMailOperationQueue singleton instance * - * Returns: the #ModestMailOperationQueue singleton + * Returns: the #ModestMailOperationQueue singleton. This should NOT be unref'd. **/ ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void); @@ -165,7 +177,7 @@ ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void); * get the send queue for the given account * * Returns: the #ModestTnySendQueue singleton instance for this account - * (ie., one singleton per account) + * (ie., one singleton per account). This should NOT be unref'd. **/ ModestTnySendQueue* modest_runtime_get_send_queue (TnyTransportAccount *account); diff --git a/src/modest-singletons.c b/src/modest-singletons.c index 1dc6a03..713fc6f 100644 --- a/src/modest-singletons.c +++ b/src/modest-singletons.c @@ -41,6 +41,8 @@ struct _ModestSingletonsPrivate { ModestTnyAccountStore *account_store; ModestCacheMgr *cache_mgr; ModestMailOperationQueue *mail_op_queue; + TnyPlatformFactory *platform_fact; + TnyDevice *device; }; #define MODEST_SINGLETONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ MODEST_TYPE_SINGLETONS, \ @@ -95,6 +97,8 @@ modest_singletons_init (ModestSingletons *obj) priv->account_store = NULL; priv->cache_mgr = NULL; priv->mail_op_queue = NULL; + priv->platform_fact = NULL; + priv->device = NULL; priv->conf = modest_conf_new (); if (!priv->conf) { @@ -125,6 +129,20 @@ modest_singletons_init (ModestSingletons *obj) g_printerr ("modest: cannot create modest mail operation queue instance\n"); return; } + + priv->platform_fact = modest_tny_platform_factory_get_instance (); + if (!priv->platform_fact) { + g_printerr ("modest: cannot create platform factory instance\n"); + return; + } + + priv->device = tny_platform_factory_new_device (priv->platform_fact); + if (!priv->device) { + g_printerr ("modest: cannot create tny device instance\n"); + return; + } + + } @@ -168,6 +186,22 @@ modest_singletons_finalize (GObject *obj) "priv->cache_mgr"); priv->cache_mgr = NULL; } + + if (priv->device) { + g_object_unref (G_OBJECT(priv->device)); + check_object_is_dead ((GObject*)priv->cache_mgr, + "priv->device"); + priv->device = NULL; + } + + if (priv->platform_fact) { + g_object_unref (G_OBJECT(priv->platform_fact)); + check_object_is_dead ((GObject*)priv->cache_mgr, + "priv->platform_fact"); + priv->platform_fact = NULL; + } + + G_OBJECT_CLASS(parent_class)->finalize (obj); } @@ -183,7 +217,7 @@ modest_singletons_new (void) /* widget_factory will still be NULL, as it is initialized lazily */ if (!(priv->conf && priv->account_mgr && priv->account_store && - priv->cache_mgr && priv->mail_op_queue)) { + priv->cache_mgr && priv->mail_op_queue && priv->device && priv->platform_fact)) { g_printerr ("modest: failed to create singletons instance\n"); g_object_unref (G_OBJECT(self)); self = NULL; @@ -227,3 +261,21 @@ modest_singletons_get_mail_operation_queue (ModestSingletons *self) g_return_val_if_fail (self, NULL); return MODEST_SINGLETONS_GET_PRIVATE(self)->mail_op_queue; } + + + +TnyDevice* +modest_singletons_get_device (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->device; +} + + + +TnyPlatformFactory* +modest_singletons_get_platform_factory (ModestSingletons *self) +{ + g_return_val_if_fail (self, NULL); + return MODEST_SINGLETONS_GET_PRIVATE(self)->platform_fact; +} diff --git a/src/modest-singletons.h b/src/modest-singletons.h index 84e647a..b6f0448 100644 --- a/src/modest-singletons.h +++ b/src/modest-singletons.h @@ -38,6 +38,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -135,6 +136,33 @@ ModestTnyAccountStore* modest_singletons_get_account_store (ModestSingletons ModestCacheMgr* modest_singletons_get_cache_mgr (ModestSingletons *self); + +/** + * modest_singletons_get_platform_factory: + * @self: a valid #ModestSingletons instance + * + * get the #TnyPlatformFactory singleton instance + * don't use this function directly, use the modest-runtime + * functions instead. + * + * Returns: the #TnyPlatformFactory singleton + **/ +TnyPlatformFactory* modest_singletons_get_platform_factory (ModestSingletons *self); + + +/** + * modest_singletons_get_device: + * @self: a valid #ModestSingletons instance + * + * get the #TnyDevice singleton instance + * don't use this function directly, use the modest-runtime + * functions instead. + * + * Returns: the #TnyDevice singleton + **/ +TnyDevice* modest_singletons_get_device (ModestSingletons *self); + + /** * modest_singletons_get_mail_operation_queue: * @self: a valid ModestSingletons instance diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 2812c9d..4d005e0 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -527,7 +527,7 @@ modest_tny_account_store_get_device (TnyAccountStore *self) ModestTnyAccountStorePrivate *priv; priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE (self); - + if (!priv->device) priv->device = tny_platform_factory_new_device (modest_tny_platform_factory_get_instance());