4 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
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.
27 #include "bt-hal-log.h"
28 #include "bt-hal-msg.h"
29 #include "bt-hal-utils.h"
31 #include "bt-hal-hid-dbus-handler.h"
32 #include "bt-hal-event-receiver.h"
34 static const bthd_callbacks_t *bt_hal_hid_device_cbacks;
36 static bool interface_ready(void)
38 return bt_hal_hid_device_cbacks != NULL;
41 static void __bt_hal_handle_conn_state(void *buf, uint16_t len)
43 struct hal_ev_hiddevice_conn_state *ev = buf;
45 if (bt_hal_hid_device_cbacks->connection_state_cb)
46 bt_hal_hid_device_cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
50 static void __bt_hal_handle_hid_device_events(int message, void *buf, uint16_t len)
54 if (!interface_ready())
58 case HAL_EV_HIDDEVICE_CONN_STATE:
59 DBG("Event: HAL_EV_HIDDEVICE_CONN_STATE");
60 __bt_hal_handle_conn_state(buf, len);
63 DBG("Event Currently not handled!!");
70 static bt_status_t init(bthd_callbacks_t *callbacks)
74 if (interface_ready())
75 return BT_STATUS_DONE;
77 bt_hal_hid_device_cbacks = callbacks;
78 DBG("Register HID events callback function");
79 _bt_hal_register_event_handler_cb(HAL_HIDDEVICE, __bt_hal_handle_hid_device_events);
81 return BT_STATUS_SUCCESS;
84 static void cleanup(void)
88 if (!interface_ready())
91 _bt_hal_unregister_hid_dbus_handler_cb();
92 _bt_hal_unregister_event_handler_cb(HAL_HIDDEVICE);
94 bt_hal_hid_device_cbacks = NULL;
97 static bthd_interface_t hiddevice_if = {
98 .size = sizeof(hiddevice_if),
103 bthd_interface_t *bt_get_hiddevice_interface(void)
105 return &hiddevice_if;