• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License"),
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 * @file
18 * @kit AbilityKit
19 */
20
21import type { AsyncCallback } from './@ohos.base';
22import type { ChildProcessArgs } from './@ohos.app.ability.ChildProcessArgs';
23import type { ChildProcessOptions } from './@ohos.app.ability.ChildProcessOptions';
24
25/**
26 * This module provides the capability to start and manage child process.
27 *
28 * @namespace childProcessManager
29 * @syscap SystemCapability.Ability.AbilityRuntime.Core
30 * @since 11
31 */
32declare namespace childProcessManager {
33
34  /**
35   * Enum for the process start mode.
36   *
37   * @enum { number }
38   * @syscap SystemCapability.Ability.AbilityRuntime.Core
39   * @stagemodelonly
40   * @since 11
41   */
42  export const enum StartMode {
43
44    /**
45     * Fork child process by application self.
46     * Binder IPC can not be used in child process in this mode, may cause crash.
47     *
48     * @syscap SystemCapability.Ability.AbilityRuntime.Core
49     * @stagemodelonly
50     * @since 11
51     */
52    SELF_FORK = 0,
53
54    /**
55     * Fork child process by app spawn.
56     *
57     * @syscap SystemCapability.Ability.AbilityRuntime.Core
58     * @stagemodelonly
59     * @since 11
60     */
61    APP_SPAWN_FORK = 1,
62  }
63
64  /**
65   * Start child process with the given src entry and start mode.
66   *
67   * @param { string } srcEntry - Child process source file entrance to be started.
68   * @param { StartMode } startMode - Child process start mode.
69   * @returns { Promise<number> } Returns the started child process pid.
70   * @throws { BusinessError } 401 - Parameter error. Possible causes:
71   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
72   * @throws { BusinessError } 16000050 - Internal error.
73   * @throws { BusinessError } 16000061 - Operation not supported.
74   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
75   * @syscap SystemCapability.Ability.AbilityRuntime.Core
76   * @stagemodelonly
77   * @since 11
78   */
79  function startChildProcess(srcEntry: string, startMode: StartMode): Promise<number>;
80
81  /**
82   * Start child process with the given src entry and mode.
83   *
84   * @param { string } srcEntry - Child process source file entrance to be started.
85   * @param { StartMode } startMode - Child process start mode.
86   * @param { AsyncCallback<number> } callback - The callback of startChildProcess.
87   * @throws { BusinessError } 401 - Parameter error. Possible causes:
88   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
89   * @throws { BusinessError } 16000050 - Internal error.
90   * @throws { BusinessError } 16000061 - Operation not supported.
91   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
92   * @syscap SystemCapability.Ability.AbilityRuntime.Core
93   * @stagemodelonly
94   * @since 11
95   */
96  function startChildProcess(srcEntry: string, startMode: StartMode, callback: AsyncCallback<number>): void;
97
98  /**
99   * Start child process with the given args and options.
100   *
101   * @param { string } srcEntry - Indicates child process source file entrance to be started.
102   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
103   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
104   * @returns { Promise<number> } Returns the started child process pid.
105   * @throws { BusinessError } 401 - Parameter error. Possible causes:
106   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
107   * @throws { BusinessError } 801 - Capability not supported.
108   * @throws { BusinessError } 16000050 - Internal error.
109   * @throws { BusinessError } 16000061 - Operation not supported.
110   * @syscap SystemCapability.Ability.AbilityRuntime.Core
111   * @stagemodelonly
112   * @since 12
113   */
114  /**
115   * Start child process with the given args and options.
116   *
117   * @param { string } srcEntry - Indicates child process source file entrance to be started.
118   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
119   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
120   * @returns { Promise<number> } Returns the started child process pid.
121   * @throws { BusinessError } 401 - Parameter error. Possible causes:
122   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
123   * @throws { BusinessError } 801 - Capability not supported.
124   * @throws { BusinessError } 16000050 - Internal error.
125   * @throws { BusinessError } 16000061 - Operation not supported.
126   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
127   * @syscap SystemCapability.Ability.AbilityRuntime.Core
128   * @stagemodelonly
129   * @since 13
130   */
131  function startArkChildProcess(srcEntry: string, args: ChildProcessArgs, options?: ChildProcessOptions): Promise<number>;
132
133  /**
134   * Start native child process with the given args and options.
135   *
136   * @param { string } entryPoint - Indicates entry point of child process, consisting of library and entry function, such as "libEntry.so:Main".
137   * @param { ChildProcessArgs } args - Indicates args to pass to child process.
138   * @param { ChildProcessOptions } [options] - Indicates options for starting child process.
139   * @returns { Promise<number> } Returns the started child process pid.
140   * @throws { BusinessError } 401 - Parameter error. Possible causes:
141   *         1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed.
142   * @throws { BusinessError } 801 - Capability not supported. Failed to call the API due to limited device capabilities.
143   * @throws { BusinessError } 16000050 - Internal error.
144   * @throws { BusinessError } 16000061 - Operation not supported.
145   * @throws { BusinessError } 16000062 - The number of child processes exceeds the upper limit.
146   * @syscap SystemCapability.Ability.AbilityRuntime.Core
147   * @stagemodelonly
148   * @since 13
149   */
150  function startNativeChildProcess(entryPoint: string, args: ChildProcessArgs, options?: ChildProcessOptions): Promise<number>;
151
152}
153
154export default childProcessManager;