4 * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Dohyung Jin <dh.jin@samsung.com>
7 * Jongwon Lee <gogosing.lee@samsung.com>
8 * Donghee Ye <donghee.ye@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #include "ctsvc_internal.h"
25 #include "ctsvc_client_ipc.h"
26 #include "ctsvc_client_utils.h"
27 #include "ctsvc_client_handle.h"
28 #include "ctsvc_client_service_helper.h"
30 API int contacts_connect_with_flags(unsigned int flags)
34 contacts_h contact = NULL;
35 unsigned int id = ctsvc_client_get_pid();
37 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
38 if (CONTACTS_ERROR_NO_DATA == ret) {
39 ret = ctsvc_client_handle_create(id, &contact);
40 if (CONTACTS_ERROR_NONE != ret)
42 CTS_ERR("ctsvc_client_handle_create() Fail(%d)", ret);
43 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
44 return CONTACTS_ERROR_INTERNAL;
48 else if (CONTACTS_ERROR_NONE != ret) {
49 CTS_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 API int contacts_connect(void)
65 contacts_h contact = NULL;
66 unsigned int id = ctsvc_client_get_pid();
68 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
69 if (CONTACTS_ERROR_NO_DATA == ret) {
70 ret = ctsvc_client_handle_create(id, &contact);
71 if (CONTACTS_ERROR_NONE != ret)
73 CTS_ERR("ctsvc_client_handle_create() Fail(%d)", ret);
74 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
75 return CONTACTS_ERROR_INTERNAL;
79 else if (CONTACTS_ERROR_NONE != ret) {
80 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
83 ret = ctsvc_client_connect(contact);
84 if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
85 || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
86 return CONTACTS_ERROR_IPC;
91 API int contacts_disconnect(void)
95 contacts_h contact = NULL;
96 unsigned int id = ctsvc_client_get_pid();
98 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
99 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
100 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
102 ret = ctsvc_client_disconnect(contact);
103 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
104 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
105 ret = CONTACTS_ERROR_IPC;
110 API int contacts_connect_on_thread(void)
114 contacts_h contact = NULL;
115 unsigned int id = ctsvc_client_get_tid();
117 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
118 if (CONTACTS_ERROR_NO_DATA == ret) {
119 ret = ctsvc_client_handle_create(id, &contact);
120 if (CONTACTS_ERROR_NONE != ret)
122 CTS_ERR("ctsvc_client_handle_create() Fail(%d)", ret);
123 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
124 return CONTACTS_ERROR_INTERNAL;
128 else if (CONTACTS_ERROR_NONE != ret) {
129 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
133 ret = ctsvc_client_connect_on_thread(contact);
134 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
135 if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
136 || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
137 return CONTACTS_ERROR_IPC;
142 API int contacts_disconnect_on_thread(void)
146 contacts_h contact = NULL;
147 unsigned int id = ctsvc_client_get_tid();
149 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
150 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
151 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
153 ret = ctsvc_client_disconnect_on_thread(contact);
154 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
155 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
156 ret = CONTACTS_ERROR_IPC;