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 API int contacts_connect_with_flags(unsigned int flags)
31 contacts_h contact = NULL;
32 unsigned int id = ctsvc_client_get_pid();
34 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
35 if (CONTACTS_ERROR_NO_DATA == ret) {
36 ret = ctsvc_client_handle_create(id, &contact);
37 if (CONTACTS_ERROR_NONE != ret) {
38 ERR("ctsvc_client_handle_create() Fail(%d)", ret);
39 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
40 return CONTACTS_ERROR_INTERNAL;
43 } else if (CONTACTS_ERROR_NONE != ret) {
44 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
48 ret = ctsvc_client_connect_with_flags(contact, flags);
49 if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
50 || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
51 return CONTACTS_ERROR_IPC;
56 API int contacts_connect(void)
60 contacts_h contact = NULL;
61 unsigned int id = ctsvc_client_get_pid();
63 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
64 if (CONTACTS_ERROR_NO_DATA == ret) {
65 ret = ctsvc_client_handle_create(id, &contact);
66 if (CONTACTS_ERROR_NONE != ret) {
67 ERR("ctsvc_client_handle_create() Fail(%d)", ret);
68 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
69 return CONTACTS_ERROR_INTERNAL;
72 } else if (CONTACTS_ERROR_NONE != ret) {
73 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
76 ret = ctsvc_client_connect(contact);
77 if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
78 || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
79 return CONTACTS_ERROR_IPC;
84 API int contacts_disconnect(void)
88 contacts_h contact = NULL;
89 unsigned int id = ctsvc_client_get_pid();
91 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
92 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
93 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
95 ret = ctsvc_client_disconnect(contact);
96 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
97 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
98 ret = CONTACTS_ERROR_IPC;
103 API int contacts_connect_on_thread(void)
107 contacts_h contact = NULL;
108 unsigned int id = ctsvc_client_get_tid();
110 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
111 if (CONTACTS_ERROR_NO_DATA == ret) {
112 ret = ctsvc_client_handle_create(id, &contact);
113 if (CONTACTS_ERROR_NONE != ret) {
114 ERR("ctsvc_client_handle_create() Fail(%d)", ret);
115 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
116 return CONTACTS_ERROR_INTERNAL;
119 } else if (CONTACTS_ERROR_NONE != ret) {
120 ERR("ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
124 ret = ctsvc_client_connect_on_thread(contact);
125 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
126 if ((CONTACTS_ERROR_IPC_NOT_AVALIABLE == ret)
127 || (CONTACTS_ERROR_PERMISSION_DENIED == ret))
128 return CONTACTS_ERROR_IPC;
133 API int contacts_disconnect_on_thread(void)
137 contacts_h contact = NULL;
138 unsigned int id = ctsvc_client_get_tid();
140 ret = ctsvc_client_handle_get_p_with_id(id, &contact);
141 RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
142 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_p_with_id() Fail(%d)", ret);
144 ret = ctsvc_client_disconnect_on_thread(contact);
145 WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
146 if (CONTACTS_ERROR_INVALID_PARAMETER == ret)
147 ret = CONTACTS_ERROR_IPC;