From: Sunwook Bae Date: Wed, 28 Aug 2013 13:15:13 +0000 (+0900) Subject: Separate the load methods (r/rw) X-Git-Tag: accepted/tizen/20130927.081017^2~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90c8889f8f31643c5953ac251442c772b9bfc9fb;p=platform%2Fframework%2Fnative%2Fappfw.git Separate the load methods (r/rw) Change-Id: I4251cce784d1e0287d6b5175ec3a867a6310910f Signed-off-by: Sunwook Bae --- diff --git a/src/app/FApp_AppRegistryImpl.cpp b/src/app/FApp_AppRegistryImpl.cpp index 11c2a89..ab1623f 100644 --- a/src/app/FApp_AppRegistryImpl.cpp +++ b/src/app/FApp_AppRegistryImpl.cpp @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -56,21 +57,21 @@ _AppRegistryImpl::Construct(void) __mutex.Create(); - SysLog(NID_APP, "Exit."); return r; } result _AppRegistryImpl::Add(const String& key, const String& value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->AddValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -78,14 +79,15 @@ _AppRegistryImpl::Add(const String& key, const String& value) result _AppRegistryImpl::Add(const String& key, int value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->AddValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -93,14 +95,15 @@ _AppRegistryImpl::Add(const String& key, int value) result _AppRegistryImpl::Add(const String& key, double value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->AddValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -108,14 +111,15 @@ _AppRegistryImpl::Add(const String& key, double value) result _AppRegistryImpl::Set(const String& key, const String& value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->SetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -123,14 +127,15 @@ _AppRegistryImpl::Set(const String& key, const String& value) result _AppRegistryImpl::Set(const String& key, int value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->SetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -138,14 +143,15 @@ _AppRegistryImpl::Set(const String& key, int value) result _AppRegistryImpl::Set(const String& key, double value) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->SetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -159,14 +165,15 @@ _AppRegistryImpl::Save(void) result _AppRegistryImpl::Remove(const String& key) { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_WRITE); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->RemoveValue(__sectionName, key); SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -174,14 +181,15 @@ _AppRegistryImpl::Remove(const String& key) result _AppRegistryImpl::Get(const String& key, String& value) const { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_ONLY); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->GetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -189,14 +197,15 @@ _AppRegistryImpl::Get(const String& key, String& value) const result _AppRegistryImpl::Get(const String& key, int& value) const { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_ONLY); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->GetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } @@ -204,26 +213,36 @@ _AppRegistryImpl::Get(const String& key, int& value) const result _AppRegistryImpl::Get(const String& key, double& value) const { - Registry* pReg = LoadN(); + MutexGuard lock(__mutex); + + Registry* pReg = LoadN(READ_ONLY); SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller..."); - __mutex.Acquire(); result r = pReg->GetValue(__sectionName, key, value); SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r)); + delete pReg; - __mutex.Release(); return r; } Registry* -_AppRegistryImpl::LoadN(void) const +_AppRegistryImpl::LoadN(LoadType type) const { + result r = E_SUCCESS; + Registry* pReg = new (std::nothrow) Registry(); SysTryReturn(NID_APP, pReg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient."); - __mutex.Acquire(); - result r = pReg->Construct(__regPath, "a+"); + if (type == READ_ONLY) + { + r = pReg->Construct(__regPath, "r"); + } + else + { + r = pReg->Construct(__regPath, "a+"); + } + SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed. %s occurred.", __regPath.GetPointer(), GetErrorMessage(r)); @@ -232,7 +251,7 @@ _AppRegistryImpl::LoadN(void) const { r = E_SUCCESS; } - __mutex.Release(); + SysAssertf(!IsFailed(r), "Adding section to registry has failed. %s occurred.", GetErrorMessage(r)); SetLastResult(r); diff --git a/src/app/FApp_AppRegistryImpl.h b/src/app/FApp_AppRegistryImpl.h index ba17431..4a1e35e 100644 --- a/src/app/FApp_AppRegistryImpl.h +++ b/src/app/FApp_AppRegistryImpl.h @@ -23,9 +23,9 @@ #define _FAPP_INTERNAL_APP_REGISTRY_IMPL_H_ #include -#include #include +namespace Tizen { namespace Base { namespace Runtime { class Mutex; } } } namespace Tizen { namespace Io { class Registry; } } namespace Tizen { namespace App @@ -226,6 +226,12 @@ private: */ _AppRegistryImpl& operator =(const _AppRegistryImpl& source); +private: + enum LoadType { + READ_ONLY, + READ_WRITE + }; + /** * Loads the registry file. * @@ -233,7 +239,7 @@ private: * @return The registry instance * @exception E_SUCCESS The method is successful. */ - Tizen::Io::Registry* LoadN(void) const; + Tizen::Io::Registry* LoadN(LoadType type) const; private: const Tizen::Base::String __sectionName;