From: Inhong Han Date: Tue, 29 Apr 2025 02:45:25 +0000 (+0900) Subject: Add API for asynchronous Remote Input connection X-Git-Tag: accepted/tizen/unified/20250508.083749~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=974dd13abf8e4b82a4274e70d14df53ba87ade53;p=platform%2Fcore%2Fapi%2Finputmethod.git Add API for asynchronous Remote Input connection Change-Id: If10d7fae8e9c7a9443cf141ff8468c2062345b5a --- diff --git a/remote_input/include/remote_input.h b/remote_input/include/remote_input.h index d2048a5..6be6eb1 100644 --- a/remote_input/include/remote_input.h +++ b/remote_input/include/remote_input.h @@ -85,6 +85,17 @@ typedef enum { REMOTE_INPUT_RESOURCE_REMOTE, /**< Input event from remote input API */ } remote_input_resource_e; +/** + * @platform + * @brief Enumeration for connection status. + * @since_tizen 10.0 + * @see remote_input_connection_status_changed_cb() + */ +typedef enum { + REMOTE_INPUT_CONNECTION_STATUS_CONNECTED = 0, /**< Connected */ + REMOTE_INPUT_CONNECTION_STATUS_REJECTED, /**< Rejected */ +} remote_input_connection_status_e; + /** * @platform * @brief Handle of the remote input. @@ -187,6 +198,18 @@ typedef void (*remote_input_key_event_cb)(void *user_data); */ typedef void (*remote_input_cursor_position_updated_cb)(int cursor_pos, void *user_data); +/** + * @platform + * @brief Called when the connection status is changed. + * @since_tizen 10.0 + * @param[in] remote_handle The remote input handle + * @param[in] status The connection status + * @param[in] user_data User data to be passed to the callback function + * @pre The callback can be registered using remote_input_async_create() function. + * @see remote_input_async_create() + */ +typedef void (*remote_input_connection_status_changed_cb)(remote_input_h remote_handle, remote_input_connection_status_e status, void *user_data); + /** * @platform * @brief Creates a remote input handle. @@ -617,6 +640,19 @@ int remote_input_cursor_position_updated_callback_set(remote_input_h remote_hand */ int remote_input_cursor_position_updated_callback_unset(remote_input_h remote_handle); +/** + * @platform + * @brief Sets a callback function to handle asynchronous creation of a remote input handle. + * @since_tizen 10.0 + * @param[in] callback A callback function to receive the remote control client asynchronously + * @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_PERMISSION_DENIED Permission denied + * @retval #REMOTE_INPUT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #REMOTE_INPUT_ERROR_OUT_OF_MEMORY Out of memory + */ +int remote_input_async_create(remote_input_connection_status_changed_cb callback, void *user_data); /** * @} diff --git a/remote_input/include/remote_input_private.h b/remote_input/include/remote_input_private.h index a5fcfd1..7460a8c 100644 --- a/remote_input/include/remote_input_private.h +++ b/remote_input/include/remote_input_private.h @@ -42,6 +42,8 @@ struct remote_input_s { void *key_event_cb_user_data; remote_input_cursor_position_updated_cb cursor_position_updated_cb; void *cursor_position_updated_cb_user_data; + remote_input_connection_status_changed_cb connection_status_changed_cb; + void *connection_status_changed_cb_user_data; }; #endif /* __TIZEN_UIX_REMOTE_INPUT_PRIVATE_H__ */ diff --git a/remote_input/src/remote_input.cpp b/remote_input/src/remote_input.cpp index 1de2d74..7392562 100644 --- a/remote_input/src/remote_input.cpp +++ b/remote_input/src/remote_input.cpp @@ -131,6 +131,28 @@ static void _cursor_position_updated_cb(void *user_data, int cursor_pos) remote_handle->cursor_position_updated_cb(cursor_pos, remote_handle->text_updated_cb_user_data); } } + +static void _async_create_cb(void *user_data, remote_control_client *client, remote_control_connection_status_e status) +{ + remote_input_h remote_handle = (remote_input_h)user_data; + + if (remote_handle == NULL) { + LOGE("remote handle is not available"); + return; + } + + remote_handle->remote_client = client; + + if (remote_handle->connection_status_changed_cb) { + remote_handle->connection_status_changed_cb(status == REMOTE_CONTROL_CONNECTION_STATUS_CONNECTED ? remote_handle : NULL, + (remote_input_connection_status_e)status, remote_handle->connection_status_changed_cb_user_data); + } + + if (status == REMOTE_CONTROL_CONNECTION_STATUS_REJECTED) { + free(remote_handle); + remote_handle = NULL; + } +} //LCOV_EXCL_STOP EXPORT_API int remote_input_create(remote_input_h *remote_handle) @@ -556,4 +578,33 @@ EXPORT_API int remote_input_cursor_position_updated_callback_unset(remote_input_ remote_handle->cursor_position_updated_cb_user_data = NULL; return REMOTE_INPUT_ERROR_NONE; +} + +EXPORT_API int remote_input_async_create(remote_input_connection_status_changed_cb callback, void *user_data) +{ + remote_input_error_e ret = REMOTE_INPUT_ERROR_NONE; + + if (!callback) { + LOGE("REMOTE_INPUT_ERROR_INVALID_PARAMETER"); + return REMOTE_INPUT_ERROR_INVALID_PARAMETER; + } + + ret = _remote_check_privilege(); + if (ret != REMOTE_INPUT_ERROR_NONE) { + LOGE("REMOTE_INPUT_ERROR_PERMISSION_DENIED"); + return ret; + } + + struct remote_input_s *remote_input = (remote_input_h)calloc(1, sizeof(struct remote_input_s)); + if (!remote_input) { + LOGE("REMOTE_INPUT_ERROR_OUT_OF_MEMORY"); + return REMOTE_INPUT_ERROR_OUT_OF_MEMORY; + } + + remote_input_h remote_handle = (remote_input_h)remote_input; + remote_control_async_connect(_async_create_cb, (void *)remote_handle); + remote_handle->connection_status_changed_cb = callback; + remote_handle->connection_status_changed_cb_user_data = user_data; + + return ret; } \ No newline at end of file diff --git a/tests/src/remote_input_unittests.cpp b/tests/src/remote_input_unittests.cpp index eaae42f..23ce6ec 100644 --- a/tests/src/remote_input_unittests.cpp +++ b/tests/src/remote_input_unittests.cpp @@ -245,5 +245,11 @@ TEST_F(RemoteInputTest, remote_input_cursor_position_updated_callback_unset_n) EXPECT_EQ(ret, REMOTE_INPUT_ERROR_INVALID_PARAMETER); } +TEST_F(RemoteInputTest, remote_input_async_create_n) +{ + int ret = remote_input_async_create(NULL, NULL); + EXPECT_EQ(ret, REMOTE_INPUT_ERROR_INVALID_PARAMETER); +} + } // namespace //LCOV_EXCL_STOP