Add remote_input_key_event_cb() API 22/272722/2
authorInHong Han <inhong1.han@samsung.com>
Fri, 18 Mar 2022 05:02:38 +0000 (14:02 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 23 Mar 2022 06:56:17 +0000 (15:56 +0900)
Change-Id: I9fcbe4618c72798a7329aa87f35e369156da05b2
(cherry picked from commit 27255f3ca2182f319ac42f545a109d8594f800af)

remote_input/include/remote_input.h
remote_input/include/remote_input_private.h
remote_input/src/remote_input.cpp
tests/src/remote_input_unittests.cpp

index 82fa3c0..25dc448 100644 (file)
@@ -164,6 +164,18 @@ typedef void (*remote_input_resource_changed_cb)(remote_input_resource_e resourc
 
 /**
  * @platform
+ * @brief Called when a key event is occurred.
+ * @since_tizen 6.5
+ * @remarks This callback will be called after remote_input_focus_in_cb().
+ * @param[in] user_data User data to be passed to the callback function
+ * @pre The callback can be registered using remote_input_key_event_callback_set() function.
+ * @see remote_input_key_event_callback_set()
+ * @see remote_input_key_event_callback_unset()
+ */
+typedef void (*remote_input_key_event_cb)(void *user_data);
+
+/**
+ * @platform
  * @brief Creates a remote input handle.
  * @since_tizen 5.5
  * @privlevel platform
@@ -483,6 +495,74 @@ int remote_input_update_preedit_string(remote_input_h remote_handle, const char
  */
 int remote_input_delete_surrounding_text(remote_input_h remote_handle, int offset, int len);
 
+/**
+ * @platform
+ * @brief Gets the key event type.
+ * @details This function can be called to get the key event type in remote_input_key_event_cb() callback function.
+ * @since_tizen 6.5
+ * @param[in] remote_handle The remote input handle
+ * @param[out] key_type The key event type
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_key_event_cb()
+ */
+int remote_input_get_key_type(remote_input_h remote_handle, remote_input_key_type_e *key_type);
+
+/**
+ * @platform
+ * @brief Gets whether the key is pressed.
+ * @details This function can be called to get the key event type in remote_input_key_event_cb() callback function.
+ * @since_tizen 6.5
+ * @param[in] remote_handle The remote input handle
+ * @param[out] pressed Whether the key is pressed or not
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_key_event_cb()
+ */
+int remote_input_get_key_pressed_state(remote_input_h remote_handle, bool *pressed);
+
+/**
+ * @platform
+ * @brief Gets the timestamp when the event occurred.
+ * @details This function can be called to get the key event type in remote_input_key_event_cb() callback function.
+ * @since_tizen 6.5
+ * @param[in] remote_handle The remote input handle
+ * @param[out] key_type The timestamp
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_key_event_cb()
+ */
+int remote_input_get_key_timestamp(remote_input_h remote_handle, int *timestamp);
+
+/**
+ * @platform
+ * @brief Sets a callback function to be called when the key event is occurred.
+ * @since_tizen 6.5
+ * @param[in] remote_handle The remote input handle
+ * @param[in] callback The callback function to register
+ * @param[in] user_data User data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_key_event_callback_unset()
+ */
+int remote_input_key_event_callback_set(remote_input_h remote_handle, remote_input_key_event_cb callback, void *user_data);
+
+/**
+ * @platform
+ * @brief Unsets the callback function.
+ * @since_tizen 6.5
+ * @param[in] remote_handle The remote input handle
+ * @return 0 on success, otherwise a negative error value
+ * @retval #REMOTE_INPUT_ERROR_NONE Successful
+ * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see remote_input_key_event_callback_set()
+ */
+int remote_input_key_event_callback_unset(remote_input_h remote_handle);
+
 
 /**
  * @}
index 0c369eb..f0fbb00 100644 (file)
@@ -29,12 +29,17 @@ struct remote_input_s {
     Ecore_IMF_Autocapital_Type autocapital_type;
     bool return_key_disabled;
     Ecore_IMF_Input_Panel_Return_Key_Type return_key_type;
+    remote_input_key_type_e key_type;
+    bool key_pressed;
+    int timestamp;
     remote_input_metadata_updated_cb metadata_updated_cb;
     void *metadata_updated_cb_user_data;
     remote_input_text_updated_cb text_updated_cb;
     void *text_updated_cb_user_data;
     remote_input_resource_changed_cb resource_changed_cb;
     void *resource_changed_cb_user_data;
+    remote_input_key_event_cb key_event_cb;
+    void *key_event_cb_user_data;
 };
 
 #endif /* __TIZEN_UIX_REMOTE_INPUT_PRIVATE_H__ */
index a598cb7..593f1ee 100644 (file)
@@ -99,6 +99,24 @@ static void _resource_updated_cb(void *user_data, remote_control_input_resource
                                            remote_handle->resource_changed_cb_user_data);
     }
 }
