Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / app / FAppAppRegistry.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        FAppAppRegistry.cpp
19  * @brief       This is the implementation for the AppRegistry class.
20  */
21
22 #include <FIoRegistry.h>
23 #include <FAppAppRegistry.h>
24 #include <FBaseSysLog.h>
25
26 #include "FApp_AppRegistryImpl.h"
27 #include "FAppPkg_PackageInfoImpl.h"
28 #ifdef _SINGLETON_CLEANUP
29 #include "FApp_LongevityManager.h"
30 #endif
31
32 using namespace Tizen::Io;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace App
37 {
38
39
40 AppRegistry::AppRegistry(void)
41         : __pAppRegistryImpl(null)
42 {
43 }
44
45
46 AppRegistry::~AppRegistry(void)
47 {
48         delete __pAppRegistryImpl;
49 }
50
51
52 result
53 AppRegistry::Construct(void)
54 {
55         SysAssertf(__pAppRegistryImpl == null,
56                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57
58         __pAppRegistryImpl = new (std::nothrow) _AppRegistryImpl();
59         SysTryReturnResult(NID_APP, __pAppRegistryImpl != null, E_OUT_OF_MEMORY, "Allocation failed.");
60
61         return __pAppRegistryImpl->Construct();
62 }
63
64
65 result
66 AppRegistry::Add(const String& key, const String& value)
67 {
68         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
69         return __pAppRegistryImpl->Add(key, value);
70 }
71
72
73 result
74 AppRegistry::Add(const String& key, int value)
75 {
76         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
77         return __pAppRegistryImpl->Add(key, value);
78 }
79
80
81 result
82 AppRegistry::Add(const String& key, double value)
83 {
84         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
85         return __pAppRegistryImpl->Add(key, value);
86 }
87
88
89 result
90 AppRegistry::Set(const String& key, const String& value)
91 {
92         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
93         return __pAppRegistryImpl->Set(key, value);
94 }
95
96
97 result
98 AppRegistry::Set(const String& key, int value)
99 {
100         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
101         return __pAppRegistryImpl->Set(key, value);
102 }
103
104
105 result
106 AppRegistry::Set(const String& key, double value)
107 {
108         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
109         return __pAppRegistryImpl->Set(key, value);
110 }
111
112
113 result
114 AppRegistry::Save(void)
115 {
116         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
117         return __pAppRegistryImpl->Save();
118 }
119
120
121 result
122 AppRegistry::Remove(const String& key)
123 {
124         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
125         return __pAppRegistryImpl->Remove(key);
126 }
127
128
129 result
130 AppRegistry::Get(const String& key, String& value) const
131 {
132         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
133         return __pAppRegistryImpl->Get(key, value);
134 }
135
136
137 result
138 AppRegistry::Get(const String& key, int& value) const
139 {
140         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
141         return __pAppRegistryImpl->Get(key, value);
142 }
143
144
145 result
146 AppRegistry::Get(const String& key, double& value) const
147 {
148         SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
149         return __pAppRegistryImpl->Get(key, value);
150 }
151
152
153 AppRegistry*
154 AppRegistry::GetInstance(void)
155 {
156         result r = E_SUCCESS;
157         static AppRegistry* pAppRegistry = null;
158
159         if (pAppRegistry == null)
160         {
161                 pAppRegistry = new (std::nothrow) AppRegistry();
162                 SysTryCatch(NID_APP, pAppRegistry != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] app registry allocation failed.");
163
164                 r = pAppRegistry->Construct();
165                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Initialization of app registry failed.", GetErrorMessage(r));
166
167 #ifdef _SINGLETON_CLEANUP
168                 _LongevityManager::GetInstance().RegisterOwnership(*pAppRegistry);
169 #endif
170         }
171
172         SetLastResult(r);
173         return pAppRegistry;
174
175 CATCH:
176         delete pAppRegistry;
177         pAppRegistry = null;
178
179         SetLastResult(r);
180         return pAppRegistry;
181 }
182
183
184 } } // Tizen::App