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 FSclAccountManager.cpp
19 * @brief This is the implementation for AccountManager class.
21 * This file contains definitions of @e AccountManager 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 <FSclAccountManager.h>
33 #include "FScl_AccountManagerImpl.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Security;
39 namespace Tizen { namespace Social
42 AccountManager* AccountManager::__pInstance = null;
44 AccountManager::AccountManager(void)
45 : __pAccountManagerImpl(null)
50 AccountManager::~AccountManager(void)
52 delete __pAccountManagerImpl;
56 AccountManager::AddAccount(Account& account)
58 SysTryReturnResult(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED
59 , "The application does not have the privilege to call this method.");
60 SysAssertf(__pAccountManagerImpl != null,
61 "Not yet constructed. Construct() should be called before use.");
63 result r = __pAccountManagerImpl->AddAccount(account);
64 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
70 AccountManager::RemoveAccount(AccountId accountId)
72 SysTryReturnResult(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED
73 , "The application does not have the privilege to call this method.");
74 SysAssertf(__pAccountManagerImpl != null,
75 "Not yet constructed. Construct() should be called before use.");
77 result r = __pAccountManagerImpl->RemoveAccount(accountId);
78 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
84 AccountManager::UpdateAccount(const Account& account)
86 SysTryReturnResult(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED
87 , "The application does not have the privilege to call this method.");
88 SysAssertf(__pAccountManagerImpl != null,
89 "Not yet constructed. Construct() should be called before use.");
91 result r = __pAccountManagerImpl->UpdateAccount(account);
92 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
98 AccountManager::GetInstance(void)
100 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
102 if (__pInstance == null)
106 pthread_once(&onceBlock, InitAccountManager);
108 result r = GetLastResult();
112 onceBlock = PTHREAD_ONCE_INIT;
120 AccountManager::Construct(void)
122 SysAssertf(__pAccountManagerImpl == null,
123 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
125 _AccountManagerImpl* pAccountManagerImpl = new (std::nothrow) _AccountManagerImpl();
126 SysTryReturnResult(NID_SCL, pAccountManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
128 result r = pAccountManagerImpl->Construct();
129 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountManagerImpl.", GetErrorMessage(r));
131 __pAccountManagerImpl = pAccountManagerImpl;
136 delete pAccountManagerImpl;
142 AccountManager::InitAccountManager(void)
144 std::unique_ptr<AccountManager> pInstance(new (std::nothrow) AccountManager());
145 SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
147 result r = pInstance->Construct();
148 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r));
150 __pInstance = pInstance.release();
152 std::atexit(DestroyAccountManager);
156 AccountManager::DestroyAccountManager(void)