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 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
59 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
60 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
62 SysAssertf(__pAccountManagerImpl != null,
63 "Not yet constructed. Construct() should be called before use.");
65 r = __pAccountManagerImpl->AddAccount(account);
66 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
72 AccountManager::RemoveAccount(AccountId accountId)
74 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
75 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
76 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
78 SysAssertf(__pAccountManagerImpl != null,
79 "Not yet constructed. Construct() should be called before use.");
81 r = __pAccountManagerImpl->RemoveAccount(accountId);
82 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
88 AccountManager::UpdateAccount(const Account& account)
90 result r = _AccessController::CheckUserPrivilege(_PRV_ACCOUNT_WRITE);
91 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
92 SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
94 SysAssertf(__pAccountManagerImpl != null,
95 "Not yet constructed. Construct() should be called before use.");
97 r = __pAccountManagerImpl->UpdateAccount(account);
98 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
104 AccountManager::GetInstance(void)
106 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
108 if (__pInstance == null)
112 pthread_once(&onceBlock, InitAccountManager);
114 result r = GetLastResult();
118 onceBlock = PTHREAD_ONCE_INIT;
126 AccountManager::Construct(void)
128 SysAssertf(__pAccountManagerImpl == null,
129 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
131 _AccountManagerImpl* pAccountManagerImpl = new (std::nothrow) _AccountManagerImpl();
132 SysTryReturnResult(NID_SCL, pAccountManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
134 result r = pAccountManagerImpl->Construct();
135 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Failed to construct pAccountManagerImpl.", GetErrorMessage(r));
137 __pAccountManagerImpl = pAccountManagerImpl;
142 delete pAccountManagerImpl;
148 AccountManager::InitAccountManager(void)
150 std::unique_ptr<AccountManager> pInstance(new (std::nothrow) AccountManager());
151 SysTryReturnVoidResult(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
153 result r = pInstance->Construct();
154 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Failed to construct pInstance.", GetErrorMessage(r));
156 __pInstance = pInstance.release();
158 std::atexit(DestroyAccountManager);
162 AccountManager::DestroyAccountManager(void)