Merge "Update deprecated libprivilege-control API functions." into tizen
[platform/framework/native/appfw.git] / src / app / FAppAppSetting.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  * @file        FAppAppSetting.h
18  * @brief       This is the implementation file for the %AppSetting class.
19  *
20  */
21
22 #include <cstdlib>
23 #include <new>
24 #include <pthread.h>
25 #include <FAppAppSetting.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include "FApp_AppSettingImpl.h"
29
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Security;
32
33 namespace Tizen { namespace App
34 {
35
36 AppSetting* AppSetting::__pAppSettingInstance = null;
37
38 AppSetting::AppSetting(void)
39         : __pAppSettingImpl(null)
40 {
41
42 }
43
44 AppSetting::~AppSetting(void)
45 {
46         delete __pAppSettingImpl;
47 }
48
49 AppSetting*
50 AppSetting::GetInstance(void)
51 {
52         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
53
54         if (!__pAppSettingInstance)
55         {
56                 ClearLastResult();
57                 pthread_once(&onceBlock, InitSingleton);
58                 result r = GetLastResult();
59                 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
60
61                 __pAppSettingInstance->__pAppSettingImpl = _AppSettingImpl::GetInstance();
62                 SysTryCatch(NID_APP, __pAppSettingInstance->__pAppSettingImpl != null, , E_OUT_OF_MEMORY,
63                                         "[%s] Memory allocation failed.");
64         }
65
66         return __pAppSettingInstance;
67
68 CATCH:
69         delete __pAppSettingInstance;
70         __pAppSettingInstance = null;
71         onceBlock = PTHREAD_ONCE_INIT;
72         return null;
73 }
74
75 AppSetting*
76 AppSetting::GetInstance(const Tizen::Base::String& version)
77 {
78         return _AppSettingImpl::GetInstance(version);
79 }
80
81 AppSetting*
82 AppSetting::GetInstanceByAppId(const AppId& appId)
83 {
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));
87
88         return _AppSettingImpl::GetInstanceByAppId(appId);
89 }
90
91 result
92 AppSetting::ReleaseInstanceByAppId(const AppId& appId)
93 {
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));
97
98         return _AppSettingImpl::ReleaseInstanceByAppId(appId);
99 }
100
101 Tizen::Base::Collection::IList*
102 AppSetting::GetAppSettingVersionListN(void)
103 {
104         return _AppSettingImpl::GetAppSettingVersionListN();
105 }
106
107 result
108 AppSetting::GetValue(const Tizen::Base::String& id, bool& value) const
109 {
110         return __pAppSettingImpl->GetValue(id, value);
111 }
112
113 result
114 AppSetting::GetValue(const Tizen::Base::String& id, int& value) const
115 {
116         return __pAppSettingImpl->GetValue(id, value);
117 }
118
119 result
120 AppSetting::GetValue(const Tizen::Base::String& id, Tizen::Base::String& value) const
121 {
122         return __pAppSettingImpl->GetValue(id, value);
123 }
124
125 result
126 AppSetting::SetValue(const Tizen::Base::String& id, bool value)
127 {
128         return __pAppSettingImpl->SetValue(id, value);
129 }
130
131 result
132 AppSetting::SetValue(const Tizen::Base::String& id, int value)
133 {
134         return __pAppSettingImpl->SetValue(id, value);
135 }
136
137 result
138 AppSetting::SetValue(const Tizen::Base::String& id, const Tizen::Base::String& value)
139 {
140         return __pAppSettingImpl->SetValue(id, value);
141 }
142
143 result
144 AppSetting::SetAppSettingEventListener(IAppSettingEventListener* pListener)
145 {
146         return __pAppSettingImpl->SetAppSettingEventListener(pListener);
147 }
148
149 void
150 AppSetting::InitSingleton(void)
151 {
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));
155
156         __pAppSettingInstance = pInst;
157         std::atexit(DestroySingleton);
158 }
159
160 void
161 AppSetting::DestroySingleton(void)
162 {
163         delete __pAppSettingInstance;
164 }
165
166
167 } } // Tizen::App