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 <FBaseSysLog.h>
23 #include <FBaseRtMutexGuard.h>
25 #include <FIoRegistry.h>
26 #include <FAppAppRegistry.h>
28 #include "FApp_AppRegistryImpl.h"
29 #include "FApp_AppInfo.h"
31 using namespace Tizen::Io;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
35 namespace Tizen { namespace App
38 static const ReadOnlyTag ReadOnly = {};
39 static const ReadWriteTag ReadWrite = {};
41 _AppRegistryImpl::_AppRegistryImpl(void)
42 : __sectionName(L"__ApplicationStates")
46 _AppRegistryImpl::~_AppRegistryImpl(void)
51 _AppRegistryImpl::Construct(void)
53 const String& packageId = _AppInfo::GetPackageId();
54 SysAssertf(!packageId.IsEmpty(), "Empty package.");
56 __regPath = _AppInfo::GetAppRootPath() + L"data/";
57 result r = __regPath.Append(packageId);
58 SysTryReturnResult(NID_APP, !IsFailed(r), r, "String appending has failed.");
61 SysTryReturnResult(NID_APP, !IsFailed(r), r, "Mutex intialization failed.");
64 MutexGuard lock(__mutex);
67 r = reg.Construct(__regPath, "a+");
68 SysAssertf(!IsFailed(r), "[%s] Constructing the registry file (%ls) has failed.", GetErrorMessage(r), __regPath.GetPointer());
70 r = reg.AddSection(__sectionName);
71 if (r == E_SECTION_ALREADY_EXIST)
80 _AppRegistryImpl::Add(const String& key, const String& value)
82 MutexGuard lock(__mutex);
84 Registry* pReg = LoadN(ReadWrite);
85 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
87 result r = pReg->AddValue(__sectionName, key, value);
88 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
96 _AppRegistryImpl::Add(const String& key, int value)
98 MutexGuard lock(__mutex);
100 Registry* pReg = LoadN(ReadWrite);
101 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
103 result r = pReg->AddValue(__sectionName, key, value);
104 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
112 _AppRegistryImpl::Add(const String& key, double value)
114 MutexGuard lock(__mutex);
116 Registry* pReg = LoadN(ReadWrite);
117 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
119 result r = pReg->AddValue(__sectionName, key, value);
120 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
128 _AppRegistryImpl::Set(const String& key, const String& value)
130 MutexGuard lock(__mutex);
132 Registry* pReg = LoadN(ReadWrite);
133 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
135 result r = pReg->SetValue(__sectionName, key, value);
136 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
144 _AppRegistryImpl::Set(const String& key, int value)
146 MutexGuard lock(__mutex);
148 Registry* pReg = LoadN(ReadWrite);
149 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
151 result r = pReg->SetValue(__sectionName, key, value);
152 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
160 _AppRegistryImpl::Set(const String& key, double value)
162 MutexGuard lock(__mutex);
164 Registry* pReg = LoadN(ReadWrite);
165 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
167 result r = pReg->SetValue(__sectionName, key, value);
168 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
176 _AppRegistryImpl::Save(void)
182 _AppRegistryImpl::Remove(const String& key)
184 MutexGuard lock(__mutex);
186 Registry* pReg = LoadN(ReadWrite);
187 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
189 result r = pReg->RemoveValue(__sectionName, key);
190 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
198 _AppRegistryImpl::Get(const String& key, String& value) const
200 MutexGuard lock(__mutex);
202 Registry* pReg = LoadN(ReadOnly);
203 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
205 result r = pReg->GetValue(__sectionName, key, value);
206 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
214 _AppRegistryImpl::Get(const String& key, int& value) const
216 MutexGuard lock(__mutex);
218 Registry* pReg = LoadN(ReadOnly);
219 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
221 result r = pReg->GetValue(__sectionName, key, value);
222 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
230 _AppRegistryImpl::Get(const String& key, double& value) const
232 MutexGuard lock(__mutex);
234 Registry* pReg = LoadN(ReadOnly);
235 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
237 result r = pReg->GetValue(__sectionName, key, value);
238 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
246 _AppRegistryImpl::LoadN(ReadOnlyTag) const
248 Registry* pReg = new (std::nothrow) Registry();
249 SysTryReturn(NID_APP, pReg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
251 result r = pReg->Construct(__regPath, "r");
252 SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed. %s occurred.",
253 __regPath.GetPointer(), GetErrorMessage(r));
260 _AppRegistryImpl::LoadN(ReadWriteTag) const
262 Registry* pReg = new (std::nothrow) Registry();
263 SysTryReturn(NID_APP, pReg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
265 result r = pReg->Construct(__regPath, "a+");
266 SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed. %s occurred.",
267 __regPath.GetPointer(), GetErrorMessage(r));