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.
17 * @file FAppAppSetting.h
18 * @brief This is the implementation file for the %AppSetting class.
25 #include <FAppAppSetting.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include "FApp_AppSettingImpl.h"
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Security;
33 namespace Tizen { namespace App
36 AppSetting* AppSetting::__pAppSettingInstance = null;
38 AppSetting::AppSetting(void)
39 : __pAppSettingImpl(null)
44 AppSetting::~AppSetting(void)
46 delete __pAppSettingImpl;
50 AppSetting::GetInstance(void)
52 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
54 if (!__pAppSettingInstance)
57 pthread_once(&onceBlock, InitSingleton);
58 result r = GetLastResult();
59 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
61 __pAppSettingInstance->__pAppSettingImpl = _AppSettingImpl::GetInstance();
62 SysTryCatch(NID_APP, __pAppSettingInstance->__pAppSettingImpl != null, , E_OUT_OF_MEMORY,
63 "[%s] Memory allocation failed.");
66 return __pAppSettingInstance;
69 delete __pAppSettingInstance;
70 __pAppSettingInstance = null;
71 onceBlock = PTHREAD_ONCE_INIT;
76 AppSetting::GetInstance(const Tizen::Base::String& version)
78 return _AppSettingImpl::GetInstance(version);
82 AppSetting::GetInstanceByAppId(const AppId& appId)
84 result r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
85 SysTryReturn(NID_APP, !IsFailed(r), null, E_PRIVILEGE_DENIED,
86 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
88 return _AppSettingImpl::GetInstanceByAppId(appId);
92 AppSetting::ReleaseInstanceByAppId(const AppId& appId)
94 result r = _AccessController::CheckUserPrivilege(_PRV_APPSETTING);
95 SysTryReturnResult(NID_APP, !IsFailed(r), E_PRIVILEGE_DENIED,
96 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
98 return _AppSettingImpl::ReleaseInstanceByAppId(appId);
101 Tizen::Base::Collection::IList*
102 AppSetting::GetAppSettingVersionListN(void)
104 return _AppSettingImpl::GetAppSettingVersionListN();
108 AppSetting::GetValue(const Tizen::Base::String& id, bool& value) const
110 return __pAppSettingImpl->GetValue(id, value);
114 AppSetting::GetValue(const Tizen::Base::String& id, int& value) const
116 return __pAppSettingImpl->GetValue(id, value);
120 AppSetting::GetValue(const Tizen::Base::String& id, Tizen::Base::String& value) const
122 return __pAppSettingImpl->GetValue(id, value);
126 AppSetting::SetValue(const Tizen::Base::String& id, bool value)
128 return __pAppSettingImpl->SetValue(id, value);
132 AppSetting::SetValue(const Tizen::Base::String& id, int value)
134 return __pAppSettingImpl->SetValue(id, value);
138 AppSetting::SetValue(const Tizen::Base::String& id, const Tizen::Base::String& value)
140 return __pAppSettingImpl->SetValue(id, value);
144 AppSetting::SetAppSettingEventListener(IAppSettingEventListener* pListener)
146 return __pAppSettingImpl->SetAppSettingEventListener(pListener);
150 AppSetting::InitSingleton(void)
152 AppSetting* pInst = new (std::nothrow) AppSetting();
153 SysTryReturnVoidResult(NID_UI_SCENES, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
154 GetErrorMessage(E_OUT_OF_MEMORY));
156 __pAppSettingInstance = pInst;
157 std::atexit(DestroySingleton);
161 AppSetting::DestroySingleton(void)
163 delete __pAppSettingInstance;