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