updated _ServiceAppImpl::OnTimerExpired()
[platform/framework/native/appfw.git] / src / app / FApp_AppRegistryImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FApp_AppRegistryImpl.cpp
19  * @brief       This is the implementation for the _AppRegistryImpl class.
20  */
21
22 #include <FAppAppRegistry.h>
23 #include <FIoRegistry.h>
24
25 #include <FBaseSysLog.h>
26 #include "FApp_AppRegistryImpl.h"
27 #include "FApp_AppInfo.h"
28
29 using namespace Tizen::Io;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33 namespace Tizen { namespace App
34 {
35
36
37 _AppRegistryImpl::_AppRegistryImpl(void)
38         : __pRegistry(null)
39         , __sectionName(L"__ApplicationStates")
40 {
41 }
42
43
44 _AppRegistryImpl::~_AppRegistryImpl(void)
45 {
46         if (__pRegistry != null)
47         {
48                 delete __pRegistry;
49                 __pRegistry = null;
50         }
51 }
52
53
54 result
55 _AppRegistryImpl::Construct(void)
56 {
57         result r = E_SUCCESS;
58
59         SysAssertf(__pRegistry == null,
60                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
61
62         const String& packageId = _AppInfo::GetPackageId();
63         String regName = _AppInfo::GetAppRootPath() + L"data/";
64
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));
68
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.");
72
73         r = __pRegistry->Construct(regName, true);
74         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%ls] Constructing the registry %s has failed.", regName.GetPointer(),
75                            GetErrorMessage(r));
76
77         r = __pRegistry->AddSection(__sectionName);
78         if (r == E_SECTION_ALREADY_EXIST)
79         {
80                 // section may exist already
81                 r = E_SUCCESS;
82         }
83
84         SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Adding section to registry has failed.", GetErrorMessage(r));
85
86         return r;
87
88 CATCH:
89         delete __pRegistry;
90         __pRegistry = null;
91
92         SysLog(NID_APP, "Exit.");
93
94         return r;
95 }
96
97
98 result
99 _AppRegistryImpl::Add(const String& key, const String& value)
100 {
101         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
102
103         result r = E_SUCCESS;
104
105         r = __pRegistry->AddValue(__sectionName, key, value);
106
107         SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
108
109         return r;
110 }
111
112
113 result
114 _AppRegistryImpl::Add(const String& key, int value)
115 {
116         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
117
118         result r = E_SUCCESS;
119
120         r = __pRegistry->AddValue(__sectionName, key, value);
121
122         SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
123
124         return r;
125 }
126
127
128 result
129 _AppRegistryImpl::Add(const String& key, double value)
130 {
131         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
132
133         result r = E_SUCCESS;
134
135         r = __pRegistry->AddValue(__sectionName, key, value);
136
137         SysTryLog(NID_APP, !IsFailed(r), "[%s] Adding value to the registry has failed.", GetErrorMessage(r));
138
139         return r;
140 }
141
142
143 result
144 _AppRegistryImpl::Set(const String& key, const String& value)
145 {
146         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
147
148         result r = E_SUCCESS;
149
150         r = __pRegistry->SetValue(__sectionName, key, value);
151
152         SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
153
154         return r;
155 }
156
157
158 result
159 _AppRegistryImpl::Set(const String& key, int value)
160 {
161         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
162
163         result r = E_SUCCESS;
164
165         r = __pRegistry->SetValue(__sectionName, key, value);
166
167         SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
168
169         return r;
170 }
171
172
173 result
174 _AppRegistryImpl::Set(const String& key, double value)
175 {
176         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
177
178         result r = E_SUCCESS;
179
180         r = __pRegistry->SetValue(__sectionName, key, value);
181
182         SysTryLog(NID_APP, !IsFailed(r), "[%s] Setting value to the registry has failed.", GetErrorMessage(r));
183
184         return r;
185 }
186
187
188 result
189 _AppRegistryImpl::Save(void)
190 {
191         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
192
193         result r = E_SUCCESS;
194
195         r = __pRegistry->Flush();
196
197         SysTryLog(NID_APP, !IsFailed(r), "[%s] Saving value to the registry has failed.", GetErrorMessage(r));
198
199         return r;
200 }
201
202
203 result
204 _AppRegistryImpl::Remove(const String& key)
205 {
206         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
207
208         result r = E_SUCCESS;
209
210         r = __pRegistry->RemoveValue(__sectionName, key);
211
212         SysTryLog(NID_APP, !IsFailed(r), "[%s] Removing value to the registry has failed.", GetErrorMessage(r));
213
214         return r;
215 }
216
217
218 result
219 _AppRegistryImpl::Get(const String& key, String& value) const
220 {
221         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
222
223         result r = E_SUCCESS;
224
225         r = __pRegistry->GetValue(__sectionName, key, value);
226
227         SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
228
229         return r;
230 }
231
232
233 result
234 _AppRegistryImpl::Get(const String& key, int& value) const
235 {
236         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
237
238         result r = E_SUCCESS;
239
240         r = __pRegistry->GetValue(__sectionName, key, value);
241
242         SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
243
244         return r;
245 }
246
247
248 result
249 _AppRegistryImpl::Get(const String& key, double& value) const
250 {
251         SysAssertf(__pRegistry != null, "Not yet constructed. Construct() should be called before use.");
252
253         result r = E_SUCCESS;
254
255         r = __pRegistry->GetValue(__sectionName, key, value);
256
257         SysTryLog(NID_APP, !IsFailed(r), "[%s] Getting value to the registry has failed.", GetErrorMessage(r));
258
259         return r;
260 }
261
262
263 } } // Tizen::App