diff --git a/ability/ability_runtime/child_process/libchild_process.ndk.json b/ability/ability_runtime/child_process/libchild_process.ndk.json index 6f6bdcebf52d519ab862738a444bbdc8ae0a2a04..7dcaf85d2ffaf13aed27138f27d68b2a2413f3b9 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": "17", "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 ca195fdefad29793d3711a5fc3b03084cf25f7d1..69a72e273cb525c3c2fe3466c7a8a0845c0c34ee 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,45 @@ Ability_NativeChildProcess_ErrCode OH_Ability_StartNativeChildProcess( */ NativeChildProcess_Args* OH_Ability_GetCurrentChildProcessArgs(); +/** + * @brief Define 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_INVALID_PARAM} if the param is invalid. + * 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_INVALID_PARAM} if the param is invalid. + * 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