1/* 2 * Copyright (c) 2021-2023 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 BasicServicesKit 19 */ 20 21/** 22 * Defines the basic callback. 23 * @typedef Callback 24 * @syscap SystemCapability.Base 25 * @since 6 26 */ 27/** 28 * Defines the basic callback. 29 * @typedef Callback 30 * @syscap SystemCapability.Base 31 * @crossplatform 32 * @since 10 33 */ 34/** 35 * Defines the basic callback. 36 * @typedef Callback 37 * @syscap SystemCapability.Base 38 * @crossplatform 39 * @atomicservice 40 * @since 11 41 */ 42export interface Callback<T> { 43 /** 44 * Defines the callback info. 45 * @param { T } data 46 * @syscap SystemCapability.Base 47 * @since 6 48 */ 49 /** 50 * Defines the callback info. 51 * @param { T } data 52 * @syscap SystemCapability.Base 53 * @crossplatform 54 * @since 10 55 */ 56 /** 57 * Defines the callback info. 58 * @param { T } data 59 * @syscap SystemCapability.Base 60 * @crossplatform 61 * @atomicservice 62 * @since 11 63 */ 64 (data: T): void; 65} 66 67/** 68 * Defines the basic error callback. 69 * @typedef ErrorCallback 70 * @syscap SystemCapability.Base 71 * @since 6 72 */ 73/** 74 * Defines the basic error callback. 75 * @typedef ErrorCallback 76 * @syscap SystemCapability.Base 77 * @crossplatform 78 * @since 10 79 */ 80/** 81 * Defines the basic error callback. 82 * @typedef ErrorCallback 83 * @syscap SystemCapability.Base 84 * @crossplatform 85 * @atomicservice 86 * @since 11 87 */ 88export interface ErrorCallback<T extends Error = BusinessError> { 89 /** 90 * Defines the basic error callback. 91 * @param { T } err 92 * @syscap SystemCapability.Base 93 * @since 6 94 */ 95 /** 96 * Defines the basic error callback. 97 * @param { T } err 98 * @syscap SystemCapability.Base 99 * @crossplatform 100 * @since 10 101 */ 102 /** 103 * Defines the basic error callback. 104 * @param { T } err 105 * @syscap SystemCapability.Base 106 * @crossplatform 107 * @atomicservice 108 * @since 11 109 */ 110 (err: T): void; 111} 112 113/** 114 * Defines the basic async callback. 115 * @typedef AsyncCallback 116 * @syscap SystemCapability.Base 117 * @since 6 118 */ 119/** 120 * Defines the basic async callback. 121 * @typedef AsyncCallback 122 * @syscap SystemCapability.Base 123 * @crossplatform 124 * @since 10 125 */ 126/** 127 * Defines the basic async callback. 128 * @typedef AsyncCallback 129 * @syscap SystemCapability.Base 130 * @crossplatform 131 * @atomicservice 132 * @since 11 133 */ 134export interface AsyncCallback<T, E = void> { 135 /** 136 * Defines the callback data. 137 * @param { BusinessError<E> } err 138 * @param { T } data 139 * @syscap SystemCapability.Base 140 * @since 6 141 */ 142 /** 143 * Defines the callback data. 144 * @param { BusinessError<E> } err 145 * @param { T } data 146 * @syscap SystemCapability.Base 147 * @crossplatform 148 * @since 10 149 */ 150 /** 151 * Defines the callback data. 152 * @param { BusinessError<E> } err 153 * @param { T } data 154 * @syscap SystemCapability.Base 155 * @crossplatform 156 * @atomicservice 157 * @since 11 158 */ 159 (err: BusinessError<E>, data: T): void; 160} 161 162/** 163 * Defines the error interface. 164 * @typedef BusinessError 165 * @syscap SystemCapability.Base 166 * @since 6 167 */ 168/** 169 * Defines the error interface. 170 * @typedef BusinessError 171 * @syscap SystemCapability.Base 172 * @crossplatform 173 * @since 10 174 */ 175/** 176 * Defines the error interface. 177 * @typedef BusinessError 178 * @syscap SystemCapability.Base 179 * @crossplatform 180 * @atomicservice 181 * @since 11 182 */ 183export interface BusinessError<T = void> extends Error { 184 /** 185 * Defines the basic error code. 186 * @type { number } code 187 * @syscap SystemCapability.Base 188 * @since 6 189 */ 190 /** 191 * Defines the basic error code. 192 * @type { number } code 193 * @syscap SystemCapability.Base 194 * @crossplatform 195 * @since 10 196 */ 197 /** 198 * Defines the basic error code. 199 * @type { number } code 200 * @syscap SystemCapability.Base 201 * @crossplatform 202 * @atomicservice 203 * @since 11 204 */ 205 code: number; 206 /** 207 * Defines the additional information for business 208 * @type { ?T } data 209 * @syscap SystemCapability.Base 210 * @since 9 211 */ 212 /** 213 * Defines the additional information for business 214 * @type { ?T } data 215 * @syscap SystemCapability.Base 216 * @crossplatform 217 * @since 10 218 */ 219 /** 220 * Defines the additional information for business 221 * @type { ?T } data 222 * @syscap SystemCapability.Base 223 * @crossplatform 224 * @atomicservice 225 * @since 11 226 */ 227 data?: T; 228} 229