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;
31 using namespace Tizen::Base::Collection;
33 namespace Tizen { namespace App
37 _AppRegistryImpl::_AppRegistryImpl(void)
39 , __sectionName(L"__ApplicationStates")
44 _AppRegistryImpl::~_AppRegistryImpl(void)
51 _AppRegistryImpl::Construct(void)
55 SysAssertf(__pRegistry == null,
56 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58 const String& packageId = _AppInfo::GetPackageId();
59 String regName = _AppInfo::GetAppRootPath() + L"data/";
61 SysAssertf(!packageId.IsEmpty(), "Empty package.");
62 r = regName.Append(packageId);
63 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] String appending has failed.", GetErrorMessage(r));
65 __pRegistry = new (std::nothrow) Registry();
66 SysTryCatch(NID_APP, __pRegistry != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
67 "[E_OUT_OF_MEMORY] Failed while instantiating registry.");
69 r = __pRegistry->Construct(regName, true);
70 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
73 r = __pRegistry->AddSection(__sectionName);
74 if (r == E_SECTION_ALREADY_EXIST)
76 // section may exist already
80 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
88 SysLog(NID_APP, "Exit.");
95 _AppRegistryImpl::Add(const String& key, const String& value)
97 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
101 r = __pRegistry->AddValue(__sectionName, key, value);
103 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
110 _AppRegistryImpl::Add(const String& key, int value)
112 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
114 result r = E_SUCCESS;
116 r = __pRegistry->AddValue(__sectionName, key, value);
118 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
125 _AppRegistryImpl::Add(const String& key, double value)
127 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
129 result r = E_SUCCESS;
131 r = __pRegistry->AddValue(__sectionName, key, value);
133 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
140 _AppRegistryImpl::Set(const String& key, const String& value)
142 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
144 result r = E_SUCCESS;
146 r = __pRegistry->SetValue(__sectionName, key, value);
148 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
155 _AppRegistryImpl::Set(const String& key, int value)
157 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
159 result r = E_SUCCESS;
161 r = __pRegistry->SetValue(__sectionName, key, value);
163 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
170 _AppRegistryImpl::Set(const String& key, double value)
172 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
174 result r = E_SUCCESS;
176 r = __pRegistry->SetValue(__sectionName, key, value);
178 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
185 _AppRegistryImpl::Save(void)
187 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
189 result r = E_SUCCESS;
191 r = __pRegistry->Flush();
193 SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
200 _AppRegistryImpl::Remove(const String& key)
202 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
204 result r = E_SUCCESS;
206 r = __pRegistry->RemoveValue(__sectionName, key);
208 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
215 _AppRegistryImpl::Get(const String& key, String& value) const
217 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
219 result r = E_SUCCESS;
221 r = __pRegistry->GetValue(__sectionName, key, value);
223 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
230 _AppRegistryImpl::Get(const String& key, int& value) const
232 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
234 result r = E_SUCCESS;
236 r = __pRegistry->GetValue(__sectionName, key, value);
238 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
245 _AppRegistryImpl::Get(const String& key, double& value) const
247 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
249 result r = E_SUCCESS;
251 r = __pRegistry->GetValue(__sectionName, key, value);
253 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));