4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@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 "bluetooth-api.h"
25 #include "bluetooth-hid-api.h"
26 #include "bt-internal-types.h"
28 #include "bt-common.h"
29 #include "bt-request-sender.h"
30 #include "bt-event-handler.h"
32 BT_EXPORT_API int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
36 /* Register AVRCP events */
37 ret = _bt_register_event(BT_HID_EVENT , (void *)callback_ptr, user_data);
39 if (ret != BLUETOOTH_ERROR_NONE &&
40 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
41 BT_ERR("Fail to init the event handler");
45 _bt_set_user_data(BT_HID, (void *)callback_ptr, user_data);
47 return BLUETOOTH_ERROR_NONE;
50 BT_EXPORT_API int bluetooth_hid_deinit(void)
54 ret = _bt_unregister_event(BT_HID_EVENT);
56 if (ret != BLUETOOTH_ERROR_NONE) {
57 BT_ERR("Fail to deinit the event handler");
61 _bt_set_user_data(BT_HID, NULL, NULL);
63 return BLUETOOTH_ERROR_NONE;
66 BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
69 bt_user_info_t *user_info;
71 BT_CHECK_PARAMETER(device_address, return);
72 BT_CHECK_ENABLED(return);
74 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_CONNECT)
75 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
76 BT_ERR("Don't have a privilege to use this API");
77 return BLUETOOTH_ERROR_PERMISSION_DEINED;
80 user_info = _bt_get_user_data(BT_HID);
81 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
84 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
86 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
88 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_CONNECT,
89 in_param1, in_param2, in_param3, in_param4,
90 user_info->cb, user_info->user_data);
92 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
97 BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
100 bt_user_info_t *user_info;
102 BT_CHECK_PARAMETER(device_address, return);
103 BT_CHECK_ENABLED(return);
105 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DISCONNECT)
106 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
107 BT_ERR("Don't have a privilege to use this API");
108 return BLUETOOTH_ERROR_PERMISSION_DEINED;
111 user_info = _bt_get_user_data(BT_HID);
112 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
115 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
117 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
119 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_DISCONNECT,
120 in_param1, in_param2, in_param3, in_param4,
121 user_info->cb, user_info->user_data);
123 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);