• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef OHOS_APPEXECFWK_LIBZIP_ZLIB_CALLBACK_H
16 #define OHOS_APPEXECFWK_LIBZIP_ZLIB_CALLBACK_H
17 
18 #include <uv.h>
19 
20 #include "appexecfwk_errors.h"
21 #include "base_cb_info.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 #include "napi/native_common.h"
25 #include "nocopyable.h"
26 #include "zip_utils.h"
27 #include "zlib_callback_info_base.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 namespace LIBZIP {
32 class ZlibCallbackInfo : public ZlibCallbackInfoBase {
33 public:
34     ZlibCallbackInfo() = default;
35     ZlibCallbackInfo(napi_env env, napi_ref callback, napi_deferred deferred, bool isCallback);
36     virtual ~ZlibCallbackInfo();
37     virtual void OnZipUnZipFinish(ErrCode result);
38     virtual void DoTask(const OHOS::AppExecFwk::InnerEvent::Callback& task);
39     bool GetIsCallback() const;
40     void SetIsCallback(bool isCallback);
41     void SetCallback(napi_ref callback);
42     void SetDeferred(napi_deferred deferred);
43     void SetDeliverErrCode(bool isDeliverErrCode);
44     void SetValid(bool valid);
45 
46 private:
47     int32_t ExcuteWork(uv_loop_s* loop, uv_work_t* work);
48 private:
49     napi_env env_ = nullptr;
50     napi_ref callback_ = nullptr;
51     napi_deferred deferred_ = nullptr;
52     bool isCallBack_ = false;
53     bool deliverErrcode_ = false;
54     bool valid_ = true;
55     std::mutex validMutex_;
56     DISALLOW_COPY_AND_MOVE(ZlibCallbackInfo);
57 };
58 
59 struct AsyncCallbackInfo {
60     napi_env env;
61     napi_ref callback;
62     napi_deferred deferred;
63     bool isCallBack = false;
64     ErrCode callbackResult;
65     bool deliverErrcode = false;
66     ZlibCallbackInfo *data = nullptr;
67 };
68 
69 struct OriginalSizeCallbackInfo : public BaseCallbackInfo {
OriginalSizeCallbackInfoOriginalSizeCallbackInfo70     explicit OriginalSizeCallbackInfo(napi_env napiEnv) : BaseCallbackInfo(napiEnv) {}
71     std::string srcFile = "";
72     int64_t originalSize = 0;
73 };
74 }  // namespace LIBZIP
75 }  // namespace AppExecFwk
76 }  // namespace OHOS
77 #endif  // OHOS_APPEXECFWK_LIBZIP_ZLIB_CALLBACK_H