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 FAppAppRegistry.cpp
20 * @brief This is the implementation for the AppRegistry class.
23 #include <FIoRegistry.h>
24 #include <FAppAppRegistry.h>
25 #include <FBaseSysLog.h>
27 #include "FApp_AppRegistryImpl.h"
28 #include "FAppPkg_PackageInfoImpl.h"
29 #ifdef _SINGLETON_CLEANUP
30 #include "FApp_LongevityManager.h"
33 using namespace Tizen::Io;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
37 namespace Tizen { namespace App
41 AppRegistry::AppRegistry(void)
42 : __pAppRegistryImpl(null)
47 AppRegistry::~AppRegistry(void)
49 delete __pAppRegistryImpl;
54 AppRegistry::Construct(void)
56 SysAssertf(__pAppRegistryImpl == null,
57 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59 __pAppRegistryImpl = new (std::nothrow) _AppRegistryImpl();
60 SysTryReturnResult(NID_APP, __pAppRegistryImpl != null, E_OUT_OF_MEMORY, "Allocation failed.");
62 return __pAppRegistryImpl->Construct();
67 AppRegistry::Add(const String& key, const String& value)
69 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
70 return __pAppRegistryImpl->Add(key, value);
75 AppRegistry::Add(const String& key, int value)
77 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
78 return __pAppRegistryImpl->Add(key, value);
83 AppRegistry::Add(const String& key, double value)
85 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
86 return __pAppRegistryImpl->Add(key, value);
91 AppRegistry::Set(const String& key, const String& value)
93 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
94 return __pAppRegistryImpl->Set(key, value);
99 AppRegistry::Set(const String& key, int value)
101 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
102 return __pAppRegistryImpl->Set(key, value);
107 AppRegistry::Set(const String& key, double value)
109 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
110 return __pAppRegistryImpl->Set(key, value);
115 AppRegistry::Save(void)
117 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
118 return __pAppRegistryImpl->Save();
123 AppRegistry::Remove(const String& key)
125 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
126 return __pAppRegistryImpl->Remove(key);
131 AppRegistry::Get(const String& key, String& value) const
133 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
134 return __pAppRegistryImpl->Get(key, value);
139 AppRegistry::Get(const String& key, int& value) const
141 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
142 return __pAppRegistryImpl->Get(key, value);
147 AppRegistry::Get(const String& key, double& value) const
149 SysAssertf(__pAppRegistryImpl != null, "Not yet constructed. Construct() should be called before use.");
150 return __pAppRegistryImpl->Get(key, value);
155 AppRegistry::GetInstance(void)
157 result r = E_SUCCESS;
158 static AppRegistry* pAppRegistry = null;
160 if (pAppRegistry == null)
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.");
165 r = pAppRegistry->Construct();
166 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Initialization of app registry failed.", GetErrorMessage(r));
168 #ifdef _SINGLETON_CLEANUP
169 _LongevityManager::GetInstance().RegisterOwnership(*pAppRegistry);