2 // Copyright (c) 2013 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 FSclAccountManager.cpp
18 * @brief This is the implementation for AccountManager class.
20 * This file contains definitions of @e AccountManager class.
25 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseSysLog.h>
28 #include <FBaseColIList.h>
29 #include <FSec_AccessController.h>
30 #include <FSclAccount.h>
31 #include <FSclAccountManager.h>
32 #include "FScl_AccountManagerImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Security;
38 namespace Tizen { namespace Social
41 AccountManager* AccountManager::__pInstance = null;
43 AccountManager::AccountManager(void)
44 : __pAccountManagerImpl(null)
49 AccountManager::~AccountManager(void)
51 delete __pAccountManagerImpl;
55 AccountManager::AddAccount(Account& account)
57 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
58 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
59 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
61 SysAssertf(__pAccountManagerImpl != null,
62 "Not yet constructed. Construct() should be called before use.");
64 r = __pAccountManagerImpl->AddAccount(account);
65 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
71 AccountManager::RemoveAccount(AccountId accountId)
73 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
74 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
75 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
77 SysAssertf(__pAccountManagerImpl != null,
78 "Not yet constructed. Construct() should be called before use.");
80 r = __pAccountManagerImpl->RemoveAccount(accountId);
81 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
87 AccountManager::UpdateAccount(const Account& account)
89 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
90 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
91 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
93 SysAssertf(__pAccountManagerImpl != null,
94 "Not yet constructed. Construct() should be called before use.");
96 r = __pAccountManagerImpl->UpdateAccount(account);
97 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
103 AccountManager::GetInstance(void)
105 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
107 if (__pInstance == null)
111 pthread_once(&onceBlock, InitAccountManager);
113 result r = GetLastResult();
117 onceBlock = PTHREAD_ONCE_INIT;
125 AccountManager::Construct(void)
127 SysAssertf(__pAccountManagerImpl == null,
128 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
130 _AccountManagerImpl* pAccountManagerImpl = new (std::nothrow) _AccountManagerImpl();
131 SysTryReturnResult(NID_SCL, pAccountManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
133 result r = pAccountManagerImpl->Construct();
134 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountManagerImpl.", GetErrorMessage(r));
136 __pAccountManagerImpl = pAccountManagerImpl;
141 delete pAccountManagerImpl;
147 AccountManager::InitAccountManager(void)
149 std::unique_ptr<AccountManager> pInstance(new (std::nothrow) AccountManager());
150 SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
152 result r = pInstance->Construct();
153 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r));
155 __pInstance = pInstance.release();
157 std::atexit(DestroyAccountManager);
161 AccountManager::DestroyAccountManager(void)