From 7768406ea62f001cd3845ca65febbcb9d6a42fdb Mon Sep 17 00:00:00 2001 From: jsjzju Date: Tue, 1 Apr 2025 17:46:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9B=91=E5=90=ACnative?= =?UTF-8?q?=E5=AD=90=E8=BF=9B=E7=A8=8B=E9=80=80=E5=87=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: I73b1c0b37826968954f2fbf44400af911f87ee70 --- .../child_process/libchild_process.ndk.json | 8 ++++ .../child_process/native_child_process.h | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/ability/ability_runtime/child_process/libchild_process.ndk.json b/ability/ability_runtime/child_process/libchild_process.ndk.json index d812f5a08..78f2cc74c 100644 --- a/ability/ability_runtime/child_process/libchild_process.ndk.json +++ b/ability/ability_runtime/child_process/libchild_process.ndk.json @@ -10,5 +10,13 @@ { "first_introduced": "16", "name": "OH_Ability_GetCurrentChildProcessArgs" + }, + { + "first_introduced": "20", + "name": "OH_Ability_RegisterNativeChildProcessExitCallback" + }, + { + "first_introduced": "20", + "name": "OH_Ability_UnregisterNativeChildProcessExitCallback" } ] \ No newline at end of file diff --git a/ability/ability_runtime/child_process/native_child_process.h b/ability/ability_runtime/child_process/native_child_process.h index 283710400..767262df3 100644 --- a/ability/ability_runtime/child_process/native_child_process.h +++ b/ability/ability_runtime/child_process/native_child_process.h @@ -111,6 +111,12 @@ typedef enum Ability_NativeChildProcess_ErrCode { * An invalid IPC object pointer may be returned. */ NCP_ERR_CONNECTION_FAILED = 16010008, + + /** + * @error The callback does not exist; it may not have been registered or has already been unregistered. + * @since 20 + */ + NCP_ERR_CALLBACK_NOT_EXIST = 16010009, } Ability_NativeChildProcess_ErrCode; @@ -288,6 +294,43 @@ Ability_NativeChildProcess_ErrCode OH_Ability_StartNativeChildProcess( */ NativeChildProcess_Args* OH_Ability_GetCurrentChildProcessArgs(); +/** + * @brief Defines a callback function to handle the exit of a native child process. + * + * @param pid The pid of the exited native child process. + * @param signal The signal of the exited native child process. + * @since 20 + */ +typedef void (*OH_Ability_OnNativeChildProcessExit)(int32_t pid, int32_t signal); + +/** + * @brief Register a native child process exit callback. + * Registering the same callback repeatedly will only keep one. + * + * @param onProcessExit Pointer to the callback function to handle the exit of a native child process. + * For details, see {@link OH_Ability_OnNativeChildProcessExit}. + * @return Returns {@link NCP_NO_ERROR} if the call is successful. + * Returns {@link NCP_ERR_INTERNAL} if internal error occurs. + * For details, see {@link Ability_NativeChildProcess_ErrCode}. + * @since 20 + */ +Ability_NativeChildProcess_ErrCode OH_Ability_RegisterNativeChildProcessExitCallback( + OH_Ability_OnNativeChildProcessExit onProcessExit); + +/** + * @brief Unregister a native child process exit callback. + * + * @param onProcessExit Pointer to the callback function to handle the exit of a native child process. + * For details, see {@link OH_Ability_OnNativeChildProcessExit}. + * @return Returns {@link NCP_NO_ERROR} if the call is successful. + * Returns {@link NCP_ERR_INTERNAL} if internal error occurs. + * Returns {@link NCP_ERR_CALLBACK_NOT_EXIST} if the callback is not exist. + * For details, see {@link Ability_NativeChildProcess_ErrCode}. + * @since 20 + */ +Ability_NativeChildProcess_ErrCode OH_Ability_UnregisterNativeChildProcessExitCallback( + OH_Ability_OnNativeChildProcessExit onProcessExit); + #ifdef __cplusplus } // extern "C" #endif -- Gitee