From 6010489cb922dc4ada71e68b28c024e5c06f0aa7 Mon Sep 17 00:00:00 2001 From: shilei Date: Tue, 12 Mar 2024 12:48:02 +0000 Subject: [PATCH] add interface Signed-off-by: shilei Change-Id: Ia0bc64c3312859261d47d4b05bb13776df453481 --- arkui/napi/common.h | 20 ++++++++++++++++++++ arkui/napi/libnapi.ndk.json | 7 +++++++ arkui/napi/native_api.h | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/arkui/napi/common.h b/arkui/napi/common.h index 8b7df91a6..031e2c327 100644 --- a/arkui/napi/common.h +++ b/arkui/napi/common.h @@ -23,4 +23,24 @@ typedef enum { napi_qos_user_initiated = 3, } napi_qos_t; +/** + * @brief Indicates the running mode of the native event loop in an asynchronous native thread. + * + * @since 12 + */ +typedef enum { + /** + * In this mode, the current asynchronous thread will be blocked and events of native event loop will + * be processed. + */ + napi_event_mode_default = 0, + + /** + * In this mode, the current asynchronous thread will not be blocked. If there are events in the event loop, + * only one event will be processed and then the event loop will stop. If there are no events in the loop, + * the event loop will stop immediately. + */ + napi_event_mode_nowait = 1, +} napi_event_mode; + #endif /* FOUNDATION_ACE_NAPI_INTERFACES_KITS_NAPI_NATIVE_API_H */ \ No newline at end of file diff --git a/arkui/napi/libnapi.ndk.json b/arkui/napi/libnapi.ndk.json index d9d055527..09c34e420 100644 --- a/arkui/napi/libnapi.ndk.json +++ b/arkui/napi/libnapi.ndk.json @@ -162,5 +162,12 @@ { "first_introduced": "12", "name": "napi_destroy_ark_runtime" + }, + { + "name": "napi_run_event_loop" + }, + { + "first_introduced": "12", + "name": "napi_stop_event_loop" } ] diff --git a/arkui/napi/native_api.h b/arkui/napi/native_api.h index 6aa257d18..74664957c 100644 --- a/arkui/napi/native_api.h +++ b/arkui/napi/native_api.h @@ -143,6 +143,29 @@ NAPI_EXTERN napi_status napi_create_ark_runtime(napi_env* env); */ NAPI_EXTERN napi_status napi_destroy_ark_runtime(napi_env* env); +/** + * @brief Run the event loop by the given env and running mode in current thread. + * + * Support to run the native event loop in an asynchronous native thread with the specified running mode. + * + * @param env Current running virtual machine context. + * @param mode Indicates the running mode of the native event loop. + * @return Return the function execution status. + * @since 12 + */ +NAPI_EXTERN napi_status napi_run_event_loop(napi_env env, napi_event_mode mode); + +/** + * @brief Stop the event loop in current thread. + * + * Support to stop the running event loop in current native thread. + * + * @param env Current running virtual machine context. + * @return Return the function execution status. + * @since 12 + */ +NAPI_EXTERN napi_status napi_stop_event_loop(napi_env env); + #ifdef __cplusplus } #endif -- Gitee