pub unsafe extern "C" fn OH_Ability_CreateNativeChildProcess(
libName: *const c_char,
onProcessStarted: OH_Ability_OnNativeChildProcessStarted,
) -> c_intapi-12 only.Expand description
Creates a child process, loads the specified dynamic library file, and returns the startup result asynchronously through a callback parameter. The callback notification is an independent thread. When implementing the callback function, pay attention to thread synchronization and do not perform time-consuming operations to avoid long-time blocking.
The dynamic library specified must implement and export the following functions:
-
OHIPCRemoteStub* NativeChildProcess_OnConnect()
-
void NativeChildProcess_MainProc()
The processing logic sequence is shown in the following pseudocode:
Main process:
- OH_Ability_CreateNativeChildProcess(libName, onProcessStartedCallback)
Child process:
-
dlopen(libName)
-
dlsym(“NativeChildProcess_OnConnect”)
-
dlsym(“NativeChildProcess_MainProc”)
-
ipcRemote = NativeChildProcess_OnConnect()
-
NativeChildProcess_MainProc()
Main process:
- onProcessStartedCallback(ipcRemote, errCode)
Child process:
- The child process exits after the NativeChildProcess_MainProc() function is returned.
§Arguments
-
libName- Name of the dynamic library file loaded in the child process. The value cannot be nullptr. -
onProcessStarted- Pointer to the callback function for notifying the child process startup result. The value cannot be nullptr. For details, seeOH_Ability_OnNativeChildProcessStarted.
§Returns
- Returns [
NCP_NO_ERROR] if the call is successful, but the actual startup result is notified by the callback function.
Returns [NCP_ERR_INVALID_PARAM] if the dynamic library name or callback function pointer is invalid.
Returns [NCP_ERR_NOT_SUPPORTED] if the device does not support the creation of native child processes.
Returns [NCP_ERR_MULTI_PROCESS_DISABLED] if the multi-process mode is disabled on the device.
Returns [NCP_ERR_ALREADY_IN_CHILD] if it is not allowed to create another child process in the child process.
Returns [NCP_ERR_MAX_CHILD_PROCESSES_REACHED] if the maximum number of native child processes is reached.
For details, see [Ability_NativeChildProcess_ErrCode].
OH_Ability_OnNativeChildProcessStarted
Available since API-level: 12