add comment LCOV_EXCL
[platform/core/pim/calendar-service.git] / client / cal_client_service.c
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include "calendar.h"
21 #include "cal_internal.h"
22 #include "cal_client_handle.h"
23 #include "cal_client_service_helper.h"
24 #include "cal_client_utils.h"
25
26 static int connection_count = 0;
27 static TLS int connection_count_on_thread = 0;
28
29 API int calendar_connect(void)
30 {
31         CAL_FN_CALL();
32         int ret;
33         calendar_h handle = NULL;
34         unsigned int id = cal_client_get_pid();
35
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                 /* LCOV_EXCL_START */
42                 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
43                 return ret;
44                 /* LCOV_EXCL_STOP */
45         }
46         ret = cal_client_connect(handle, id, &connection_count);
47         return ret;
48 }
49
50 API int calendar_disconnect(void)
51 {
52         int ret;
53         calendar_h handle = NULL;
54         unsigned int id = cal_client_get_pid();
55
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) {
60                 /* LCOV_EXCL_START */
61                 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
62                 return ret;
63                 /* LCOV_EXCL_STOP */
64         }
65         ret = cal_client_disconnect(handle, id, &connection_count);
66         WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
67         return ret;
68 }
69
70 API int calendar_connect_on_thread(void)
71 {
72         int ret;
73         calendar_h handle = NULL;
74         unsigned int id = cal_client_get_tid();
75
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) {
81                 /* LCOV_EXCL_START */
82                 ERR("cal_client_handle_get_p_with_id() Fail(%d)", ret);
83                 return ret;
84                 /* LCOV_EXCL_STOP */
85         }
86         ret = cal_client_connect(handle, id, &connection_count_on_thread);
87         return ret;
88 }
89
90 API int calendar_disconnect_on_thread(void)
91 {
92         int ret;
93         calendar_h handle = NULL;
94         unsigned int id = cal_client_get_tid();
95
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);
102                 return ret;
103                 /* LCOV_EXCL_STOP */
104         }
105         ret = cal_client_disconnect(handle, id, &connection_count_on_thread);
106         WARN_IF(CALENDAR_ERROR_NONE != ret, "cal_client_disconnect() Fail(%d)", ret);
107         return ret;
108 }
109
110 API int calendar_connect_with_flags(unsigned int flags)
111 {
112         int ret;
113         calendar_h handle = NULL;
114         unsigned int id = cal_client_get_pid();
115
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);
123                 return ret;
124                 /* LCOV_EXCL_STOP */
125         }
126         ret = cal_client_connect_with_flags(handle, id, &connection_count, flags);
127         return ret;
128 }