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 _AppRegistryImpl::_AppRegistryImpl(void)
39 : __sectionName(L"__ApplicationStates")
43 _AppRegistryImpl::~_AppRegistryImpl(void)
48 _AppRegistryImpl::Construct(void)
50 const String& packageId = _AppInfo::GetPackageId();
51 SysAssertf(!packageId.IsEmpty(), "Empty package.");
53 __regPath = _AppInfo::GetAppRootPath() + L"data/";
54 result r = __regPath.Append(packageId);
55 SysTryReturnResult(NID_APP, !IsFailed(r), r, "String appending has failed.");
60 MutexGuard lock(__mutex);
63 r = reg.Construct(__regPath, "a+");
64 SysAssertf(!IsFailed(r), "[%s] Constructing the registry file (%ls) has failed.", GetErrorMessage(r), __regPath.GetPointer());
66 r = reg.AddSection(__sectionName);
67 if (r == E_SECTION_ALREADY_EXIST)
76 _AppRegistryImpl::Add(const String& key, const String& value)
78 MutexGuard lock(__mutex);
80 Registry* pReg = LoadN(ReadWrite);
81 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
83 result r = pReg->AddValue(__sectionName, key, value);
84 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
92 _AppRegistryImpl::Add(const String& key, int value)
94 MutexGuard lock(__mutex);
96 Registry* pReg = LoadN(ReadWrite);
97 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
99 result r = pReg->AddValue(__sectionName, key, value);
100 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
108 _AppRegistryImpl::Add(const String& key, double value)
110 MutexGuard lock(__mutex);
112 Registry* pReg = LoadN(ReadWrite);
113 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
115 result r = pReg->AddValue(__sectionName, key, value);
116 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
124 _AppRegistryImpl::Set(const String& key, const String& value)
126 MutexGuard lock(__mutex);
128 Registry* pReg = LoadN(ReadWrite);
129 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
131 result r = pReg->SetValue(__sectionName, key, value);
132 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
140 _AppRegistryImpl::Set(const String& key, int value)
142 MutexGuard lock(__mutex);
144 Registry* pReg = LoadN(ReadWrite);
145 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
147 result r = pReg->SetValue(__sectionName, key, value);
148 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
156 _AppRegistryImpl::Set(const String& key, double value)
158 MutexGuard lock(__mutex);
160 Registry* pReg = LoadN(ReadWrite);
161 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
163 result r = pReg->SetValue(__sectionName, key, value);
164 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
172 _AppRegistryImpl::Save(void)
178 _AppRegistryImpl::Remove(const String& key)
180 MutexGuard lock(__mutex);
182 Registry* pReg = LoadN(ReadWrite);
183 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
185 result r = pReg->RemoveValue(__sectionName, key);
186 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
194 _AppRegistryImpl::Get(const String& key, String& value) const
196 MutexGuard lock(__mutex);
198 Registry* pReg = LoadN(ReadOnly);
199 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
201 result r = pReg->GetValue(__sectionName, key, value);
202 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
210 _AppRegistryImpl::Get(const String& key, int& value) const
212 MutexGuard lock(__mutex);
214 Registry* pReg = LoadN(ReadOnly);
215 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
217 result r = pReg->GetValue(__sectionName, key, value);
218 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
226 _AppRegistryImpl::Get(const String& key, double& value) const
228 MutexGuard lock(__mutex);
230 Registry* pReg = LoadN(ReadOnly);
231 SysTryReturnResult(NID_APP, pReg != null, GetLastResult(), "Propagating to caller...");
233 result r = pReg->GetValue(__sectionName, key, value);
234 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
242 _AppRegistryImpl::LoadN(ReadOnlyTag) const
244 Registry* pReg = new (std::nothrow) Registry();
245 SysTryReturn(NID_APP, pReg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
247 result r = pReg->Construct(__regPath, "r");
248 SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed. %s occurred.",
249 __regPath.GetPointer(), GetErrorMessage(r));
256 _AppRegistryImpl::LoadN(ReadWriteTag) const
258 Registry* pReg = new (std::nothrow) Registry();
259 SysTryReturn(NID_APP, pReg != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
261 result r = pReg->Construct(__regPath, "a+");
262 SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed. %s occurred.",
263 __regPath.GetPointer(), GetErrorMessage(r));