* @brief This is the implementation for the _AppRegistryImpl class.
*/
-#include <FAppAppRegistry.h>
+#include <FBaseSysLog.h>
+#include <FIoFile.h>
+#include <FIoFileAttributes.h>
#include <FIoRegistry.h>
+#include "FAppAppRegistry.h"
-#include <FBaseSysLog.h>
#include "FApp_AppRegistryImpl.h"
#include "FApp_AppInfo.h"
namespace Tizen { namespace App
{
-
_AppRegistryImpl::_AppRegistryImpl(void)
: __pRegistry(null)
, __sectionName(L"__ApplicationStates")
{
}
-
_AppRegistryImpl::~_AppRegistryImpl(void)
{
- delete __pRegistry;
}
-
result
_AppRegistryImpl::Construct(void)
{
- result r = E_SUCCESS;
-
- SysAssertf(__pRegistry == null,
- "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
-
const String& packageId = _AppInfo::GetPackageId();
- String regName = _AppInfo::GetAppRootPath() + L"data/";
-
SysAssertf(!packageId.IsEmpty(), "Empty package.");
- r = regName.Append(packageId);
- SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] String appending has failed.", GetErrorMessage(r));
-
- __pRegistry = new (std::nothrow) Registry();
- SysTryCatch(NID_APP, __pRegistry != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
- "[E_OUT_OF_MEMORY] Failed while instantiating registry.");
-
- r = __pRegistry->Construct(regName, true);
- SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
- GetErrorMessage(r));
-
- r = __pRegistry->AddSection(__sectionName);
- if (r == E_SECTION_ALREADY_EXIST)
- {
- // section may exist already
- r = E_SUCCESS;
- }
-
- SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
- return r;
-
-CATCH:
- delete __pRegistry;
- __pRegistry = null;
+ __regPath = _AppInfo::GetAppRootPath() + L"data/";
+ result r = __regPath.Append(packageId);
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "String appending has failed.");
SysLog(NID_APP, "Exit.");
-
return r;
}
-
result
_AppRegistryImpl::Add(const String& key, const String& value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->AddValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Add(const String& key, int value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->AddValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Add(const String& key, double value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->AddValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Set(const String& key, const String& value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->SetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Set(const String& key, int value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->SetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Set(const String& key, double value)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->SetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Save(void)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
-
- r = __pRegistry->Flush();
-
- SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
-
- return r;
+ return E_SUCCESS;
}
-
result
_AppRegistryImpl::Remove(const String& key)
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->RemoveValue(__sectionName, key);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Get(const String& key, String& value) const
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->GetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Get(const String& key, int& value) const
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->GetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
-
result
_AppRegistryImpl::Get(const String& key, double& value) const
{
- SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
-
- result r = E_SUCCESS;
+ result r = Load();
+ SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
r = __pRegistry->GetValue(__sectionName, key, value);
-
SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
+ Unload();
return r;
}
+result
+_AppRegistryImpl::Load(void) const
+{
+ __pRegistry = new (std::nothrow) Registry();
+ SysTryReturnResult(NID_APP, __pRegistry != null, E_OUT_OF_MEMORY, "Instantiating registry has failed.");
+
+ result r = __pRegistry->Construct(__regPath, "a+");
+ SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed.", __regPath.GetPointer());
+
+ r = __pRegistry->AddSection(__sectionName);
+ if (r == E_SECTION_ALREADY_EXIST)
+ {
+ r = E_SUCCESS;
+ }
+ SysAssertf(!IsFailed(r), "Adding section to registry has failed.");
+
+ return E_SUCCESS;
+}
+
+void
+_AppRegistryImpl::Unload(void) const
+{
+ delete __pRegistry;
+}
+
+}} // Tizen::App
-} } // Tizen::App
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value A string value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value An integer value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value A floating point value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_ALREADY_EXIST The key has already been used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value A string value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value An integer value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
* @return An error code
* @param[in] key A key corresponding to the value
* @param[in] value A floating point value
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
* @exception E_OUT_OF_MEMORY Insufficient memory.
*
* @since 1.0
* @return An error code
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
*/
result Save(void);
* @since 1.0
* @return An error code
* @param[in] key The key of the value to be removed
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
*/
result Remove(const Tizen::Base::String& key);
* @return An error code
* @param[in] key The key of the value to retrieve
* @param[out] value A string value to be retrieved
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
*/
* @return An error code
* @param[in] key The key of the value to retrieve
* @param[out] value An integer value to be retrieved
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
*/
* @return An error code
* @param[in] key The key of the value to retrieve
* @param[out] value A floating point value to be retrieved
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The length of the specified string for a section or entry is smaller than or equal to zero. Or, a @c null value or string with '\0' and '\n' was passed.
* @exception E_KEY_NOT_FOUND The specified key was not used in the application preferences.
*/
* Allocates memory for an _AppRegistryImpl object.
*
* @since 1.0
- *
* @return An error code
- * @exception E_SUCCESS The method was successful.
+ * @exception E_SUCCESS The method is successful.
*/
result Construct(void);
*/
_AppRegistryImpl& operator =(const _AppRegistryImpl& source);
+ /**
+ * Loads the registry file.
+ *
+ * @since 2.2
+ * @return An error code
+ * @exception E_SUCCESS The method is successful.
+ */
+ result Load(void) const;
+
+ /*
+ * Unloads the registry file.
+ *
+ * @since 2.2
+ */
+ void Unload(void) const;
+
private:
- Tizen::Io::Registry* __pRegistry;
+ mutable Tizen::Io::Registry* __pRegistry;
const Tizen::Base::String __sectionName;
+ Tizen::Base::String __regPath;
friend class AppRegistry;
}; // _AppRegistryImpl