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>
24 #include <FIoFileAttributes.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;
34 namespace Tizen { namespace App
37 _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.");
57 SysLog(NID_APP, "Exit.");
62 _AppRegistryImpl::Add(const String& key, const String& value)
65 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
67 r = __pRegistry->AddValue(__sectionName, key, value);
68 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
75 _AppRegistryImpl::Add(const String& key, int value)
78 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
80 r = __pRegistry->AddValue(__sectionName, key, value);
81 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
88 _AppRegistryImpl::Add(const String& key, double value)
91 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
93 r = __pRegistry->AddValue(__sectionName, key, value);
94 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
101 _AppRegistryImpl::Set(const String& key, const String& value)
104 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
106 r = __pRegistry->SetValue(__sectionName, key, value);
107 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
114 _AppRegistryImpl::Set(const String& key, int value)
117 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
119 r = __pRegistry->SetValue(__sectionName, key, value);
120 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
127 _AppRegistryImpl::Set(const String& key, double value)
130 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
132 r = __pRegistry->SetValue(__sectionName, key, value);
133 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
140 _AppRegistryImpl::Save(void)
146 _AppRegistryImpl::Remove(const String& key)
149 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
151 r = __pRegistry->RemoveValue(__sectionName, key);
152 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
159 _AppRegistryImpl::Get(const String& key, String& value) const
162 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
164 r = __pRegistry->GetValue(__sectionName, key, value);
165 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
172 _AppRegistryImpl::Get(const String& key, int& value) const
175 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
177 r = __pRegistry->GetValue(__sectionName, key, value);
178 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
185 _AppRegistryImpl::Get(const String& key, double& value) const
188 SysTryReturnResult(NID_APP, !IsFailed(r), r, "[%s] Propagating to caller...", GetErrorMessage(r));
190 r = __pRegistry->GetValue(__sectionName, key, value);
191 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
198 _AppRegistryImpl::Load(void) const
200 __pRegistry = new (std::nothrow) Registry();
201 SysTryReturnResult(NID_APP, __pRegistry != null, E_OUT_OF_MEMORY, "Instantiating registry has failed.");
203 result r = __pRegistry->Construct(__regPath, "a+");
204 SysAssertf(!IsFailed(r), "Constructing the registry file (%ls) has failed.", __regPath.GetPointer());
206 r = __pRegistry->AddSection(__sectionName);
207 if (r == E_SECTION_ALREADY_EXIST)
211 SysAssertf(!IsFailed(r), "Adding section to registry has failed.");
217 _AppRegistryImpl::Unload(void) const