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 SysTryReturnResult(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED
62 , "The application does not have the privilege to call this method.");
63 SysAssertf(__pAccountAccessorImpl != null,
64 "Not yet constructed. Construct() should be called before use.");
66 result r = __pAccountAccessorImpl->SetEventListener(pListener);
67 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
73 AccountAccessor::GetAccount(AccountId accountId) const
77 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, account, E_PRIVILEGE_DENIED
78 , "The application does not have the privilege to call this method.");
79 SysAssertf(__pAccountAccessorImpl != null,
80 "Not yet constructed. Construct() should be called before use.");
82 account = __pAccountAccessorImpl->GetAccount(accountId);
83 SysTryReturn(NID_SCL, !IsFailed(GetLastResult()), account, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
89 AccountAccessor::GetAccountsByAccountProviderN(const AppId& accountProviderAppId) const
91 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED
92 , "The application does not have the privilege to call this method.");
93 SysAssertf(__pAccountAccessorImpl != null,
94 "Not yet constructed. Construct() should be called before use.");
96 IList* pList = __pAccountAccessorImpl->GetAccountsByAccountProviderN(accountProviderAppId);
97 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
103 AccountAccessor::GetAllAccountsN(void) const
105 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED
106 , "The application does not have the privilege to call this method.");
107 SysAssertf(__pAccountAccessorImpl != null,
108 "Not yet constructed. Construct() should be called before use.");
110 IList* pList = __pAccountAccessorImpl->GetAllAccountsN();
111 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
117 AccountAccessor::GetAccountProvider(const AppId& accountProviderAppId) const
119 AccountProvider accountProvider;
121 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, accountProvider, E_PRIVILEGE_DENIED
122 , "The application does not have the privilege to call this method.");
123 SysAssertf(__pAccountAccessorImpl != null,
124 "Not yet constructed. Construct() should be called before use.");
126 accountProvider = __pAccountAccessorImpl->GetAccountProvider(accountProviderAppId);
127 SysTryReturn(NID_SCL, !IsFailed(GetLastResult()), accountProvider, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
129 return accountProvider;
133 AccountAccessor::GetAccountProvidersByCapabilityN(const String& capability) const
135 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED
136 , "The application does not have the privilege to call this method.");
137 SysAssertf(__pAccountAccessorImpl != null,
138 "Not yet constructed. Construct() should be called before use.");
140 IList* pList = __pAccountAccessorImpl->GetAccountProvidersByCapabilityN(capability);
141 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
147 AccountAccessor::GetAllAccountProvidersN(void) const
149 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED
150 , "The application does not have the privilege to call this method.");
151 SysAssertf(__pAccountAccessorImpl != null,
152 "Not yet constructed. Construct() should be called before use.");
154 IList* pList = __pAccountAccessorImpl->GetAllAccountProvidersN();
155 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
161 AccountAccessor::GetInstance(void)
163 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
165 if (__pInstance == null)
169 pthread_once(&onceBlock, InitAccountAccessor);
171 result r = GetLastResult();
175 onceBlock = PTHREAD_ONCE_INIT;
183 AccountAccessor::Construct(void)
185 SysAssertf(__pAccountAccessorImpl == null,
186 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
188 _AccountAccessorImpl* pAccountAccessorImpl = new (std::nothrow) _AccountAccessorImpl();
189 SysTryReturnResult(NID_SCL, pAccountAccessorImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
191 result r = pAccountAccessorImpl->Construct();
192 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountAccessorImpl.", GetErrorMessage(r));
194 __pAccountAccessorImpl = pAccountAccessorImpl;
199 delete pAccountAccessorImpl;
205 AccountAccessor::InitAccountAccessor(void)
207 std::unique_ptr<AccountAccessor> pInstance(new (std::nothrow) AccountAccessor());
208 SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
210 result r = pInstance->Construct();
211 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r));
213 __pInstance = pInstance.release();
215 std::atexit(DestroyAccountAccessor);
219 AccountAccessor::DestroyAccountAccessor(void)