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_CalendarbookDbConnector.cpp
18 * @brief This is the implementation for _CalendarbookDbConnector class.
20 * This file contains definitions of @e _CalendarbookDbConnector class.
25 #include <calendar2.h>
26 #include <FBaseResult.h>
27 #include <FBaseRtMutex.h>
28 #include <FBaseSysLog.h>
29 #include <FSysSystemTime.h>
30 #include "FScl_CalendarbookDbConnector.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Runtime;
35 namespace Tizen { namespace Social
38 int _CalendarbookDbConnector::__connectingCount = 0;
39 Mutex _CalendarbookDbConnector::__mutex;
40 bool _CalendarbookDbConnector::__isInit = false;
43 _CalendarbookDbConnector::Connect(void)
46 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
48 if (__isInit == false)
52 pthread_once(&onceBlock, InitCalendarbookDbConnector);
53 if (GetLastResult() != E_SUCCESS)
55 onceBlock = PTHREAD_ONCE_INIT;
56 SysLogException(NID_SCL, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
63 r = __mutex.Acquire();
64 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
66 if (__connectingCount == 0)
68 long long startTicks = 0;
69 long long endTicks = 0;
71 System::SystemTime::GetTicks(startTicks);
73 int errorCode = calendar_connect_with_flags(CALENDAR_CONNECT_FLAG_RETRY);
75 System::SystemTime::GetTicks(endTicks);
77 SysTryCatch(NID_SCL, errorCode == CALENDAR_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Elapsed time : %lld (milliseconds)", endTicks - startTicks);
78 __connectingCount = 0;
83 r = __mutex.Release();
84 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
95 _CalendarbookDbConnector::Disconnect(void)
97 SysTryReturnResult(NID_SCL, __isInit == true, E_SYSTEM, "A system error has been occurred.");
99 result r = __mutex.Acquire();
100 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
104 if (__connectingCount == 0)
106 int errorCode = calendar_disconnect();
107 SysTryCatch(NID_SCL, errorCode == CALENDAR_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
110 r = __mutex.Release();
111 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
121 _CalendarbookDbConnector::_CalendarbookDbConnector(void)
125 _CalendarbookDbConnector::~_CalendarbookDbConnector(void)
130 _CalendarbookDbConnector::InitCalendarbookDbConnector(void)
132 result r = __mutex.Create();
133 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");