1/* 2 * Copyright (c) 2021-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 { BusinessError } from '../@ohos.base'; 22 23/** 24 * The event center of a context, support the subscription and publication of events. 25 * 26 * @syscap SystemCapability.Ability.AbilityRuntime.Core 27 * @StageModelOnly 28 * @since 9 29 */ 30/** 31 * The event center of a context, support the subscription and publication of events. 32 * 33 * @syscap SystemCapability.Ability.AbilityRuntime.Core 34 * @StageModelOnly 35 * @atomicservice 36 * @since 11 37 */ 38/** 39 * The event center of a context, support the subscription and publication of events. 40 * 41 * @syscap SystemCapability.Ability.AbilityRuntime.Core 42 * @stagemodelonly 43 * @crossplatform 44 * @atomicservice 45 * @since 12 46 */ 47export default class EventHub { 48 /** 49 * Subscribe to an event. 50 * 51 * @param { string } event - Indicates the event. 52 * @param { Function } callback - Indicates the callback. 53 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 54 * 2. Incorrect parameter types; 3. Parameter verification failed. 55 * @syscap SystemCapability.Ability.AbilityRuntime.Core 56 * @StageModelOnly 57 * @since 9 58 */ 59 /** 60 * Subscribe to an event. 61 * 62 * @param { string } event - Indicates the event. 63 * @param { Function } callback - Indicates the callback. 64 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 65 * 2. Incorrect parameter types; 3. Parameter verification failed. 66 * @syscap SystemCapability.Ability.AbilityRuntime.Core 67 * @StageModelOnly 68 * @atomicservice 69 * @since 11 70 */ 71 /** 72 * Subscribe to an event. 73 * 74 * @param { string } event - Indicates the event. 75 * @param { Function } callback - Indicates the callback. 76 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 77 * 2. Incorrect parameter types; 3. Parameter verification failed. 78 * @syscap SystemCapability.Ability.AbilityRuntime.Core 79 * @stagemodelonly 80 * @crossplatform 81 * @atomicservice 82 * @since 12 83 */ 84 on(event: string, callback: Function): void; 85 86 /** 87 * Unsubscribe from an event. 88 * 89 * @param { string } event - Indicates the event. 90 * @param { Function } [callback] - Indicates the callback. 91 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 92 * 2. Incorrect parameter types; 3. Parameter verification failed. 93 * @syscap SystemCapability.Ability.AbilityRuntime.Core 94 * @StageModelOnly 95 * @since 9 96 */ 97 /** 98 * Unsubscribe from an event. 99 * 100 * @param { string } event - Indicates the event. 101 * @param { Function } [callback] - Indicates the callback. 102 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 103 * 2. Incorrect parameter types; 3. Parameter verification failed. 104 * @syscap SystemCapability.Ability.AbilityRuntime.Core 105 * @StageModelOnly 106 * @atomicservice 107 * @since 11 108 */ 109 /** 110 * Unsubscribe from an event. 111 * 112 * @param { string } event - Indicates the event. 113 * @param { Function } [callback] - Indicates the callback. 114 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 115 * 2. Incorrect parameter types; 3. Parameter verification failed. 116 * @syscap SystemCapability.Ability.AbilityRuntime.Core 117 * @stagemodelonly 118 * @crossplatform 119 * @atomicservice 120 * @since 12 121 */ 122 off(event: string, callback?: Function): void; 123 124 /** 125 * Trigger the event callbacks. 126 * 127 * @param { string } event - Indicates the event. 128 * @param { Object[] } args - Indicates the callback arguments. 129 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 130 * 2. Incorrect parameter types; 3. Parameter verification failed. 131 * @syscap SystemCapability.Ability.AbilityRuntime.Core 132 * @StageModelOnly 133 * @since 9 134 */ 135 /** 136 * Trigger the event callbacks. 137 * 138 * @param { string } event - Indicates the event. 139 * @param { Object[] } args - Indicates the callback arguments. 140 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 141 * 2. Incorrect parameter types; 3. Parameter verification failed. 142 * @syscap SystemCapability.Ability.AbilityRuntime.Core 143 * @StageModelOnly 144 * @atomicservice 145 * @since 11 146 */ 147 /** 148 * Trigger the event callbacks. 149 * 150 * @param { string } event - Indicates the event. 151 * @param { Object[] } args - Indicates the callback arguments. 152 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 153 * 2. Incorrect parameter types; 3. Parameter verification failed. 154 * @syscap SystemCapability.Ability.AbilityRuntime.Core 155 * @stagemodelonly 156 * @crossplatform 157 * @atomicservice 158 * @since 12 159 */ 160 emit(event: string, ...args: Object[]): void; 161} 162