2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_AppRegistryImpl.cpp
19 * @brief This is the implementation for the _AppRegistryImpl class.
22 #include <FAppAppRegistry.h>
23 #include <FIoRegistry.h>
25 #include <FBaseSysLog.h>
26 #include "FApp_AppRegistryImpl.h"
27 #include "FApp_AppInfo.h"
29 using namespace Tizen::Io;
30 using namespace Tizen::Base;
32 namespace Tizen { namespace App
36 _AppRegistryImpl::_AppRegistryImpl(void)
38 , __sectionName(L"__ApplicationStates")
43 _AppRegistryImpl::~_AppRegistryImpl(void)
50 _AppRegistryImpl::Construct(void)
54 SysAssertf(__pRegistry == null,
55 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 const String& packageId = _AppInfo::GetPackageId();
58 String regName = _AppInfo::GetAppRootPath() + L"data/";
60 SysAssertf(!packageId.IsEmpty(), "Empty package.");
61 r = regName.Append(packageId);
62 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] String appending has failed.", GetErrorMessage(r));
64 __pRegistry = new (std::nothrow) Registry();
65 SysTryCatch(NID_APP, __pRegistry != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
66 "[E_OUT_OF_MEMORY] Failed while instantiating registry.");
68 r = __pRegistry->Construct(regName, true);
69 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
72 r = __pRegistry->AddSection(__sectionName);
73 if (r == E_SECTION_ALREADY_EXIST)
75 // section may exist already
79 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
87 SysLog(NID_APP, "Exit.");
94 _AppRegistryImpl::Add(const String& key, const String& value)
96 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
100 r = __pRegistry->AddValue(__sectionName, key, value);
102 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
109 _AppRegistryImpl::Add(const String& key, int value)
111 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
113 result r = E_SUCCESS;
115 r = __pRegistry->AddValue(__sectionName, key, value);
117 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
124 _AppRegistryImpl::Add(const String& key, double value)
126 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
128 result r = E_SUCCESS;
130 r = __pRegistry->AddValue(__sectionName, key, value);
132 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
139 _AppRegistryImpl::Set(const String& key, const String& value)
141 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
143 result r = E_SUCCESS;
145 r = __pRegistry->SetValue(__sectionName, key, value);
147 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
154 _AppRegistryImpl::Set(const String& key, int value)
156 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
158 result r = E_SUCCESS;
160 r = __pRegistry->SetValue(__sectionName, key, value);
162 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
169 _AppRegistryImpl::Set(const String& key, double value)
171 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
173 result r = E_SUCCESS;
175 r = __pRegistry->SetValue(__sectionName, key, value);
177 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
184 _AppRegistryImpl::Save(void)
186 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
188 result r = E_SUCCESS;
190 r = __pRegistry->Flush();
192 SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
199 _AppRegistryImpl::Remove(const String& key)
201 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
203 result r = E_SUCCESS;
205 r = __pRegistry->RemoveValue(__sectionName, key);
207 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
214 _AppRegistryImpl::Get(const String& key, String& value) const
216 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
218 result r = E_SUCCESS;
220 r = __pRegistry->GetValue(__sectionName, key, value);
222 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
229 _AppRegistryImpl::Get(const String& key, int& value) const
231 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
233 result r = E_SUCCESS;
235 r = __pRegistry->GetValue(__sectionName, key, value);
237 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
244 _AppRegistryImpl::Get(const String& key, double& value) const
246 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
248 result r = E_SUCCESS;
250 r = __pRegistry->GetValue(__sectionName, key, value);
252 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));