// // Copyright (c) 2013 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /** * @file FSclAccountManager.cpp * @brief This is the implementation for AccountManager class. * * This file contains definitions of @e AccountManager class. */ #include #include #include #include #include #include #include #include #include #include "FScl_AccountManagerImpl.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Security; namespace Tizen { namespace Social { AccountManager* AccountManager::__pInstance = null; AccountManager::AccountManager(void) : __pAccountManagerImpl(null) { // empty body } AccountManager::~AccountManager(void) { delete __pAccountManagerImpl; } result AccountManager::AddAccount(Account& account) { result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r)); SysAssertf(__pAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pAccountManagerImpl->AddAccount(account); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } result AccountManager::RemoveAccount(AccountId accountId) { result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r)); SysAssertf(__pAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pAccountManagerImpl->RemoveAccount(accountId); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } result AccountManager::UpdateAccount(const Account& account) { result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r)); SysAssertf(__pAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pAccountManagerImpl->UpdateAccount(account); SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r)); return E_SUCCESS; } AccountManager* AccountManager::GetInstance(void) { static pthread_once_t onceBlock = PTHREAD_ONCE_INIT; if (__pInstance == null) { ClearLastResult(); pthread_once(&onceBlock, InitAccountManager); result r = GetLastResult(); if (IsFailed(r)) { onceBlock = PTHREAD_ONCE_INIT; } } return __pInstance; } result AccountManager::Construct(void) { SysAssertf(__pAccountManagerImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); _AccountManagerImpl* pAccountManagerImpl = new (std::nothrow) _AccountManagerImpl(); SysTryReturnResult(NID_SCL, pAccountManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed."); result r = pAccountManagerImpl->Construct(); SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountManagerImpl.", GetErrorMessage(r)); __pAccountManagerImpl = pAccountManagerImpl; return E_SUCCESS; CATCH: delete pAccountManagerImpl; return r; } void AccountManager::InitAccountManager(void) { std::unique_ptr pInstance(new (std::nothrow) AccountManager()); SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); result r = pInstance->Construct(); SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r)); __pInstance = pInstance.release(); std::atexit(DestroyAccountManager); } void AccountManager::DestroyAccountManager(void) { delete __pInstance; __pInstance = null; } }} // Tizen::Social