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)
46 if (__pRegistry != null)
55 _AppRegistryImpl::Construct(void)
59 SysAssertf(__pRegistry == null,
60 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
62 const String& packageId = _AppInfo::GetPackageId();
63 String regName = _AppInfo::GetAppRootPath() + L"data/";
65 SysAssertf(!packageId.IsEmpty(), "Empty packageId.");
66 r = regName.Append(static_cast <const String&>(packageId));
67 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] String appending has failed.", GetErrorMessage(r));
69 __pRegistry = new (std::nothrow) Registry();
70 SysTryCatch(NID_APP, __pRegistry != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
71 "[E_OUT_OF_MEMORY] Failed while instantiating registry.");
73 r = __pRegistry->Construct(regName, true);
74 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
77 r = __pRegistry->AddSection(__sectionName);
78 if (r == E_SECTION_ALREADY_EXIST)
80 // section may exist already
84 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
92 SysLog(NID_APP, "Exit.");
99 _AppRegistryImpl::Add(const String& key, const String& value)
101 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
103 result r = E_SUCCESS;
105 r = __pRegistry->AddValue(__sectionName, key, value);
107 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
114 _AppRegistryImpl::Add(const String& key, int value)
116 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
118 result r = E_SUCCESS;
120 r = __pRegistry->AddValue(__sectionName, key, value);
122 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
129 _AppRegistryImpl::Add(const String& key, double value)
131 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
133 result r = E_SUCCESS;
135 r = __pRegistry->AddValue(__sectionName, key, value);
137 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
144 _AppRegistryImpl::Set(const String& key, const String& value)
146 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
148 result r = E_SUCCESS;
150 r = __pRegistry->SetValue(__sectionName, key, value);
152 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
159 _AppRegistryImpl::Set(const String& key, int value)
161 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
163 result r = E_SUCCESS;
165 r = __pRegistry->SetValue(__sectionName, key, value);
167 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
174 _AppRegistryImpl::Set(const String& key, double value)
176 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
178 result r = E_SUCCESS;
180 r = __pRegistry->SetValue(__sectionName, key, value);
182 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
189 _AppRegistryImpl::Save(void)
191 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
193 result r = E_SUCCESS;
195 r = __pRegistry->Flush();
197 SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
204 _AppRegistryImpl::Remove(const String& key)
206 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
208 result r = E_SUCCESS;
210 r = __pRegistry->RemoveValue(__sectionName, key);
212 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
219 _AppRegistryImpl::Get(const String& key, String& value) const
221 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
223 result r = E_SUCCESS;
225 r = __pRegistry->GetValue(__sectionName, key, value);
227 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
234 _AppRegistryImpl::Get(const String& key, int& value) const
236 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
238 result r = E_SUCCESS;
240 r = __pRegistry->GetValue(__sectionName, key, value);
242 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
249 _AppRegistryImpl::Get(const String& key, double& value) const
251 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
253 result r = E_SUCCESS;
255 r = __pRegistry->GetValue(__sectionName, key, value);
257 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));