diff --git a/ability/ability_runtime/child_process/libchild_process.ndk.json b/ability/ability_runtime/child_process/libchild_process.ndk.json index d812f5a08bc7ac6471ed7a2a96290acdc0faec5e..78f2cc74c29d7c90b8c82a43d6b11eb0744b66a6 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 2837104000d588409635bf594b085559ed1da42c..767262df3721f203f50defc908ac9e49e300e3b1 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