2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
19 #include <syspopup_caller.h>
22 #include "bluetooth-api.h"
23 #include "bt-internal-types.h"
25 #include "bt-common.h"
26 #include "bt-request-sender.h"
27 #include "bt-event-handler.h"
29 static char is_pbap_initialized = FALSE;
31 #define BT_CHECK_PBAP_INITIALIZED(func) \
32 if (is_pbap_initialized == FALSE) { \
33 BT_ERR("BT PBAP Client is not initiatized"); \
34 func BLUETOOTH_ERROR_NOT_INITIALIZED; \
38 BT_EXPORT_API int bluetooth_pbap_init(void)
40 bt_user_info_t *user_info;
43 if (is_pbap_initialized)
44 return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
46 user_info = _bt_get_user_data(BT_COMMON);
47 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
49 ret = _bt_register_event(BT_PBAP_CLIENT_EVENT, user_info->cb,
50 user_info->user_data);
52 is_pbap_initialized = TRUE;
57 BT_EXPORT_API int bluetooth_pbap_deinit(void)
61 BT_CHECK_PBAP_INITIALIZED(return);
63 ret = _bt_unregister_event(BT_PBAP_CLIENT_EVENT);
66 is_pbap_initialized = FALSE;
71 BT_EXPORT_API int bluetooth_pbap_connect(const bluetooth_device_address_t *address)
76 BT_CHECK_ENABLED(return);
77 BT_CHECK_PBAP_INITIALIZED(return);
80 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
82 g_array_append_vals(in_param1, address,
83 sizeof(bluetooth_device_address_t));
84 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_CONNECT,
85 in_param1, in_param2, in_param3, in_param4, &out_param);
87 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
93 BT_EXPORT_API int bluetooth_pbap_disconnect(const bluetooth_device_address_t *address)
98 BT_CHECK_ENABLED(return);
99 BT_CHECK_PBAP_INITIALIZED(return);
102 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
104 g_array_append_vals(in_param1, address,
105 sizeof(bluetooth_device_address_t));
106 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_DISCONNECT,
107 in_param1, in_param2, in_param3, in_param4, &out_param);
109 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
115 BT_EXPORT_API int bluetooth_pbap_get_phonebook_size(const bluetooth_device_address_t *address,
116 bt_pbap_folder_t *folder)
121 BT_CHECK_ENABLED(return);
122 BT_CHECK_PBAP_INITIALIZED(return);
125 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
127 g_array_append_vals(in_param1, address, sizeof(bluetooth_device_address_t));
129 g_array_append_vals(in_param2, folder, sizeof(bt_pbap_folder_t));
131 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_GET_PHONEBOOK_SIZE,
132 in_param1, in_param2, in_param3, in_param4, &out_param);
134 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
140 BT_EXPORT_API int bluetooth_pbap_get_phonebook(const bluetooth_device_address_t *address,
141 bt_pbap_folder_t *folder, bt_pbap_pull_parameters_t *app_param)
146 BT_CHECK_ENABLED(return);
147 BT_CHECK_PBAP_INITIALIZED(return);
150 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
152 g_array_append_vals(in_param1, address,
153 sizeof(bluetooth_device_address_t));
154 g_array_append_vals(in_param2, folder, sizeof(bt_pbap_folder_t));
155 g_array_append_vals(in_param3, app_param, sizeof(bt_pbap_pull_parameters_t));
156 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_GET_PHONEBOOK,
157 in_param1, in_param2, in_param3, in_param4, &out_param);
159 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
165 BT_EXPORT_API int bluetooth_pbap_get_list(const bluetooth_device_address_t *address,
166 bt_pbap_folder_t *folder, bt_pbap_list_parameters_t *app_param)
171 BT_CHECK_ENABLED(return);
172 BT_CHECK_PBAP_INITIALIZED(return);
175 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
177 g_array_append_vals(in_param1, address,
178 sizeof(bluetooth_device_address_t));
179 g_array_append_vals(in_param2, folder, sizeof(bt_pbap_folder_t));
180 g_array_append_vals(in_param3, app_param, sizeof(bt_pbap_list_parameters_t));
182 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_GET_LIST,
183 in_param1, in_param2, in_param3, in_param4, &out_param);
185 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
191 BT_EXPORT_API int bluetooth_pbap_pull_vcard(const bluetooth_device_address_t *address,
192 bt_pbap_folder_t *folder, bt_pbap_pull_vcard_parameters_t *app_param)
197 BT_CHECK_ENABLED(return);
198 BT_CHECK_PBAP_INITIALIZED(return);
201 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
203 g_array_append_vals(in_param1, address, sizeof(bluetooth_device_address_t));
204 g_array_append_vals(in_param2, folder, sizeof(bt_pbap_folder_t));
205 g_array_append_vals(in_param3, app_param, sizeof(bt_pbap_pull_vcard_parameters_t));
207 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_PULL_VCARD,
208 in_param1, in_param2, in_param3, in_param4, &out_param);
210 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
216 BT_EXPORT_API int bluetooth_pbap_phonebook_search(const bluetooth_device_address_t *address,
217 bt_pbap_folder_t *folder, bt_pbap_search_parameters_t *app_param)
221 BT_CHECK_ENABLED(return);
222 BT_CHECK_PBAP_INITIALIZED(return);
225 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
227 g_array_append_vals(in_param1, address, sizeof(bluetooth_device_address_t));
228 g_array_append_vals(in_param2, folder, sizeof(bt_pbap_folder_t));
229 g_array_append_vals(in_param3, app_param, sizeof(bt_pbap_search_parameters_t));
231 result = _bt_send_request(BT_OBEX_SERVICE, BT_PBAP_PHONEBOOK_SEARCH,
232 in_param1, in_param2, in_param3, in_param4, &out_param);
234 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);