+
+static void _key_event_cb(void *user_data, remote_control_key_event_s *data)
+{
+    remote_input_h remote_handle = (remote_input_h)user_data;
+
+    if (remote_handle == NULL) {
+        LOGE("remote handle is not available");
+        return;
+    }
+
+    remote_handle->key_type = (remote_input_key_type_e)data->type;
+    remote_handle->key_pressed = data->pressed ? true : false;
+    remote_handle->timestamp = data->timestamp;
+
+    if (remote_handle->key_event_cb) {
+        remote_handle->key_event_cb(remote_handle->key_event_cb_user_data);
+    }
+}
 //LCOV_EXCL_STOP
 
 EXPORT_API int remote_input_create(remote_input_h *remote_handle)
@@ -417,4 +435,68 @@ EXPORT_API int remote_input_delete_surrounding_text(remote_input_h remote_handle
     }
 
     return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_get_key_type(remote_input_h remote_handle, remote_input_key_type_e *key_type)
+{
+    if (!remote_handle || !key_type) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    *key_type = remote_handle->key_type;
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_get_key_pressed_state(remote_input_h remote_handle, bool *pressed)
+{
+    if (!remote_handle || !pressed) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    *pressed = remote_handle->key_pressed;
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_get_key_timestamp(remote_input_h remote_handle, int *timestamp)
+{
+    if (!remote_handle || !timestamp) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    *timestamp = remote_handle->timestamp;
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_key_event_callback_set(remote_input_h remote_handle, remote_input_key_event_cb callback, void *user_data)
+{
+    if (!remote_handle || !remote_handle->remote_client || !callback) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    remote_control_key_event_callback_set(remote_handle->remote_client, _key_event_cb, (void *)remote_handle);
+    remote_handle->key_event_cb = callback;
+    remote_handle->key_event_cb_user_data = user_data;
+
+    return REMOTE_INPUT_ERROR_NONE;
+}
+
+EXPORT_API int remote_input_key_event_callback_unset(remote_input_h remote_handle)
+{
+    if (!remote_handle || !remote_handle->remote_client) {
+        LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER");
+        return REMOTE_INPUT_ERROR_INVALID_PARAMETER;
+    }
+
+    remote_control_key_event_callback_unset(remote_handle->remote_client);
+    remote_handle->key_event_cb = NULL;
+    remote_handle->key_event_cb_user_data = NULL;
+
+    return REMOTE_INPUT_ERROR_NONE;
 }
\ No newline at end of file
index 2281f31..ad30559 100644 (file)
@@ -130,6 +130,18 @@ TEST_F(RemoteInputTest, utc_remote_input_resource_changed_callback_unset_n)
     EXPECT_EQ(ret, REMOTE_INPUT_ERROR_INVALID_PARAMETER);
 }
 
+TEST_F(RemoteInputTest, utc_remote_input_key_event_callback_set_n)
+{
+    int ret = remote_input_key_event_callback_set(NULL, NULL, NULL);
+    EXPECT_EQ(ret, REMOTE_INPUT_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(RemoteInputTest, utc_remote_input_key_event_callback_unset_n)
+{
+    int ret = remote_input_key_event_callback_unset(NULL);
+    EXPECT_EQ(ret, REMOTE_INPUT_ERROR_INVALID_PARAMETER);
+}
+
 TEST_F(RemoteInputTest, utc_remote_input_get_input_hint_n)
 {
     Ecore_IMF_Input_Hints input_hint;