2 // Open Service Platform
3 // Copyright (c) 2013 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.
18 * @file FSclAccountAccessor.cpp
19 * @brief This is the implementation for AccountAccessor class.
21 * This file contains definitions of @e AccountAccessor class.
26 #include <unique_ptr.h>
27 #include <FBaseResult.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseColIList.h>
30 #include <FSec_AccessController.h>
31 #include <FSclAccount.h>
32 #include <FSclAccountAccessor.h>
33 #include <FSclAccountProvider.h>
34 #include <FSclIAccountEventListener.h>
35 #include "FScl_AccountAccessorImpl.h"
37 using namespace Tizen::App;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Security;
42 namespace Tizen { namespace Social
45 AccountAccessor* AccountAccessor::__pInstance = null;
47 AccountAccessor::AccountAccessor(void)
48 : __pAccountAccessorImpl(null)
53 AccountAccessor::~AccountAccessor(void)
55 delete __pAccountAccessorImpl;
59 AccountAccessor::SetEventListener(IAccountEventListener* pListener)
61 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
62 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
63 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
65 SysAssertf(__pAccountAccessorImpl != null,
66 "Not yet constructed. Construct() should be called before use.");
68 r = __pAccountAccessorImpl->SetEventListener(pListener);
69 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
75 AccountAccessor::GetAccount(AccountId accountId) const
79 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
80 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
81 SysTryReturn(NID_SCL, r == E_SUCCESS, account, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
83 SysAssertf(__pAccountAccessorImpl != null,
84 "Not yet constructed. Construct() should be called before use.");
86 account = __pAccountAccessorImpl->GetAccount(accountId);
87 SysTryReturn(NID_SCL, !IsFailed(GetLastResult()), account, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
93 AccountAccessor::GetAccountsByAccountProviderN(const AppId& accountProviderAppId) const
95 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
96 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
97 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
99 SysAssertf(__pAccountAccessorImpl != null,
100 "Not yet constructed. Construct() should be called before use.");
102 IList* pList = __pAccountAccessorImpl->GetAccountsByAccountProviderN(accountProviderAppId);
103 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
109 AccountAccessor::GetAllAccountsN(void) const
111 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
112 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
113 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
115 SysAssertf(__pAccountAccessorImpl != null,
116 "Not yet constructed. Construct() should be called before use.");
118 IList* pList = __pAccountAccessorImpl->GetAllAccountsN();
119 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
125 AccountAccessor::GetAccountProvider(const AppId& accountProviderAppId) const
127 AccountProvider accountProvider;
129 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
130 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
131 SysTryReturn(NID_SCL, r == E_SUCCESS, accountProvider, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
133 SysAssertf(__pAccountAccessorImpl != null,
134 "Not yet constructed. Construct() should be called before use.");
136 accountProvider = __pAccountAccessorImpl->GetAccountProvider(accountProviderAppId);
137 SysTryReturn(NID_SCL, !IsFailed(GetLastResult()), accountProvider, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
139 return accountProvider;
143 AccountAccessor::GetAccountProvidersByCapabilityN(const String& capability) const
145 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
146 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
147 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
149 SysAssertf(__pAccountAccessorImpl != null,
150 "Not yet constructed. Construct() should be called before use.");
152 IList* pList = __pAccountAccessorImpl->GetAccountProvidersByCapabilityN(capability);
153 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
159 AccountAccessor::GetAllAccountProvidersN(void) const
161 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ);
162 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
163 SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
165 SysAssertf(__pAccountAccessorImpl != null,
166 "Not yet constructed. Construct() should be called before use.");
168 IList* pList = __pAccountAccessorImpl->GetAllAccountProvidersN();
169 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
175 AccountAccessor::GetInstance(void)
177 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
179 if (__pInstance == null)
183 pthread_once(&onceBlock, InitAccountAccessor);
185 result r = GetLastResult();
189 onceBlock = PTHREAD_ONCE_INIT;
197 AccountAccessor::Construct(void)
199 SysAssertf(__pAccountAccessorImpl == null,
200 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
202 _AccountAccessorImpl* pAccountAccessorImpl = new (std::nothrow) _AccountAccessorImpl();
203 SysTryReturnResult(NID_SCL, pAccountAccessorImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
205 result r = pAccountAccessorImpl->Construct();
206 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountAccessorImpl.", GetErrorMessage(r));
208 __pAccountAccessorImpl = pAccountAccessorImpl;
213 delete pAccountAccessorImpl;
219 AccountAccessor::InitAccountAccessor(void)
221 std::unique_ptr<AccountAccessor> pInstance(new (std::nothrow) AccountAccessor());
222 SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
224 result r = pInstance->Construct();
225 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r));
227 __pInstance = pInstance.release();
229 std::atexit(DestroyAccountAccessor);
233 AccountAccessor::DestroyAccountAccessor(void)