OSDN Git Service

android: Add support for registering and unregistering hid service
authorSzymon Janc <szymon.janc@tieto.com>
Wed, 23 Oct 2013 11:04:41 +0000 (13:04 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Wed, 23 Oct 2013 11:26:40 +0000 (14:26 +0300)
android/hid.c
android/hid.h
android/main.c

index 31de20d..2c74352 100644 (file)
  */
 
 #include <stdint.h>
+#include <stdbool.h>
 
 #include <glib.h>
 
+#include "lib/bluetooth.h"
 #include "log.h"
 #include "hal-msg.h"
 #include "ipc.h"
 #include "hid.h"
 
+static GIOChannel *notification_io = NULL;
+
 void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 {
        uint8_t status = HAL_ERROR_FAILED;
@@ -46,3 +50,20 @@ void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len)
 
        ipc_send_error(io, HAL_SERVICE_ID_HIDHOST, status);
 }
+
+bool bt_hid_register(GIOChannel *io, const bdaddr_t *addr)
+{
+       DBG("");
+
+       notification_io = g_io_channel_ref(io);
+
+       return true;
+}
+
+void bt_hid_unregister(void)
+{
+       DBG("");
+
+       g_io_channel_unref(notification_io);
+       notification_io = NULL;
+}
index 1247488..674b35a 100644 (file)
@@ -22,3 +22,6 @@
  */
 
 void bt_hid_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len);
+
+bool bt_hid_register(GIOChannel *io, const bdaddr_t *addr);
+void bt_hid_unregister(void);
index e8b584d..edcca73 100644 (file)
@@ -88,6 +88,11 @@ static void service_register(void *buf, uint16_t len)
                        goto error;
 
                break;
+       case HAL_SERVICE_ID_HIDHOST:
+               if (!bt_hid_register(hal_notif_io, bt_adapter_get_address()))
+                       goto error;
+
+               break;
        default:
                DBG("service %u not supported", m->service_id);
                goto error;
@@ -118,6 +123,9 @@ static void service_unregister(void *buf, uint16_t len)
        case HAL_SERVICE_ID_SOCK:
                bt_socket_unregister();
                break;
+       case HAL_SERVICE_ID_HIDHOST:
+               bt_hid_unregister();
+               break;
        default:
                /* This would indicate bug in HAL, as unregister should not be
                 * called in init failed */