4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "bluetooth-api.h"
21 #include "bluetooth-hid-api.h"
22 #include "bt-internal-types.h"
24 #include "bt-common.h"
25 #include "bt-request-sender.h"
26 #include "bt-event-handler.h"
28 BT_EXPORT_API int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
32 /* Register AVRCP events */
33 ret = _bt_register_event(BT_HID_EVENT , (void *)callback_ptr, user_data);
35 if (ret != BLUETOOTH_ERROR_NONE &&
36 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
37 BT_ERR("Fail to init the event handler");
41 _bt_set_user_data(BT_HID, (void *)callback_ptr, user_data);
43 return BLUETOOTH_ERROR_NONE;
46 BT_EXPORT_API int bluetooth_hid_deinit(void)
50 ret = _bt_unregister_event(BT_HID_EVENT);
52 if (ret != BLUETOOTH_ERROR_NONE) {
53 BT_ERR("Fail to deinit the event handler");
57 _bt_set_user_data(BT_HID, NULL, NULL);
59 return BLUETOOTH_ERROR_NONE;
62 BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
65 bt_user_info_t *user_info;
67 BT_CHECK_PARAMETER(device_address, return);
68 BT_CHECK_ENABLED(return);
71 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
73 user_info = _bt_get_user_data(BT_HID);
74 retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
76 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
78 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_CONNECT,
79 in_param1, in_param2, in_param3, in_param4,
80 user_info->cb, user_info->user_data);
82 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
87 BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
90 bt_user_info_t *user_info;
92 BT_CHECK_PARAMETER(device_address, return);
93 BT_CHECK_ENABLED(return);
96 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
98 user_info = _bt_get_user_data(BT_HID);
99 retv_if(user_info == NULL, BLUETOOTH_ERROR_INTERNAL);
101 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
103 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_DISCONNECT,
104 in_param1, in_param2, in_param3, in_param4,
105 user_info->cb, user_info->user_data);
107 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);