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