1 /* 2 * Copyright (c) 2021 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_NAPI_DATA_ABILITY_HELPER_H 17 #define OHOS_ABILITY_RUNTIME_NAPI_DATA_ABILITY_HELPER_H 18 19 #include "data_ability_helper_common.h" 20 #include "data_ability_observer_stub.h" 21 #include "feature_ability_common.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 26 /** 27 * @brief DataAbilityHelper NAPI module registration. 28 * 29 * @param env The environment that the Node-API call is invoked under. 30 * @param exports An empty object via the exports parameter as a convenience. 31 * 32 * @return The return value from Init is treated as the exports object for the module. 33 */ 34 napi_value DataAbilityHelperInit(napi_env env, napi_value exports); 35 napi_value DataAbilityHelperConstructor(napi_env env, napi_callback_info info); 36 37 /** 38 * @brief DataAbilityHelper NAPI method : insert. 39 * 40 * @param env The environment that the Node-API call is invoked under. 41 * @param info The callback info passed into the callback function. 42 * 43 * @return The return value from NAPI C++ to JS for the module. 44 */ 45 napi_value NAPI_Insert(napi_env env, napi_callback_info info); 46 47 /** 48 * @brief Insert processing function. 49 * 50 * @param env The environment that the Node-API call is invoked under. 51 * @param insertCB Process data asynchronously. 52 * 53 * @return Return JS data successfully, otherwise return nullptr. 54 */ 55 napi_value InsertWrap(napi_env env, napi_callback_info info, DAHelperInsertCB *insertCB); 56 57 /** 58 * @brief DataAbilityHelper NAPI method : notifyChange. 59 * 60 * @param env The environment that the Node-API call is invoked under. 61 * @param info The callback info passed into the callback function. 62 * 63 * @return The return value from NAPI C++ to JS for the module. 64 */ 65 napi_value NAPI_NotifyChange(napi_env env, napi_callback_info info); 66 67 /** 68 * @brief NotifyChange processing function. 69 * 70 * @param env The environment that the Node-API call is invoked under. 71 * @param notifyChangeCB Process data asynchronously. 72 * 73 * @return Return JS data successfully, otherwise return nullptr. 74 */ 75 napi_value NotifyChangeWrap(napi_env env, napi_callback_info info, DAHelperNotifyChangeCB *notifyChangeCB); 76 77 /** 78 * @brief DataAbilityHelper NAPI method : on. 79 * 80 * @param env The environment that the Node-API call is invoked under. 81 * @param info The callback info passed into the callback function. 82 * 83 * @return The return value from NAPI C++ to JS for the module. 84 */ 85 napi_value NAPI_Register(napi_env env, napi_callback_info info); 86 87 /** 88 * @brief On processing function. 89 * 90 * @param env The environment that the Node-API call is invoked under. 91 * @param onCB Process data asynchronously. 92 * 93 * @return Return JS data successfully, otherwise return nullptr. 94 */ 95 napi_value RegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB *onCB); 96 97 /** 98 * @brief On Async. 99 * 100 * @param env The environment that the Node-API call is invoked under. 101 * @param args Indicates the arguments passed into the callback. 102 * @param argcPromise Asynchronous data processing. 103 * @param onCB Process data asynchronously. 104 * 105 * @return Return JS data successfully, otherwise return nullptr. 106 */ 107 napi_value RegisterAsync( 108 napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, DAHelperOnOffCB *onCB); 109 110 /** 111 * @brief On asynchronous processing function. 112 * 113 * @param env The environment that the Node-API call is invoked under. 114 * @param data Point to asynchronous processing of data. 115 */ 116 void RegisterExecuteCB(napi_env env, void *data); 117 void RegisterCompleteCB(napi_env env, napi_status status, void *data); 118 119 /** 120 * @brief DataAbilityHelper NAPI method : off. 121 * 122 * @param env The environment that the Node-API call is invoked under. 123 * @param info The callback info passed into the callback function. 124 * 125 * @return The return value from NAPI C++ to JS for the module. 126 */ 127 napi_value NAPI_UnRegister(napi_env env, napi_callback_info info); 128 129 /** 130 * @brief Off processing function. 131 * 132 * @param env The environment that the Node-API call is invoked under. 133 * @param offCB Process data asynchronously. 134 * 135 * @return Return JS data successfully, otherwise return nullptr. 136 */ 137 napi_value UnRegisterWrap(napi_env env, napi_callback_info info, DAHelperOnOffCB *offCB); 138 139 /** 140 * @brief Off Async. 141 * 142 * @param env The environment that the Node-API call is invoked under. 143 * @param offCB Process data asynchronously. 144 * 145 * @return Return JS data successfully, otherwise return nullptr. 146 */ 147 napi_value UnRegisterSync(napi_env env, DAHelperOnOffCB *offCB); 148 149 /** 150 * @brief Off asynchronous processing function. 151 * 152 * @param env The environment that the Node-API call is invoked under. 153 * @param data Point to asynchronous processing of data. 154 */ 155 void UnRegisterExecuteCB(napi_env env, void *data); 156 void UnRegisterCompleteCB(napi_env env, napi_status status, void *data); 157 void FindRegisterObs(napi_env env, DAHelperOnOffCB *data); 158 /** 159 * @brief Parse the ValuesBucket parameters. 160 * 161 * @param param Indicates the want parameters saved the parse result. 162 * @param env The environment that the Node-API call is invoked under. 163 * @param args Indicates the arguments passed into the callback. 164 * 165 * @return The return value from NAPI C++ to JS for the module. 166 */ 167 napi_value UnwrapValuesBucket(std::string &value, napi_env env, napi_value args); 168 169 napi_value NAPI_GetType(napi_env env, napi_callback_info info); 170 napi_value GetTypeWrap(napi_env env, napi_callback_info info, DAHelperGetTypeCB *gettypeCB); 171 172 napi_value NAPI_GetFileTypes(napi_env env, napi_callback_info info); 173 napi_value GetFileTypesWrap(napi_env env, napi_callback_info info, DAHelperGetFileTypesCB *getfiletypesCB); 174 175 napi_value NAPI_NormalizeUri(napi_env env, napi_callback_info info); 176 napi_value NormalizeUriWrap(napi_env env, napi_callback_info info, DAHelperNormalizeUriCB *normalizeuriCB); 177 178 napi_value NAPI_DenormalizeUri(napi_env env, napi_callback_info info); 179 napi_value DenormalizeUriWrap(napi_env env, napi_callback_info info, DAHelperDenormalizeUriCB *denormalizeuriCB); 180 181 napi_value NAPI_Delete(napi_env env, napi_callback_info info); 182 183 napi_value DeleteWrap(napi_env env, napi_callback_info info, DAHelperDeleteCB *deleteCB); 184 185 napi_value NAPI_Update(napi_env env, napi_callback_info info); 186 187 napi_value UpdateWrap(napi_env env, napi_callback_info info, DAHelperUpdateCB *updateCB); 188 189 napi_value NAPI_Call(napi_env env, napi_callback_info info); 190 191 napi_value NAPI_OpenFile(napi_env env, napi_callback_info info); 192 193 napi_value OpenFileWrap(napi_env env, napi_callback_info info, DAHelperOpenFileCB *openFileCB); 194 195 napi_value NAPI_BatchInsert(napi_env env, napi_callback_info info); 196 197 napi_value BatchInsertWrap(napi_env env, napi_callback_info info, DAHelperBatchInsertCB *batchInsertCB); 198 std::vector<NativeRdb::ValuesBucket> NapiValueObject(napi_env env, napi_value param); 199 200 bool UnwrapArrayObjectFromJS(napi_env env, napi_value param, std::vector<NativeRdb::ValuesBucket> &value); 201 202 napi_value NAPI_Query(napi_env env, napi_callback_info info); 203 204 napi_value QueryWrap(napi_env env, napi_callback_info info, DAHelperQueryCB *queryCB); 205 206 void AnalysisValuesBucket(NativeRdb::ValuesBucket &valuesBucket, const napi_env &env, const napi_value &arg); 207 void SetValuesBucketObject( 208 NativeRdb::ValuesBucket &valuesBucket, const napi_env &env, std::string keyStr, napi_value value); 209 210 void UnwrapDataAbilityPredicates(NativeRdb::DataAbilityPredicates &predicates, napi_env env, napi_value value); 211 212 /** 213 * @brief DataAbilityHelper NAPI method : executeBatch. 214 * 215 * @param env The environment that the Node-API call is invoked under. 216 * @param info The callback info passed into the callback function. 217 * 218 * @return The return value from NAPI C++ to JS for the module. 219 */ 220 napi_value NAPI_ExecuteBatch(napi_env env, napi_callback_info info); 221 222 /** 223 * @brief ExecuteBatch processing function. 224 * 225 * @param env The environment that the Node-API call is invoked under. 226 * @param executeBatchCB Process data asynchronously. 227 * 228 * @return Return JS data successfully, otherwise return nullptr. 229 */ 230 napi_value ExecuteBatchWrap(napi_env env, napi_callback_info info, DAHelperExecuteBatchCB *executeBatchCB); 231 232 bool UnwrapArrayOperationFromJS( 233 napi_env env, napi_value param, std::vector<std::shared_ptr<DataAbilityOperation>> &result); 234 235 void DeleteDAHelperOnOffCB(DAHelperOnOffCB *onCB); 236 bool NeedErase(std::vector<DAHelperOnOffCB*>::iterator& iter, 237 const std::shared_ptr<DataAbilityHelper>&& dataAbilityHelper); 238 void EraseMemberProperties(DAHelperOnOffCB* onCB); 239 } // namespace AppExecFwk 240 } // namespace OHOS 241 #endif /* OHOS_ABILITY_RUNTIME_NAPI_DATA_ABILITY_HELPER_H */ 242