Skip to main content

OH_Ability_CreateNativeChildProcessWithConfigs

Function OH_Ability_CreateNativeChildProcessWithConfigs 

Source
pub unsafe extern "C" fn OH_Ability_CreateNativeChildProcessWithConfigs(
    libName: *const c_char,
    configs: *mut Ability_ChildProcessConfigs,
    onProcessStarted: OH_Ability_OnNativeChildProcessStarted,
) -> Ability_NativeChildProcessResult
Available on crate features api-12 and api-20 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:

  1. OHIPCRemoteStub* NativeChildProcess_OnConnect()
  2. void NativeChildProcess_MainProc()

The processing logic sequence is shown in the following pseudocode: Main process:

  1. OH_Ability_CreateNativeChildProcessWithConfigs(libName, configs, onProcessStartedCallback) Child process:
  2. dlopen(libName)
  3. dlsym(“NativeChildProcess_OnConnect”)
  4. dlsym(“NativeChildProcess_MainProc”)
  5. ipcRemote = NativeChildProcess_OnConnect()
  6. NativeChildProcess_MainProc() Main process:
  7. onProcessStartedCallback(ipcRemote, errCode) Child process:
  8. 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.

  • configs - Pointer to the child process configs object. 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, see OH_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: 20