Fixed the build error for gcc-14
[platform/core/pim/contacts-service.git] / client / ctsvc_client_service.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20 #include "contacts.h"
21 #include "ctsvc_internal.h"
22 #include "ctsvc_client_ipc.h"
23 #include "ctsvc_client_utils.h"
24 #include "ctsvc_client_handle.h"
25 #include "ctsvc_client_service_helper.h"
26
27 EXPORT_API int contacts_connect_with_flags(unsigned int flags)
28 {
29         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
30         CTS_FN_CALL;
31         int ret;
32         contacts_h contact = NULL;
33         unsigned int id = ctsvc_client_get_pid();
34
35         ret = ctsvc_client_handle_get_p_with_id(id, &contact);
36         if (CONTACTS_ERROR_NO_DATA == ret) {
37                 ret = ctsvc_client_handle_create(id, &contact);
38                 if (CONTACTS_ERROR_NONE != ret) {
39                         /* LCOV_EXCL_START */
40                         ERR("ctsvc_client_handle_create() Fail(%d)", ret);
41                         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
42                                 return CONTACTS_ERROR_INTERNAL;
43                         return ret;
44                         /* LCOV_EXCL_STOP */
45                 }
46         } else if (CONTACTS_ERROR_NONE != ret) {
47                 /* LCOV_EXCL_START */
48                 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
49                 return ret;
50                 /* LCOV_EXCL_STOP */
51         }
52
53         ret = ctsvc_client_connect_with_flags(contact, flags);
54         if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
55                         || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
56                 return CONTACTS_ERROR_IPC;
57
58         return ret;
59 }
60
61 EXPORT_API int contacts_connect(void)
62 {
63         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
64         CTS_FN_CALL;
65         int ret;
66         contacts_h contact = NULL;
67         unsigned int id = ctsvc_client_get_pid();
68
69         ret = ctsvc_client_handle_get_p_with_id(id, &contact);
70         if (CONTACTS_ERROR_NO_DATA == ret) {
71                 ret = ctsvc_client_handle_create(id, &contact);
72                 if (CONTACTS_ERROR_NONE != ret) {
73                         /* LCOV_EXCL_START */
74                         ERR("ctsvc_client_handle_create() Fail(%d)", ret);
75                         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
76                                 return CONTACTS_ERROR_INTERNAL;
77                         return ret;
78                         /* LCOV_EXCL_STOP */
79                 }
80         } else if (CONTACTS_ERROR_NONE != ret) {
81                 /* LCOV_EXCL_START */
82                 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
83                 return ret;
84                 /* LCOV_EXCL_STOP */
85         }
86         ret = ctsvc_client_connect(contact);
87         if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
88                         || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
89                 return CONTACTS_ERROR_IPC;
90
91         return ret;
92 }
93
94 EXPORT_API int contacts_disconnect(void)
95 {
96         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
97         CTS_FN_CALL;
98         int ret;
99         contacts_h contact = NULL;
100         unsigned int id = ctsvc_client_get_pid();
101
102         ret = ctsvc_client_handle_get_p_with_id(id, &contact);
103         RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
104         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
105
106         ret = ctsvc_client_disconnect(contact);
107         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
108         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
109                 ret = CONTACTS_ERROR_IPC;
110
111         return ret;
112 }
113
114 EXPORT_API int contacts_connect_on_thread(void)
115 {
116         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
117         CTS_FN_CALL;
118         int ret;
119         contacts_h contact = NULL;
120         unsigned int id = ctsvc_client_get_tid();
121
122         ret = ctsvc_client_handle_get_p_with_id(id, &contact);
123         if (CONTACTS_ERROR_NO_DATA == ret) {
124                 ret = ctsvc_client_handle_create(id, &contact);
125                 if (CONTACTS_ERROR_NONE != ret) {
126                         /* LCOV_EXCL_START */
127                         ERR("ctsvc_client_handle_create() Fail(%d)", ret);
128                         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
129                                 return CONTACTS_ERROR_INTERNAL;
130                         return ret;
131                         /* LCOV_EXCL_STOP */
132                 }
133         } else if (CONTACTS_ERROR_NONE != ret) {
134                 /* LCOV_EXCL_START */
135                 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
136                 return ret;
137                 /* LCOV_EXCL_STOP */
138         }
139
140         ret = ctsvc_client_connect_on_thread(contact);
141         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
142         if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
143                         || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
144                 return CONTACTS_ERROR_IPC;
145
146         return ret;
147 }
148
149 EXPORT_API int contacts_disconnect_on_thread(void)
150 {
151         CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
152         CTS_FN_CALL;
153         int ret;
154         contacts_h contact = NULL;
155         unsigned int id = ctsvc_client_get_tid();
156
157         ret = ctsvc_client_handle_get_p_with_id(id, &contact);
158         RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
159         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
160
161         ret = ctsvc_client_disconnect_on_thread(contact);
162         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
163         if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
164                 ret = CONTACTS_ERROR_IPC;
165
166         return ret;
167 }
168