4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include "cal_internal.h"
22 #include "cal_client_handle.h"
23 #include "cal_client_service_helper.h"
24 #include "cal_client_utils.h"
26 static int connection_count = 0;
27 static TLS int connection_count_on_thread = 0;
29 API int calendar_connect(void)
33 calendar_h handle = NULL;
34 unsigned int id = cal_client_get_pid();
36 ret = cal_client_handle_get_p_with_id(id, &handle);
37 if (CALENDAR_ERROR_NO_DATA == ret) {
38 ret = cal_client_handle_create(id, &handle);
39 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_create() Fail(%d)", ret);
40 } else if (CALENDAR_ERROR_NONE != ret) {
42 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
46 ret = cal_client_connect(handle, id, &connection_count);
50 API int calendar_disconnect(void)
53 calendar_h handle = NULL;
54 unsigned int id = cal_client_get_pid();
56 ret = cal_client_handle_get_p_with_id(id, &handle);
57 if (CALENDAR_ERROR_NO_DATA == ret) {
58 return CALENDAR_ERROR_NONE;
59 } else if (CALENDAR_ERROR_NONE != ret) {
61 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
65 ret = cal_client_disconnect(handle, id, &connection_count);
66 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
70 API int calendar_connect_on_thread(void)
73 calendar_h handle = NULL;
74 unsigned int id = cal_client_get_tid();
76 ret = cal_client_handle_get_p_with_id(id, &handle);
77 if (CALENDAR_ERROR_NO_DATA == ret) {
78 ret = cal_client_handle_create(id, &handle);
79 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_create() Fail(%d)", ret);
80 } else if (CALENDAR_ERROR_NONE != ret) {
82 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
86 ret = cal_client_connect(handle, id, &connection_count_on_thread);
90 API int calendar_disconnect_on_thread(void)
93 calendar_h handle = NULL;
94 unsigned int id = cal_client_get_tid();
96 ret = cal_client_handle_get_p_with_id(id, &handle);
97 if (CALENDAR_ERROR_NO_DATA == ret) {
98 return CALENDAR_ERROR_NONE;
99 } else if (CALENDAR_ERROR_NONE != ret) {
100 /* LCOV_EXCL_START */
101 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
105 ret = cal_client_disconnect(handle, id, &connection_count_on_thread);
106 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
110 API int calendar_connect_with_flags(unsigned int flags)
113 calendar_h handle = NULL;
114 unsigned int id = cal_client_get_pid();
116 ret = cal_client_handle_get_p_with_id(id, &handle);
117 if (CALENDAR_ERROR_NO_DATA == ret) {
118 ret = cal_client_handle_create(id, &handle);
119 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_create() Fail(%d)", ret);
120 } else if (CALENDAR_ERROR_NONE != ret) {
121 /* LCOV_EXCL_START */
122 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
126 ret = cal_client_connect_with_flags(handle, id, &connection_count, flags);