From: DoHyun Pyun Date: Mon, 29 Aug 2016 05:35:25 +0000 (+0900) Subject: HID: Add API to send customized event X-Git-Tag: accepted/tizen/common/20160901.143334~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ed378ba475948656bb3f3b7645ab12a28075f0b5;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git HID: Add API to send customized event Change-Id: Ic3353185e7d73eca14a0d886370eb03bb59c4cc3 Signed-off-by: DoHyun Pyun --- diff --git a/bt-api/bt-hid-device.c b/bt-api/bt-hid-device.c index a1c03aa..d58edbd 100644 --- a/bt-api/bt-hid-device.c +++ b/bt-api/bt-hid-device.c @@ -760,17 +760,22 @@ BT_EXPORT_API int bluetooth_hid_device_send_key_event(const char *remote_addr, return written; } -BT_EXPORT_API int bluetooth_hid_device_send_rc_key_event(const char *remote_addr, - hid_send_rc_key_event_t send_event) +BT_EXPORT_API int bluetooth_hid_device_send_custom_event(const char *remote_addr, + unsigned char btcode, unsigned char report_id, + const char *data, unsigned int data_len) { int result; int written = 0; int socket_fd; hid_connected_device_info_t *info = NULL; + char *send_event = NULL; + + BT_CHECK_PARAMETER(remote_addr, return); + BT_CHECK_PARAMETER(data, return); switch (privilege_token_send_key) { case 0: - result = _bt_check_privilege(BT_BLUEZ_SERVICE, BT_HID_DEVICE_SEND_KEY_EVENT); + result = _bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DEVICE_SEND_CUSTOM_EVENT); if (result == BLUETOOTH_ERROR_NONE) { privilege_token_send_key = 1; /* Have a permission */ @@ -803,7 +808,18 @@ BT_EXPORT_API int bluetooth_hid_device_send_rc_key_event(const char *remote_addr else socket_fd = info->ctrl_fd; - written = write(socket_fd, &send_event, sizeof(send_event)); + send_event = (char*)g_malloc0(data_len + 2); + if (send_event == NULL) + return BLUETOOTH_ERROR_OUT_OF_MEMORY; + + send_event[0] = (char)btcode; + send_event[1] = (char)report_id; + memcpy(send_event + 2, data, data_len); + + written = write(socket_fd, send_event, data_len + 2); + + g_free(send_event); + return written; } diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index 7cbcc14..64041a7 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -2639,6 +2639,7 @@ gboolean __bt_service_check_privilege(int function_name, case BT_HID_DEVICE_SEND_MOUSE_EVENT: case BT_HID_DEVICE_SEND_KEY_EVENT: case BT_HID_DEVICE_SEND_REPLY_TO_REPORT: + case BT_HID_DEVICE_SEND_CUSTOM_EVENT: case BT_CONNECT_LE: case BT_DISCONNECT_LE: diff --git a/include/bluetooth-hid-api.h b/include/bluetooth-hid-api.h index abd7733..917d9f5 100644 --- a/include/bluetooth-hid-api.h +++ b/include/bluetooth-hid-api.h @@ -59,12 +59,6 @@ typedef struct { unsigned char key[8]; } hid_send_key_event_t; -typedef struct { - unsigned char btcode; - unsigned char rep_id; - unsigned short key[3]; -} hid_send_rc_key_event_t; - typedef void (*hid_cb_func_ptr)(int, hid_event_param_t *, void *); typedef struct { @@ -292,8 +286,9 @@ int bluetooth_hid_device_send_key_event(const char *remote_addr, hid_send_key_event_t send_event); /** - * @fn int bluetooth_hid_device_send_rc_key_event( - * const char *remote_addr, hid_send_rc_key_event_t send_event) + * @fn int bluetooth_hid_device_send_custom_event(const char *remote_addr, + * unsigned char btcode, unsigned char report_id, + * const char *data, unsigned int data_len) * * @brief write the event data on the socket. * @@ -307,11 +302,16 @@ int bluetooth_hid_device_send_key_event(const char *remote_addr, * * @exception None * @param[in] remote_addr device address of remote device. - * @param[in] send_event This indicates the event data to send to remote device. + * @param[in] btcode The btcode + * @param[in] report_id The report id + * @param[in] data This indicates the event data to send to remote device. + * @param[in] data_len The length of the data * @remark None */ -int bluetooth_hid_device_send_rc_key_event(const char *remote_addr, - hid_send_rc_key_event_t send_event); +int bluetooth_hid_device_send_custom_event(const char *remote_addr, + unsigned char btcode, unsigned char report_id, + const char *data, unsigned int data_len); + /** * @fn int bluetooth_hid_device_reply_to_report(const char *remote_addr, * bt_hid_header_type_t htype, diff --git a/include/bt-internal-types.h b/include/bt-internal-types.h index a6ab959..c5f2b0d 100644 --- a/include/bt-internal-types.h +++ b/include/bt-internal-types.h @@ -211,6 +211,7 @@ typedef enum { BT_HID_DEVICE_DISCONNECT, BT_HID_DEVICE_SEND_MOUSE_EVENT, BT_HID_DEVICE_SEND_KEY_EVENT, + BT_HID_DEVICE_SEND_CUSTOM_EVENT, BT_HID_DEVICE_SEND_REPLY_TO_REPORT, BT_HID_ENABLE_BARCODE_FEATURE, BT_NETWORK_ACTIVATE = BT_FUNC_NETWORK_BASE,