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(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
82 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
84 ret = ctsvc_client_disconnect(contact);
85 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
87 if (0 == ((ctsvc_base_s *)contact)->connection_count) {
88 ret = ctsvc_client_handle_remove(id, contact);
89 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);
95 API int contacts_connect_on_thread(void)
99 contacts_h contact = NULL;
100 unsigned int id = ctsvc_client_get_tid();
102 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
103 if (NULL == contact) {
104 ret = ctsvc_client_handle_create(id, &contact);
105 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
107 else if (CONTACTS_ERROR_NONE != ret) {
108 CTS_ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
112 ret = ctsvc_client_connect_on_thread(contact);
113 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
118 API int contacts_disconnect_on_thread(void)
122 contacts_h contact = NULL;
123 unsigned int id = ctsvc_client_get_tid();
125 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
126 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
127 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
129 ret = ctsvc_client_disconnect_on_thread(contact);
130 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
132 if (0 == ((ctsvc_base_s *)contact)->connection_count) {
133 ret = ctsvc_client_handle_remove(id, contact);
134 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_handle_remove() Fail(%d)", ret);