Add API for asynchronous Remote Input connection 49/323549/2
authorInhong Han <inhong1.han@samsung.com>
Tue, 29 Apr 2025 02:45:25 +0000 (11:45 +0900)
committerInhong Han <inhong1.han@samsung.com>
Wed, 30 Apr 2025 06:14:41 +0000 (15:14 +0900)
Change-Id: If10d7fae8e9c7a9443cf141ff8468c2062345b5a

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 d2048a5330d71745978667fff4957c4609f2ccbd..6be6eb15466b5241ef65d1ea385d142b2335baa3 100644 (file)
@@ -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);
 
 /**
  * @}
index a5fcfd1f45ad98156c1dadb906473aaf53c7c0d6..7460a8c21457d338e96538c936fc3c1eb9deb86c 100644 (file)
@@ -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__ */
index 1de2d741c77b64e4df6196f91eac089669a1b525..7392562169180a4aae827971cea9e3eaf77543fe 100644 (file)
@@ -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
index eaae42fdab668ffc2e59758fbe2509570fbde27f..23ce6ec8c514969e26384b9f5d532741d0844cb3 100644 (file)
@@ -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