2 // Open Service Platform
3 // Copyright (c) 2012 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 FScl_CalendarbookDbConnector.cpp
19 * @brief This is the implementation for _CalendarbookDbConnector class.
21 * This file contains definitions of @e _CalendarbookDbConnector class.
26 #include <calendar2.h>
27 #include <FBaseResult.h>
28 #include <FBaseRtMutex.h>
29 #include <FBaseSysLog.h>
30 #include <FSysSystemTime.h>
31 #include "FScl_CalendarbookDbConnector.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Runtime;
36 namespace Tizen { namespace Social
39 int _CalendarbookDbConnector::__connectingCount = 0;
40 Mutex _CalendarbookDbConnector::__mutex;
41 bool _CalendarbookDbConnector::__isInit = false;
44 _CalendarbookDbConnector::Connect(void)
47 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
49 if (__isInit == false)
53 pthread_once(&onceBlock, InitCalendarbookDbConnector);
54 if (GetLastResult() != E_SUCCESS)
56 onceBlock = PTHREAD_ONCE_INIT;
57 SysLogException(NID_SCL, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
64 r = __mutex.Acquire();
65 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
67 if (__connectingCount == 0)
69 long long startTicks = 0;
70 long long endTicks = 0;
72 System::SystemTime::GetTicks(startTicks);
74 int errorCode = calendar_connect_with_flags(CALENDAR_CONNECT_FLAG_RETRY);
76 System::SystemTime::GetTicks(endTicks);
78 SysTryCatch(NID_SCL, errorCode == CALENDAR_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Elapsed time : %lld (milliseconds)", endTicks - startTicks);
79 __connectingCount = 0;
84 r = __mutex.Release();
85 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
96 _CalendarbookDbConnector::Disconnect(void)
98 SysTryReturnResult(NID_SCL, __isInit == true, E_SYSTEM, "A system error has been occurred.");
100 result r = __mutex.Acquire();
101 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
105 if (__connectingCount == 0)
107 int errorCode = calendar_disconnect();
108 SysTryCatch(NID_SCL, errorCode == CALENDAR_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");
111 r = __mutex.Release();
112 SysTryReturnResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred.");
122 _CalendarbookDbConnector::_CalendarbookDbConnector(void)
126 _CalendarbookDbConnector::~_CalendarbookDbConnector(void)
131 _CalendarbookDbConnector::InitCalendarbookDbConnector(void)
133 result r = __mutex.Create();
134 SysTryReturnVoidResult(NID_SCL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has been occurred.");