4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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"
27 EXPORT_API int contacts_connect_with_flags(unsigned int flags)
29 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
32 contacts_h contact = NULL;
33 unsigned int id = ctsvc_client_get_pid();
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) {
40 ERR("ctsvc_client_handle_create() Fail(%d)", ret);
41 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
42 return CONTACTS_ERROR_INTERNAL;
46 } else if (CONTACTS_ERROR_NONE != ret) {
48 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
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;
61 EXPORT_API int contacts_connect(void)
63 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
66 contacts_h contact = NULL;
67 unsigned int id = ctsvc_client_get_pid();
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) {
74 ERR("ctsvc_client_handle_create() Fail(%d)", ret);
75 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
76 return CONTACTS_ERROR_INTERNAL;
80 } else if (CONTACTS_ERROR_NONE != ret) {
82 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
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;
94 EXPORT_API int contacts_disconnect(void)
96 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
99 contacts_h contact = NULL;
100 unsigned int id = ctsvc_client_get_pid();
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);
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;
114 EXPORT_API int contacts_connect_on_thread(void)
116 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
119 contacts_h contact = NULL;
120 unsigned int id = ctsvc_client_get_tid();
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;
133 } else if (CONTACTS_ERROR_NONE != ret) {
134 /* LCOV_EXCL_START */
135 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
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;
149 EXPORT_API int contacts_disconnect_on_thread(void)
151 CHECK_CONTACT_SUPPORTED(CONTACT_FEATURE);
154 contacts_h contact = NULL;
155 unsigned int id = ctsvc_client_get_tid();
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);
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;