1 /*
2  * Copyright (c) 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 #ifndef OHOS_ABILITY_RUNTIME_NAPI_DATA_ABILITY_HELPER_UTILS_H
17 #define OHOS_ABILITY_RUNTIME_NAPI_DATA_ABILITY_HELPER_UTILS_H
18 
19 #include "data_ability_helper_common.h"
20 #include "feature_ability_common.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 
25 /**
26  * @brief Insert Async.
27  *
28  * @param env The environment that the Node-API call is invoked under.
29  * @param args Indicates the arguments passed into the callback.
30  * @param argcPromise Asynchronous data processing.
31  * @param insertCB Process data asynchronously.
32  *
33  * @return Return JS data successfully, otherwise return nullptr.
34  */
35 napi_value InsertAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperInsertCB *insertCB);
36 
37 /**
38  * @brief Insert Promise.
39  *
40  * @param env The environment that the Node-API call is invoked under.
41  * @param insertCB Process data asynchronously.
42  *
43  * @return Return JS data successfully, otherwise return nullptr.
44  */
45 napi_value InsertPromise(napi_env env, DAHelperInsertCB *insertCB);
46 
47 /**
48  * @brief Insert asynchronous processing function.
49  *
50  * @param env The environment that the Node-API call is invoked under.
51  * @param data Point to asynchronous processing of data.
52  */
53 void InsertExecuteCB(napi_env env, void *data);
54 
55 /**
56  * @brief The callback at the end of the asynchronous callback.
57  *
58  * @param env The environment that the Node-API call is invoked under.
59  * @param data Point to asynchronous processing of data.
60  */
61 void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data);
62 
63 /**
64  * @brief The callback at the end of the Promise callback.
65  *
66  * @param env The environment that the Node-API call is invoked under.
67  * @param data Point to asynchronous processing of data.
68  */
69 void InsertPromiseCompleteCB(napi_env env, napi_status status, void *data);
70 
71 /**
72  * @brief NotifyChange Async.
73  *
74  * @param env The environment that the Node-API call is invoked under.
75  * @param args Indicates the arguments passed into the callback.
76  * @param argcPromise Asynchronous data processing.
77  * @param notifyChangeCB Process data asynchronously.
78  *
79  * @return Return JS data successfully, otherwise return nullptr.
80  */
81 napi_value NotifyChangeAsync(
82     napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, DAHelperNotifyChangeCB *notifyChangeCB);
83 
84 /**
85  * @brief NotifyChange Promise.
86  *
87  * @param env The environment that the Node-API call is invoked under.
88  * @param notifyChangeCB Process data asynchronously.
89  *
90  * @return Return JS data successfully, otherwise return nullptr.
91  */
92 napi_value NotifyChangePromise(napi_env env, DAHelperNotifyChangeCB *notifyChangeCB);
93 
94 /**
95  * @brief NotifyChange asynchronous processing function.
96  *
97  * @param env The environment that the Node-API call is invoked under.
98  * @param data Point to asynchronous processing of data.
99  */
100 void NotifyChangeExecuteCB(napi_env env, void *data);
101 
102 /**
103  * @brief The callback at the end of the asynchronous callback.
104  *
105  * @param env The environment that the Node-API call is invoked under.
106  * @param data Point to asynchronous processing of data.
107  */
108 void NotifyChangeAsyncCompleteCB(napi_env env, napi_status status, void *data);
109 
110 /**
111  * @brief The callback at the end of the Promise callback.
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 NotifyChangePromiseCompleteCB(napi_env env, napi_status status, void *data);
117 
118 napi_value GetTypeAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperGetTypeCB *gettypeCB);
119 napi_value GetTypePromise(napi_env env, DAHelperGetTypeCB *gettypeCB);
120 void GetTypeExecuteCB(napi_env env, void *data);
121 void GetTypeAsyncCompleteCB(napi_env env, napi_status status, void *data);
122 void GetTypePromiseCompleteCB(napi_env env, napi_status status, void *data);
123 
124 napi_value GetFileTypesAsync(
125     napi_env env, napi_value *args, const size_t argCallback, DAHelperGetFileTypesCB *getfiletypesCB);
126 napi_value GetFileTypesPromise(napi_env env, DAHelperGetFileTypesCB *getfiletypesCB);
127 void GetFileTypesExecuteCB(napi_env env, void *data);
128 void GetFileTypesAsyncCompleteCB(napi_env env, napi_status status, void *data);
129 void GetFileTypesPromiseCompleteCB(napi_env env, napi_status status, void *data);
130 napi_value WrapGetFileTypesCB(napi_env env, const DAHelperGetFileTypesCB &getfiletypesCB);
131 
132 napi_value NormalizeUriAsync(
133     napi_env env, napi_value *args, const size_t argCallback, DAHelperNormalizeUriCB *normalizeuriCB);
134 napi_value NormalizeUriPromise(napi_env env, DAHelperNormalizeUriCB *normalizeuriCB);
135 void NormalizeUriExecuteCB(napi_env env, void *data);
136 void NormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data);
137 void NormalizeUriPromiseCompleteCB(napi_env env, napi_status status, void *data);
138 
139 napi_value DenormalizeUriAsync(
140     napi_env env, napi_value *args, const size_t argCallback, DAHelperDenormalizeUriCB *denormalizeuriCB);
141 napi_value DenormalizeUriPromise(napi_env env, DAHelperDenormalizeUriCB *denormalizeuriCB);
142 void DenormalizeUriExecuteCB(napi_env env, void *data);
143 void DenormalizeUriAsyncCompleteCB(napi_env env, napi_status status, void *data);
144 void DenormalizeUriPromiseCompleteCB(napi_env env, napi_status status, void *data);
145 
146 napi_value DeleteAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperDeleteCB *deleteCB);
147 napi_value DeletePromise(napi_env env, DAHelperDeleteCB *deleteCB);
148 void DeleteExecuteCB(napi_env env, void *data);
149 void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data);
150 void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data);
151 
152 napi_value UpdateAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperUpdateCB *updateCB);
153 napi_value UpdatePromise(napi_env env, DAHelperUpdateCB *updateCB);
154 void UpdateExecuteCB(napi_env env, void *data);
155 void UpdateAsyncCompleteCB(napi_env env, napi_status status, void *data);
156 void UpdatePromiseCompleteCB(napi_env env, napi_status status, void *data);
157 
158 napi_value CallErrorWrap(napi_env env, napi_value thisVar, napi_callback_info info, napi_value *args, bool isPromise);
159 napi_value CallAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperCallCB *callCB);
160 napi_value CallPromise(napi_env env, DAHelperCallCB *callCB);
161 
162 napi_value OpenFileAsync(napi_env env, napi_value *args, const size_t argCallback, DAHelperOpenFileCB *openFileCB);
163 napi_value OpenFilePromise(napi_env env, DAHelperOpenFileCB *openFileCB);
164 void OpenFileExecuteCB(napi_env env, void *data);
165 void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data);
166 void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data);
167 
168 napi_value BatchInsertAsync(
169     napi_env env, napi_value *args, const size_t argCallback, DAHelperBatchInsertCB *batchInsertCB);
170 napi_value BatchInsertPromise(napi_env env, DAHelperBatchInsertCB *batchInsertCB);
171 void BatchInsertExecuteCB(napi_env env, void *data);
172 void BatchInsertAsyncCompleteCB(napi_env env, napi_status status, void *data);
173 void BatchInsertPromiseCompleteCB(napi_env env, napi_status status, void *data);
174 
175 napi_value QuerySync(napi_env env, napi_value *args, const size_t argCallback, DAHelperQueryCB *queryCB);
176 napi_value QueryPromise(napi_env env, DAHelperQueryCB *queryCB);
177 napi_value WrapResultSet(napi_env env, const std::shared_ptr<NativeRdb::AbsSharedResultSet> &resultSet);
178 
179 /**
180  * @brief ExecuteBatch Async.
181  *
182  * @param env The environment that the Node-API call is invoked under.
183  * @param args Indicates the arguments passed into the callback.
184  * @param argcPromise Asynchronous data processing.
185  * @param executeBatchCB Process data asynchronously.
186  *
187  * @return Return JS data successfully, otherwise return nullptr.
188  */
189 napi_value ExecuteBatchAsync(
190     napi_env env, napi_value *args, size_t argcAsync, const size_t argcPromise, DAHelperExecuteBatchCB *executeBatchCB);
191 
192 /**
193  * @brief ExecuteBatch Promise.
194  *
195  * @param env The environment that the Node-API call is invoked under.
196  * @param executeBatchCB Process data asynchronously.
197  *
198  * @return Return JS data successfully, otherwise return nullptr.
199  */
200 napi_value ExecuteBatchPromise(napi_env env, DAHelperExecuteBatchCB *executeBatchCB);
201 
202 /**
203  * @brief ExecuteBatch asynchronous processing function.
204  *
205  * @param env The environment that the Node-API call is invoked under.
206  * @param data Point to asynchronous processing of data.
207  */
208 void ExecuteBatchExecuteCB(napi_env env, void *data);
209 
210 /**
211  * @brief The callback at the end of the asynchronous callback.
212  *
213  * @param env The environment that the Node-API call is invoked under.
214  * @param data Point to asynchronous processing of data.
215  */
216 void ExecuteBatchAsyncCompleteCB(napi_env env, napi_status status, void *data);
217 
218 /**
219  * @brief The callback at the end of the Promise callback.
220  *
221  * @param env The environment that the Node-API call is invoked under.
222  * @param data Point to asynchronous processing of data.
223  */
224 void ExecuteBatchPromiseCompleteCB(napi_env env, napi_status status, void *data);
225 
226 void GetDataAbilityResultForResult(
227     napi_env env, const std::vector<std::shared_ptr<DataAbilityResult>> &dataAbilityResult, napi_value result);
228 
229 void GetDataAbilityHelper(napi_env env, napi_value thisVar, std::shared_ptr<DataAbilityHelper>& dataAbilityHelper);
230 }  // namespace AppExecFwk
231 }  // namespace OHOS
232 #endif /* OHOS_ABILITY_RUNTIME_NAPI_DATA_ABILITY_HELPER_UTILS_H */