2 // Copyright (c) 2012 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 FScl_AccountDbConnector.cpp
18 * @brief This is the implementation for _AccountDbConnector class.
20 * This file contains definitions of @e _AccountDbConnector class.
23 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include "FScl_AccountDbConnector.h"
28 namespace Tizen { namespace Social
31 bool _AccountDbConnector::__isAccountDbConnected = false;
32 _AccountDbConnector* _AccountDbConnector::__pInstance = null;
34 _AccountDbConnector::_AccountDbConnector(void)
38 _AccountDbConnector::~_AccountDbConnector(void)
43 _AccountDbConnector::Connect(void)
45 int ret = account_connect();
46 SysTryReturnResult(NID_SCL, ret == ACCOUNT_ERROR_NONE, E_SYSTEM, "The method cannot proceed due to a severe system error.");
52 _AccountDbConnector::Disconnect(void)
54 int ret = account_disconnect();
55 SysTryReturnResult(NID_SCL, ret == ACCOUNT_ERROR_NONE, E_SYSTEM, "The method cannot proceed due to a severe system error.");
61 _AccountDbConnector::EnsureDbConnection(void)
63 if (!__isAccountDbConnected)
65 _AccountDbConnector* pInstance = GetInstance();
66 SysTryReturn(NID_SCL, pInstance != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
68 result r = pInstance->Connect();
69 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
71 __isAccountDbConnected = true;
78 _AccountDbConnector::InitAccountDbConnector(void)
80 std::unique_ptr<_AccountDbConnector> pInstance(new (std::nothrow) _AccountDbConnector());
81 SysTryReturnVoidResult(NID_SCL, pInstance, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
83 __pInstance = pInstance.release();
85 std::atexit(DestroyAccountDbConnector);
89 _AccountDbConnector::DestroyAccountDbConnector(void)
96 _AccountDbConnector::GetInstance(void)
98 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
100 if (__pInstance == null)
104 pthread_once(&onceBlock, InitAccountDbConnector);
106 result r = GetLastResult();
110 onceBlock = PTHREAD_ONCE_INIT;