1 /* 2 * Copyright (c) 2021-2022 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 #ifndef OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_H 17 #define OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_H 18 #include "feature_ability_common.h" 19 using Want = OHOS::AAFwk::Want; 20 21 namespace OHOS { 22 namespace AppExecFwk { 23 using namespace OHOS::AbilityRuntime; 24 /** 25 * @brief FeatureAbility NAPI module registration. 26 * 27 * @param env The environment that the Node-API call is invoked under. 28 * @param exports An empty object via the exports parameter as a convenience. 29 * 30 * @return The return value from Init is treated as the exports object for the module. 31 */ 32 napi_value FeatureAbilityInit(napi_env env, napi_value exports); 33 34 EXTERN_C_START 35 /** 36 * @brief The interface of onAbilityResult provided for ACE to call back to JS. 37 * 38 * @param requestCode Indicates the request code returned after the ability is started. 39 * @param resultCode Indicates the result code returned after the ability is started. 40 * @param resultData Indicates the data returned after the ability is started. 41 * @param callbackInfo The environment and call back info that the Node-API call is invoked under. 42 * 43 * @return The return value from NAPI C++ to JS for the module. 44 */ 45 void CallOnAbilityResult(int requestCode, int resultCode, const Want &resultData, CallbackInfo callbackInfo); 46 EXTERN_C_END 47 48 /** 49 * @brief FeatureAbility NAPI method : setResult. 50 * 51 * @param env The environment that the Node-API call is invoked under. 52 * @param info The callback info passed into the callback function. 53 * 54 * @return The return value from NAPI C++ to JS for the module. 55 */ 56 napi_value NAPI_SetResult(napi_env env, napi_callback_info info); 57 58 /** 59 * @brief Get want(sync). 60 * 61 * @param env The environment that the Node-API call is invoked under. 62 * @param info The callback info passed into the callback function. 63 * 64 * @return The return value from NAPI C++ to JS for the module. 65 */ 66 napi_value NAPI_GetWantSync(napi_env env, napi_callback_info info); 67 68 /** 69 * @brief Obtains the type of this application. 70 * 71 * @param env The environment that the Node-API call is invoked under. 72 * @param info The callback info passed into the callback function. 73 * 74 * @return The return value from NAPI C++ to JS for the module. 75 */ 76 napi_value NAPI_GetAppType(napi_env env, napi_callback_info info); 77 78 /** 79 * @brief Obtains the class name in this ability name, without the prefixed bundle name. 80 * 81 * @param env The environment that the Node-API call is invoked under. 82 * @param info The callback info passed into the callback function. 83 * 84 * @return The return value from NAPI C++ to JS for the module. 85 */ 86 napi_value NAPI_GetAbilityName(napi_env env, napi_callback_info info); 87 88 /** 89 * @brief Obtains information about the current ability. 90 * 91 * @param env The environment that the Node-API call is invoked under. 92 * @param info The callback info passed into the callback function. 93 * 94 * @return The return value from NAPI C++ to JS for the module. 95 */ 96 napi_value NAPI_GetAbilityInfo(napi_env env, napi_callback_info info); 97 98 /** 99 * @brief FeatureAbility NAPI method : getDataAbilityHelper. 100 * 101 * @param env The environment that the Node-API call is invoked under. 102 * @param info The callback info passed into the callback function. 103 * 104 * @return The return value from NAPI C++ to JS for the module. 105 */ 106 napi_value NAPI_GetDataAbilityHelper(napi_env env, napi_callback_info info); 107 108 /** 109 * @brief FeatureAbility NAPI method : acquireDataAbilityHelper. 110 * 111 * @param env The environment that the Node-API call is invoked under. 112 * @param info The callback info passed into the callback function. 113 * 114 * @return The return value from NAPI C++ to JS for the module. 115 */ 116 napi_value NAPI_AcquireDataAbilityHelper(napi_env env, napi_callback_info info); 117 118 /** 119 * @brief Parse the parameters. 120 * 121 * @param param Indicates the parameters saved the parse result. 122 * @param env The environment that the Node-API call is invoked under. 123 * @param args Indicates the arguments passed into the callback. 124 * 125 * @return The return value from NAPI C++ to JS for the module. 126 */ 127 napi_value UnwrapForResultParam(CallAbilityParam ¶m, napi_env env, napi_value args); 128 129 /** 130 * @brief Parse the abilityResult parameters. 131 * 132 * @param param Indicates the abilityResult parameters saved the parse result. 133 * @param env The environment that the Node-API call is invoked under. 134 * @param args Indicates the arguments passed into the callback. 135 * 136 * @return The return value from NAPI C++ to JS for the module. 137 */ 138 napi_value UnwrapAbilityResult(CallAbilityParam ¶m, napi_env env, napi_value args); 139 140 /** 141 * @brief Create asynchronous data. 142 * 143 * @param env The environment that the Node-API call is invoked under. 144 * 145 * @return Return a pointer to AppInfoCB on success, nullptr on failure. 146 */ 147 AppInfoCB *CreateAppInfoCBInfo(napi_env env); 148 149 /** 150 * @brief SetResult processing function. 151 * 152 * @param env The environment that the Node-API call is invoked under. 153 * @param asyncCallbackInfo Process data asynchronously. 154 * 155 * @return Return JS data successfully, otherwise return nullptr. 156 */ 157 napi_value SetResultWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 158 napi_value SetResultAsync( 159 napi_env env, napi_value *args, const size_t argCallback, AsyncCallbackInfo *asyncCallbackInfo); 160 napi_value SetResultPromise(napi_env env, AsyncCallbackInfo *asyncCallbackInfo); 161 162 /** 163 * @brief ContinueAbility processing function. 164 * 165 * @param env The environment that the Node-API call is invoked under. 166 * @param asyncCallbackInfo Process data asynchronously. 167 * 168 * @return Return JS data successfully, otherwise return nullptr. 169 */ 170 napi_value ContinueAbilityWrap(napi_env env, napi_callback_info info, AsyncCallbackInfo *asyncCallbackInfo); 171 napi_value ContinueAbilityAsync(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); 172 napi_value ContinueAbilityPromise(napi_env env, napi_value *args, AsyncCallbackInfo *asyncCallbackInfo, size_t argc); 173 174 /** 175 * @brief Obtains the HapModuleInfo object of the application. 176 * 177 * @param env The environment that the Node-API call is invoked under. 178 * @param info The callback info passed into the callback function. 179 * 180 * @return The return value from NAPI C++ to JS for the module. 181 */ 182 napi_value NAPI_GetHapModuleInfo(napi_env env, napi_callback_info info); 183 184 /** 185 * @brief getDataAbilityHelper processing function. 186 * 187 * @param env The environment that the Node-API call is invoked under. 188 * @param dataAbilityHelperCB Process data asynchronously. 189 * 190 * @return Return JS data successfully, otherwise return nullptr. 191 */ 192 napi_value GetDataAbilityHelperWrap(napi_env env, napi_callback_info info, DataAbilityHelperCB *dataAbilityHelperCB); 193 194 /** 195 * @brief GetDataAbilityHelper Async. 196 * 197 * @param env The environment that the Node-API call is invoked under. 198 * @param args Indicates the arguments passed into the callback. 199 * @param argcPromise Asynchronous data processing. 200 * @param dataAbilityHelperCB Process data asynchronously. 201 * 202 * @return Return JS data successfully, otherwise return nullptr. 203 */ 204 napi_value GetDataAbilityHelperAsync( 205 napi_env env, napi_value *args, const size_t argCallback, DataAbilityHelperCB *dataAbilityHelperCB); 206 207 /** 208 * @brief GetDataAbilityHelper Promise. 209 * 210 * @param env The environment that the Node-API call is invoked under. 211 * @param dataAbilityHelperCB Process data asynchronously. 212 * 213 * @return Return JS data successfully, otherwise return nullptr. 214 */ 215 napi_value GetDataAbilityHelperPromise(napi_env env, DataAbilityHelperCB *dataAbilityHelperCB); 216 217 /** 218 * @brief The callback at the end of the asynchronous callback. 219 * 220 * @param env The environment that the Node-API call is invoked under. 221 * @param data Point to asynchronous processing of data. 222 */ 223 void GetDataAbilityHelperAsyncCompleteCB(napi_env env, napi_status status, void *data); 224 225 /** 226 * @brief The callback at the end of the Promise callback. 227 * 228 * @param env The environment that the Node-API call is invoked under. 229 * @param data Point to asynchronous processing of data. 230 */ 231 void GetDataAbilityHelperPromiseCompleteCB(napi_env env, napi_status status, void *data); 232 233 /** 234 * @brief FeatureAbility NAPI method : continueAbility. 235 * 236 * @param env The environment that the Node-API call is invoked under. 237 * @param info The callback info passed into the callback function. 238 * 239 * @return The return value from NAPI C++ to JS for the module. 240 */ 241 napi_value NAPI_FAContinueAbility(napi_env env, napi_callback_info info); 242 243 napi_value JsFeatureAbilityInit(napi_env env, napi_value exports); 244 } // namespace AppExecFwk 245 } // namespace OHOS 246 #endif /* OHOS_ABILITY_RUNTIME_FEATURE_ABILITY_H */ 247