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 FAppAppRegistry.cpp
19 * @brief This is the implementation for the AppRegistry class.
22 #include <FIoRegistry.h>
23 #include <FAppAppRegistry.h>
24 #include <FBaseSysLog.h>
26 #include "FApp_AppRegistryImpl.h"
27 #include "FAppPkg_PackageInfoImpl.h"
28 #ifdef _SINGLETON_CLEANUP
29 #include "FApp_LongevityManager.h"
32 using namespace Tizen::Io;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
36 namespace Tizen { namespace App
40 AppRegistry::AppRegistry(void)
41 : __pAppRegistryImpl(null)
46 AppRegistry::~AppRegistry(void)
48 delete __pAppRegistryImpl;
53 AppRegistry::Construct(void)
55 SysAssertf(__pAppRegistryImpl == null,
56 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58 __pAppRegistryImpl = new (std::nothrow) _AppRegistryImpl();
59 SysTryReturnResult(NID_APP, __pAppRegistryImpl != null, E_OUT_OF_MEMORY, "Allocation failed.");
61 return __pAppRegistryImpl->Construct();
66 AppRegistry::Add(const String& key, const String& value)
68 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
69 return __pAppRegistryImpl->Add(key, value);
74 AppRegistry::Add(const String& key, int value)
76 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
77 return __pAppRegistryImpl->Add(key, value);
82 AppRegistry::Add(const String& key, double value)
84 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
85 return __pAppRegistryImpl->Add(key, value);
90 AppRegistry::Set(const String& key, const String& value)
92 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
93 return __pAppRegistryImpl->Set(key, value);
98 AppRegistry::Set(const String& key, int value)
100 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
101 return __pAppRegistryImpl->Set(key, value);
106 AppRegistry::Set(const String& key, double value)
108 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
109 return __pAppRegistryImpl->Set(key, value);
114 AppRegistry::Save(void)
116 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
117 return __pAppRegistryImpl->Save();
122 AppRegistry::Remove(const String& key)
124 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
125 return __pAppRegistryImpl->Remove(key);
130 AppRegistry::Get(const String& key, String& value) const
132 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
133 return __pAppRegistryImpl->Get(key, value);
138 AppRegistry::Get(const String& key, int& value) const
140 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
141 return __pAppRegistryImpl->Get(key, value);
146 AppRegistry::Get(const String& key, double& value) const
148 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
149 return __pAppRegistryImpl->Get(key, value);
154 AppRegistry::GetInstance(void)
156 result r = E_SUCCESS;
157 static AppRegistry* pAppRegistry = null;
159 if (pAppRegistry == null)
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.");
164 r = pAppRegistry->Construct();
165 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Initialization of app registry failed.", GetErrorMessage(r));
167 #ifdef _SINGLETON_CLEANUP
168 _LongevityManager::GetInstance().RegisterOwnership(*pAppRegistry);