HID: Added new API to send RC key events 31/77831/2 accepted/tizen/common/20160704.145416 accepted/tizen/ivi/20160705.003641 accepted/tizen/mobile/20160705.003539 accepted/tizen/tv/20160705.003621 accepted/tizen/wearable/20160705.003600 submit/tizen/20160704.015035
authorAtul Rai <a.rai@samsung.com>
Fri, 1 Jul 2016 08:21:14 +0000 (17:21 +0900)
committerAtul Rai <a.rai@samsung.com>
Mon, 4 Jul 2016 02:55:04 +0000 (11:55 +0900)
This patch adds API to send RC key event to remote device.
It also adds new test case to demonstarte usage of added API.

Change-Id: I24da5cbc58ed48707275dc110afdd5d1c19aa154
Signed-off-by: Atul Rai <a.rai@samsung.com>
include/bluetooth_private.h
src/bluetooth-hid.c
test/bt_unit_test.c
test/bt_unit_test.h

index 1407f6c..689d051 100644 (file)
@@ -369,6 +369,17 @@ typedef enum {
 } bt_authentication_type_info_e;
 
 /**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_HID_DEVICE_MODULE
+ * @brief The structure type containing the HID RC key event information.
+ * @since_tizen 3.0
+ *
+ * @see bt_hid_device_send_rc_key_event()
+ */
+typedef struct {
+        unsigned short key[3]; /**< The key value - currently pressed keys : Max 3 at once */
+} bt_hid_rc_key_data_s;
+
+/**
  * @internal
  * @brief Check the initialzating status
  */
@@ -701,6 +712,28 @@ int bt_passkey_reply(char *passkey, bool authentication_reply);
  */
 int bt_passkey_confirmation_reply(bool confirmation_reply);
 
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE
+ * @brief Sends the RC key event data.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/bluetooth.admin
+ *
+ * @param[in] remote_address device address of remote device.
+ * @param[in] key_data  key data the need to be passed to remote device
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #BT_ERROR_NONE  Successful
+ * @retval #BT_ERROR_NOT_INITIALIZED  Not initialized
+ * @retval #BT_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval #BT_ERROR_OPERATION_FAILED  Operation failed
+ * @retval #BT_ERROR_PERMISSION_DENIED  Permission denied
+ *
+ * @pre The HID connection must be established.
+ * @see bt_hid_device_connection_state_changed_cb()
+ */
+int bt_hid_device_send_rc_key_event(const char *remote_address,
+                               const bt_hid_rc_key_data_s *key_data);
+
 #ifdef __cplusplus
 }
 #endif
index 06a59a5..15eb31f 100644 (file)
@@ -283,9 +283,48 @@ int bt_hid_device_send_key_event(const char *remote_address,
        BT_CHECK_INIT_STATUS();
        BT_CHECK_INPUT_PARAMETER(remote_address);
        BT_CHECK_INPUT_PARAMETER(key_data);
+       hid_send_key_event_t send_event;
 
-       ret = bluetooth_hid_device_send_key_event(remote_address,
-                       *(hid_send_key_event_t *)key_data);
+       send_event.modify = key_data->modifier;
+       memcpy(send_event.key, key_data->key, sizeof(send_event.key));
+
+       ret = bluetooth_hid_device_send_key_event(remote_address, send_event);
+       if (ret <= 0) {
+               if (ret == -1) {
+                       /* write fail case */
+                       if (errno == EACCES || errno == EPERM)
+                               set_last_result(BT_ERROR_PERMISSION_DENIED);
+                       else if (errno == EAGAIN || errno == EWOULDBLOCK)
+                               set_last_result(BT_ERROR_AGAIN);
+                       else
+                               set_last_result(BT_ERROR_OPERATION_FAILED);
+               } else {
+                       ret = _bt_get_error_code(ret);
+                       set_last_result(ret);
+               }
+
+               BT_ERR("Write failed, ret = %d", ret);
+       }
+
+       return ret;
+}
+
+#ifdef TIZEN_WEARABLE
+int bt_hid_device_send_rc_key_event(const char *remote_address,
+               const bt_hid_rc_key_data_s *key_data)
+{
+       int ret;
+       BT_CHECK_HID_DEVICE_SUPPORT();
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(remote_address);
+       BT_CHECK_INPUT_PARAMETER(key_data);
+       hid_send_rc_key_event_t send_event;
+
+       send_event.btcode = 0xA1;
+       send_event.rep_id = 0xF7;
+       memcpy(send_event.key, key_data->key, sizeof(send_event.key));
+
+       ret = bluetooth_hid_device_send_rc_key_event(remote_address, send_event);
        if (ret <= 0) {
                if (ret == -1) {
                        /* write fail case */
@@ -305,6 +344,7 @@ int bt_hid_device_send_key_event(const char *remote_address,
 
        return ret;
 }
+#endif
 
 int bt_hid_device_reply_to_report(const char *remote_address,
                bt_hid_header_type_e header_type,
index 069fa6f..dedb641 100644 (file)
@@ -763,6 +763,10 @@ tc_table_t tc_hid[] = {
                , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT},
        {"bt_hid_device_send_key_event"
                , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT},
+#ifdef TIZEN_WEARABLE
+       {"bt_hid_device_send_rc_key_event"
+               , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT},
+#endif
        {"bt_hid_device_set_data_received_cb"
                , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB},
        {"bt_hid_device_unset_data_received_cd"
@@ -7349,6 +7353,25 @@ int test_input_callback(void *data)
                        TC_PRT("returns %d\n", ret);
                        break;
                }
+#ifdef TIZEN_WEARABLE
+               case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT: {
+                       bt_hid_rc_key_data_s send_data;
+                       /* Will send volume Up */
+                       unsigned short  key_press[3]     = {0x0007, 0x0000, 0x0000};
+                       unsigned short  key_release[3]   = {0x0000, 0x0000, 0x0000};
+
+                       memcpy(send_data.key, key_press, sizeof(key_press));
+                       ret = bt_hid_device_send_rc_key_event(
+                                       remote_addr, &send_data);
+                       TC_PRT("returns %d\n", ret);
+
+                       memcpy(send_data.key, key_release, sizeof(key_release));
+                       ret = bt_hid_device_send_rc_key_event(
+                                       remote_addr, &send_data);
+                       TC_PRT("returns %d\n", ret);
+                       break;
+               }
+#endif
                case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB: {
                        ret = bt_hid_device_set_data_received_cb(
                                        __bt_hid_device_data_received_cb,
index 60fd18b..d83f353 100644 (file)
@@ -321,6 +321,9 @@ typedef enum {
        BT_UNIT_TEST_FUCNTION_HID_DEVICE_DEACTIVATE,
        BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT,
        BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT,
+#ifdef TIZEN_WEARABLE
+       BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_RC_KEY_EVENT,
+#endif
        BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB,
        BT_UNIT_TEST_FUNCTION_HID_DEVICE_UNSET_DATA_RECEIVED_CB,
        BT_UNIT_TEST_FUNCTION_IPSP_REGISTER = 1,