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 #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 "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 #include "napi/native_common.h" 24 #include "nocopyable.h" 25 #include "zip_utils.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 namespace LIBZIP { 30 class ZlibCallbackInfo { 31 public: 32 ZlibCallbackInfo() = default; 33 ZlibCallbackInfo(napi_env env, napi_ref callback, napi_deferred deferred, bool isCallback); 34 virtual ~ZlibCallbackInfo(); 35 void OnZipUnZipFinish(ErrCode result); 36 bool GetIsCallback() const; 37 void SetIsCallback(bool isCallback); 38 void SetCallback(napi_ref callback); 39 void SetDeferred(napi_deferred deferred); 40 void SetDeliverErrCode(bool isDeliverErrCode); 41 void SetValid(bool valid); 42 private: 43 int32_t ExcuteWork(uv_loop_s* loop, uv_work_t* work); 44 private: 45 napi_env env_ = nullptr; 46 napi_ref callback_ = nullptr; 47 napi_deferred deferred_ = nullptr; 48 bool isCallBack_ = false; 49 bool deliverErrcode_ = false; 50 bool valid_ = true; 51 std::mutex validMutex_; 52 DISALLOW_COPY_AND_MOVE(ZlibCallbackInfo); 53 }; 54 55 struct AsyncCallbackInfo { 56 napi_env env; 57 napi_ref callback; 58 napi_deferred deferred; 59 bool isCallBack = false; 60 ErrCode callbackResult; 61 bool deliverErrcode = false; 62 }; 63 } // namespace LIBZIP 64 } // namespace AppExecFwk 65 } // namespace OHOS 66 #endif // OHOS_APPEXECFWK_LIBZIP_ZLIB_CALLBACK_H