2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FApp_AppRegistryImpl.cpp
20 * @brief This is the implementation for the _AppRegistryImpl class.
23 #include <FAppAppRegistry.h>
24 #include <FIoRegistry.h>
26 #include <FBaseSysLog.h>
27 #include "FApp_AppRegistryImpl.h"
28 #include "FApp_AppInfo.h"
30 using namespace Tizen::Io;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
34 namespace Tizen { namespace App
38 _AppRegistryImpl::_AppRegistryImpl(void)
40 , __sectionName(L"__ApplicationStates")
45 _AppRegistryImpl::~_AppRegistryImpl(void)
47 if (__pRegistry != null)
56 _AppRegistryImpl::Construct(void)
60 SysAssertf(__pRegistry == null,
61 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63 const String& packageId = _AppInfo::GetPackageId();
64 String regName = _AppInfo::GetAppRootPath() + L"data/";
66 SysAssertf(!packageId.IsEmpty(), "Empty packageId.");
67 r = regName.Append(static_cast <const String&>(packageId));
68 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] String appending has failed.", GetErrorMessage(r));
70 __pRegistry = new (std::nothrow) Registry();
71 SysTryCatch(NID_APP, __pRegistry != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
72 "[E_OUT_OF_MEMORY] Failed while instantiating registry.");
74 r = __pRegistry->Construct(regName, true);
75 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
78 r = __pRegistry->AddSection(__sectionName);
79 if (r == E_SECTION_ALREADY_EXIST)
81 // section may exist already
85 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
93 SysLog(NID_APP, "Exit.");
100 _AppRegistryImpl::Add(const String& key, const String& value)
102 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
104 result r = E_SUCCESS;
106 r = __pRegistry->AddValue(__sectionName, key, value);
108 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
115 _AppRegistryImpl::Add(const String& key, int value)
117 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
119 result r = E_SUCCESS;
121 r = __pRegistry->AddValue(__sectionName, key, value);
123 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
130 _AppRegistryImpl::Add(const String& key, double value)
132 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
134 result r = E_SUCCESS;
136 r = __pRegistry->AddValue(__sectionName, key, value);
138 SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
145 _AppRegistryImpl::Set(const String& key, const String& value)
147 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
149 result r = E_SUCCESS;
151 r = __pRegistry->SetValue(__sectionName, key, value);
153 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
160 _AppRegistryImpl::Set(const String& key, int value)
162 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
164 result r = E_SUCCESS;
166 r = __pRegistry->SetValue(__sectionName, key, value);
168 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
175 _AppRegistryImpl::Set(const String& key, double value)
177 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
179 result r = E_SUCCESS;
181 r = __pRegistry->SetValue(__sectionName, key, value);
183 SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
190 _AppRegistryImpl::Save(void)
192 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
194 result r = E_SUCCESS;
196 r = __pRegistry->Flush();
198 SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
205 _AppRegistryImpl::Remove(const String& key)
207 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
209 result r = E_SUCCESS;
211 r = __pRegistry->RemoveValue(__sectionName, key);
213 SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
220 _AppRegistryImpl::Get(const String& key, String& value) const
222 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
224 result r = E_SUCCESS;
226 r = __pRegistry->GetValue(__sectionName, key, value);
228 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
235 _AppRegistryImpl::Get(const String& key, int& value) const
237 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
239 result r = E_SUCCESS;
241 r = __pRegistry->GetValue(__sectionName, key, value);
243 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
250 _AppRegistryImpl::Get(const String& key, double& value) const
252 SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
254 result r = E_SUCCESS;
256 r = __pRegistry->GetValue(__sectionName, key, value);
258 SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));