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 #include "bluetooth-api.h"
19 #include "bluetooth-hid-api.h"
20 #include "bt-internal-types.h"
22 #include "bt-common.h"
23 #include "bt-request-sender.h"
24 #include "bt-event-handler.h"
26 BT_EXPORT_API int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
30 /* Register AVRCP events */
31 ret = _bt_register_event(BT_HID_EVENT , (void *)callback_ptr, user_data);
33 if (ret != BLUETOOTH_ERROR_NONE &&
34 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
35 BT_ERR("Fail to init the event handler");
39 _bt_set_user_data(BT_HID, (void *)callback_ptr, user_data);
41 return BLUETOOTH_ERROR_NONE;
44 BT_EXPORT_API int bluetooth_hid_deinit(void)
48 ret = _bt_unregister_event(BT_HID_EVENT);
50 if (ret != BLUETOOTH_ERROR_NONE) {
51 BT_ERR("Fail to deinit the event handler");
55 _bt_set_user_data(BT_HID, NULL, NULL);
57 return BLUETOOTH_ERROR_NONE;
60 BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
63 bt_user_info_t *user_info;
65 BT_CHECK_PARAMETER(device_address, return);
66 BT_CHECK_ENABLED(return);
68 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_CONNECT)
69 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
70 BT_ERR("Don't have a privilege to use this API");
71 return BLUETOOTH_ERROR_PERMISSION_DEINED;
74 user_info = _bt_get_user_data(BT_HID);
75 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
78 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
80 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
82 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_CONNECT,
83 in_param1, in_param2, in_param3, in_param4,
84 user_info->cb, user_info->user_data);
86 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
91 BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
94 bt_user_info_t *user_info;
96 BT_CHECK_PARAMETER(device_address, return);
97 BT_CHECK_ENABLED(return);
99 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DISCONNECT)
100 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
101 BT_ERR("Don't have a privilege to use this API");
102 return BLUETOOTH_ERROR_PERMISSION_DEINED;
105 user_info = _bt_get_user_data(BT_HID);
106 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
109 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
111 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
113 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_DISCONNECT,
114 in_param1, in_param2, in_param3, in_param4,
115 user_info->cb, user_info->user_data);
117 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);