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 (NULL == contact) {
39 ret = ctsvc_client_handle_create(id, &contact);
40 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
42 else if (CONTACTS_ERROR_NONE != ret) {
43 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
47 ret = ctsvc_client_connect_with_flags(contact, flags);
52 API int contacts_connect(void)
56 contacts_h contact = NULL;
57 unsigned int id = ctsvc_client_get_pid();
59 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
60 if (NULL == contact) {
61 ret = ctsvc_client_handle_create(id, &contact);
62 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
64 else if (CONTACTS_ERROR_NONE != ret) {
65 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
68 ret = ctsvc_client_connect(contact);
73 API int contacts_disconnect(void)
77 contacts_h contact = NULL;
78 unsigned int id = ctsvc_client_get_pid();
80 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
81 RETV_IF(NULL == contact, CONTACTS_ERROR_NONE);
82 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
83 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
85 ret = ctsvc_client_disconnect(contact);
86 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
88 if (0 == ((ctsvc_base_s *)contact)->connection_count) {
89 ret = ctsvc_client_handle_remove(id, contact);
90 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
96 API int contacts_connect_on_thread(void)
100 contacts_h contact = NULL;
101 unsigned int id = ctsvc_client_get_tid();
103 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
104 if (NULL == contact) {
105 ret = ctsvc_client_handle_create(id, &contact);
106 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
108 else if (CONTACTS_ERROR_NONE != ret) {
109 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
113 ret = ctsvc_client_connect_on_thread(contact);
114 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
119 API int contacts_disconnect_on_thread(void)
123 contacts_h contact = NULL;
124 unsigned int id = ctsvc_client_get_tid();
126 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
127 RETV_IF(NULL == contact, CONTACTS_ERROR_NONE);
128 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
129 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
131 ret = ctsvc_client_disconnect_on_thread(contact);
132 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
134 if (0 == ((ctsvc_base_s *)contact)->connection_count) {
135 ret = ctsvc_client_handle_remove(id, contact);
136 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);