add handle
[platform/core/pim/contacts-service.git] / client / ctsvc_client_service.c
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Dohyung Jin <dh.jin@samsung.com>
7  *                 Jongwon Lee <gogosing.lee@samsung.com>
8  *                 Donghee Ye <donghee.ye@samsung.com>
9  *
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
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
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.
21  *
22  */
23 #include "contacts.h"
24 #include "ctsvc_internal.h"
25 #include "ctsvc_client_ipc.h"
26 #include "ctsvc_client_handle.h"
27 #include "ctsvc_client_service_helper.h"
28
29 API int contacts_connect_with_flags(unsigned int flags)
30 {
31         CTS_FN_CALL;
32         int ret;
33         contacts_h contact = NULL;
34
35         ret = ctsvc_client_handle_get_current_p(&contact);
36         if (CONTACTS_ERROR_NO_DATA == ret) {
37                 ret = ctsvc_client_handle_create(&contact);
38                 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
39         }
40         else if (CONTACTS_ERROR_NONE != ret) {
41                 CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
42                 return ret;
43         }
44
45         ret = ctsvc_client_connect_with_flags(contact, flags);
46
47         return ret;
48 }
49
50 API int contacts_connect(void)
51 {
52         CTS_FN_CALL;
53         int ret;
54         contacts_h contact = NULL;
55
56         ret = ctsvc_client_handle_get_current_p(&contact);
57         if (CONTACTS_ERROR_NO_DATA == ret) {
58                 ret = ctsvc_client_handle_create(&contact);
59                 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
60         }
61         else if (CONTACTS_ERROR_NONE != ret) {
62                 CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
63                 return ret;
64         }
65         ret = ctsvc_client_connect(contact);
66
67         return ret;
68 }
69
70 API int contacts_disconnect(void)
71 {
72         CTS_FN_CALL;
73         int ret;
74         contacts_h contact = NULL;
75
76         ret = ctsvc_client_handle_get_current_p(&contact);
77         RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
78         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
79
80         ret = ctsvc_client_disconnect(contact);
81         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect() Fail(%d)", ret);
82
83         return ret;
84 }
85
86 API int contacts_connect_on_thread(void)
87 {
88         CTS_FN_CALL;
89         int ret;
90         contacts_h contact = NULL;
91
92         ret = ctsvc_client_handle_get_current_p(&contact);
93         if (CONTACTS_ERROR_NO_DATA == ret) {
94                 ret = ctsvc_client_handle_create(&contact);
95                 RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_create() Fail(%d)", ret);
96         }
97         else if (CONTACTS_ERROR_NONE != ret) {
98                 CTS_ERR("ctsvc_client_handle_get_current_p() Fail(%d)", ret);
99                 return ret;
100         }
101
102         ret = ctsvc_client_connect_on_thread(contact);
103         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_connect_on_thread() Fail(%d)", ret);
104
105         return ret;
106 }
107
108 API int contacts_disconnect_on_thread(void)
109 {
110         CTS_FN_CALL;
111         int ret;
112         contacts_h contact = NULL;
113
114         ret = ctsvc_client_handle_get_current_p(&contact);
115         RETV_IF(CONTACTS_ERROR_NO_DATA == ret, CONTACTS_ERROR_NONE);
116         RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_client_handle_get_current_p() Fail(%d)", ret);
117
118         ret = ctsvc_client_disconnect_on_thread(contact);
119         WARN_IF(CONTACTS_ERROR_NONE != ret, "ctsvc_client_disconnect_on_thread() Fail(%d)", ret);
120
121         return ret;
122 }
123