1 /*
2  * Copyright (c) 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 HUKS_NAPI_UPDATE_FINISH_SESSION_H
17 #define HUKS_NAPI_UPDATE_FINISH_SESSION_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 #include "hks_type.h"
22 
23 namespace HuksNapiItem {
24 struct UpdateAsyncContextT {
25     napi_async_work asyncWork = nullptr;
26     napi_deferred deferred = nullptr;
27     napi_ref callback = nullptr;
28 
29     int32_t result = 0;
30     struct HksBlob *handle = nullptr;
31     struct HksParamSet *paramSet = nullptr;
32     struct HksBlob *inData = nullptr;
33     struct HksBlob *outData = nullptr;
34     struct HksBlob *token = nullptr;
35     bool isUpdate = false;
36 };
37 using UpdateAsyncContext = UpdateAsyncContextT *;
38 
39 UpdateAsyncContext CreateUpdateAsyncContext();
40 
41 int32_t FillContextInDataAndOutBlob(napi_env env, napi_value *argv, UpdateAsyncContext context, size_t index);
42 
43 int32_t GetTokenOrCallback(napi_env env, napi_value *argv, UpdateAsyncContext context,
44     size_t index, size_t maxIndex);
45 
46 void DeleteUpdateAsyncContext(napi_env env, UpdateAsyncContext &context);
47 
48 napi_value UpdateFinishAsyncWork(napi_env env, UpdateAsyncContext &context);
49 
50 napi_value HuksNapiUpdateSession(napi_env env, napi_callback_info info);
51 
52 napi_value HuksNapiFinishSession(napi_env env, napi_callback_info info);
53 }  // namespace HuksNapiItem
54 
55 #endif  // HUKS_NAPI_UPDATE_FINISH_SESSION_H