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) {
41 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
44 ret = cal_client_connect(handle, id, &connection_count);
48 API int calendar_disconnect(void)
51 calendar_h handle = NULL;
52 unsigned int id = cal_client_get_pid();
54 ret = cal_client_handle_get_p_with_id(id, &handle);
55 if (CALENDAR_ERROR_NO_DATA == ret) {
56 return CALENDAR_ERROR_NONE;
57 } else if (CALENDAR_ERROR_NONE != ret) {
58 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
61 ret = cal_client_disconnect(handle, id, &connection_count);
62 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
66 API int calendar_connect_on_thread(void)
69 calendar_h handle = NULL;
70 unsigned int id = cal_client_get_tid();
72 ret = cal_client_handle_get_p_with_id(id, &handle);
73 if (CALENDAR_ERROR_NO_DATA == ret) {
74 ret = cal_client_handle_create(id, &handle);
75 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_create() Fail(%d)", ret);
76 } else if (CALENDAR_ERROR_NONE != ret) {
77 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
80 ret = cal_client_connect(handle, id, &connection_count_on_thread);
84 API int calendar_disconnect_on_thread(void)
87 calendar_h handle = NULL;
88 unsigned int id = cal_client_get_tid();
90 ret = cal_client_handle_get_p_with_id(id, &handle);
91 if (CALENDAR_ERROR_NO_DATA == ret) {
92 return CALENDAR_ERROR_NONE;
93 } else if (CALENDAR_ERROR_NONE != ret) {
94 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
97 ret = cal_client_disconnect(handle, id, &connection_count_on_thread);
98 WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
102 API int calendar_connect_with_flags(unsigned int flags)
105 calendar_h handle = NULL;
106 unsigned int id = cal_client_get_pid();
108 ret = cal_client_handle_get_p_with_id(id, &handle);
109 if (CALENDAR_ERROR_NO_DATA == ret) {
110 ret = cal_client_handle_create(id, &handle);
111 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_client_handle_create() Fail(%d)", ret);
112 } else if (CALENDAR_ERROR_NONE != ret) {
113 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
116 ret = cal_client_connect_with_flags(handle, id, &connection_count, flags);