161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"),
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit AbilityKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport type { AsyncCallback } from './@ohos.base';
2261847f8eSopenharmony_ciimport type { ChildProcessArgs } from './@ohos.app.ability.ChildProcessArgs';
2361847f8eSopenharmony_ciimport type { ChildProcessOptions } from './@ohos.app.ability.ChildProcessOptions';
2461847f8eSopenharmony_ci
2561847f8eSopenharmony_ci/**
2661847f8eSopenharmony_ci * This module provides the capability to start and manage child process.
2761847f8eSopenharmony_ci *
2861847f8eSopenharmony_ci * @namespace childProcessManager
2961847f8eSopenharmony_ci * @syscap SystemCapability.Ability.AbilityRuntime.Core
3061847f8eSopenharmony_ci * @since 11
3161847f8eSopenharmony_ci */
3261847f8eSopenharmony_cideclare namespace childProcessManager {
3361847f8eSopenharmony_ci
3461847f8eSopenharmony_ci  /**
3561847f8eSopenharmony_ci   * Enum for the process start mode.
3661847f8eSopenharmony_ci   * 
3761847f8eSopenharmony_ci   * @enum { number }
3861847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
3961847f8eSopenharmony_ci   * @stagemodelonly
4061847f8eSopenharmony_ci   * @since 11
4161847f8eSopenharmony_ci   */
4261847f8eSopenharmony_ci  export const enum StartMode {
4361847f8eSopenharmony_ci
4461847f8eSopenharmony_ci    /**
4561847f8eSopenharmony_ci     * Fork child process by application self.
4661847f8eSopenharmony_ci     * Binder IPC can not be used in child process in this mode, may cause crash.
4761847f8eSopenharmony_ci     *
4861847f8eSopenharmony_ci     * @syscap SystemCapability.Ability.AbilityRuntime.Core
4961847f8eSopenharmony_ci     * @stagemodelonly
5061847f8eSopenharmony_ci     * @since 11
5161847f8eSopenharmony_ci     */
5261847f8eSopenharmony_ci    SELF_FORK = 0,
5361847f8eSopenharmony_ci
5461847f8eSopenharmony_ci    /**
5561847f8eSopenharmony_ci     * Fork child process by app spawn.
5661847f8eSopenharmony_ci     *
5761847f8eSopenharmony_ci     * @syscap SystemCapability.Ability.AbilityRuntime.Core
5861847f8eSopenharmony_ci     * @stagemodelonly
5961847f8eSopenharmony_ci     * @since 11
6061847f8eSopenharmony_ci     */
6161847f8eSopenharmony_ci    APP_SPAWN_FORK = 1,
6261847f8eSopenharmony_ci  }
6361847f8eSopenharmony_ci
6461847f8eSopenharmony_ci  /**
6561847f8eSopenharmony_ci   * Start child process with the given src entry and start mode.
6661847f8eSopenharmony_ci   *
6761847f8eSopenharmony_ci   * @param { string } srcEntry - Child process source file entrance to be started.
6861847f8eSopenharmony_ci   * @param { StartMode } startMode - Child process start mode.
6961847f8eSopenharmony_ci   * @returns { Promise<number> } Returns the started child process pid.
7061847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes:
7161847f8eSopenharmony_ci   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
7261847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
7361847f8eSopenharmony_ci   * @throws { BusinessError } 16000061 - Operation not supported.
7461847f8eSopenharmony_ci   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
7561847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
7661847f8eSopenharmony_ci   * @stagemodelonly
7761847f8eSopenharmony_ci   * @since 11
7861847f8eSopenharmony_ci   */
7961847f8eSopenharmony_ci  function startChildProcess(srcEntry: string, startMode: StartMode): Promise<number>;
8061847f8eSopenharmony_ci
8161847f8eSopenharmony_ci  /**
8261847f8eSopenharmony_ci   * Start child process with the given src entry and mode.
8361847f8eSopenharmony_ci   *
8461847f8eSopenharmony_ci   * @param { string } srcEntry - Child process source file entrance to be started.
8561847f8eSopenharmony_ci   * @param { StartMode } startMode - Child process start mode.
8661847f8eSopenharmony_ci   * @param { AsyncCallback<number> } callback - The callback of startChildProcess.
8761847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes:
8861847f8eSopenharmony_ci   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
8961847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
9061847f8eSopenharmony_ci   * @throws { BusinessError } 16000061 - Operation not supported.
9161847f8eSopenharmony_ci   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
9261847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
9361847f8eSopenharmony_ci   * @stagemodelonly
9461847f8eSopenharmony_ci   * @since 11
9561847f8eSopenharmony_ci   */
9661847f8eSopenharmony_ci  function startChildProcess(srcEntry: string, startMode: StartMode, callback: AsyncCallback<number>): void;
9761847f8eSopenharmony_ci
9861847f8eSopenharmony_ci  /** 
9961847f8eSopenharmony_ci   * Start child process with the given args and options.
10061847f8eSopenharmony_ci   *
10161847f8eSopenharmony_ci   * @param { string } srcEntry - Indicates child process source file entrance to be started.
10261847f8eSopenharmony_ci   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
10361847f8eSopenharmony_ci   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
10461847f8eSopenharmony_ci   * @returns { Promise<number> } Returns the started child process pid.
10561847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes:
10661847f8eSopenharmony_ci   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
10761847f8eSopenharmony_ci   * @throws { BusinessError } 801 - Capability not supported.
10861847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
10961847f8eSopenharmony_ci   * @throws { BusinessError } 16000061 - Operation not supported. The API cannot be called in a child process.
11061847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
11161847f8eSopenharmony_ci   * @stagemodelonly
11261847f8eSopenharmony_ci   * @since 12
11361847f8eSopenharmony_ci   */
11461847f8eSopenharmony_ci  /** 
11561847f8eSopenharmony_ci   * Start child process with the given args and options.
11661847f8eSopenharmony_ci   *
11761847f8eSopenharmony_ci   * @param { string } srcEntry - Indicates child process source file entrance to be started.
11861847f8eSopenharmony_ci   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
11961847f8eSopenharmony_ci   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
12061847f8eSopenharmony_ci   * @returns { Promise<number> } Returns the started child process pid.
12161847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes:
12261847f8eSopenharmony_ci   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
12361847f8eSopenharmony_ci   * @throws { BusinessError } 801 - Capability not supported.
12461847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
12561847f8eSopenharmony_ci   * @throws { BusinessError } 16000061 - Operation not supported. The API cannot be called in a child process.
12661847f8eSopenharmony_ci   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
12761847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
12861847f8eSopenharmony_ci   * @stagemodelonly
12961847f8eSopenharmony_ci   * @since 13
13061847f8eSopenharmony_ci   */
13161847f8eSopenharmony_ci  function startArkChildProcess(srcEntry: string, args: ChildProcessArgs, options?: ChildProcessOptions): Promise<number>;
13261847f8eSopenharmony_ci
13361847f8eSopenharmony_ci  /** 
13461847f8eSopenharmony_ci   * Start native child process with the given args and options.
13561847f8eSopenharmony_ci   *
13661847f8eSopenharmony_ci   * @param { string } entryPoint - Indicates entry point of child process, consisting of library and entry function, such as "libEntry.so:Main".
13761847f8eSopenharmony_ci   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
13861847f8eSopenharmony_ci   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
13961847f8eSopenharmony_ci   * @returns { Promise<number> } Returns the started child process pid.
14061847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes:
14161847f8eSopenharmony_ci   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
14261847f8eSopenharmony_ci   * @throws { BusinessError } 801 - Capability not supported. Failed to call the API due to limited device capabilities.
14361847f8eSopenharmony_ci   * @throws { BusinessError } 16000050 - Internal error.
14461847f8eSopenharmony_ci   * @throws { BusinessError } 16000061 - Operation not supported. The API cannot be called in a child process.
14561847f8eSopenharmony_ci   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
14661847f8eSopenharmony_ci   * @syscap SystemCapability.Ability.AbilityRuntime.Core
14761847f8eSopenharmony_ci   * @stagemodelonly
14861847f8eSopenharmony_ci   * @since 13
14961847f8eSopenharmony_ci   */
15061847f8eSopenharmony_ci  function startNativeChildProcess(entryPoint: string, args: ChildProcessArgs, options?: ChildProcessOptions): Promise<number>;
15161847f8eSopenharmony_ci
15261847f8eSopenharmony_ci}
15361847f8eSopenharmony_ci
15461847f8eSopenharmony_ciexport default childProcessManager;