• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_H
16 #define OHOS_APPEXECFWK_LIBZIP_COMMON_H
17 #include <memory>
18 #include <string>
19 
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "zlib_callback_info.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace LIBZIP {
28 #define NAPI_CALL_BASE_BOOL(theCall, retVal) \
29     do {                                     \
30         if ((theCall) == false) {            \
31             return retVal;                   \
32         }                                    \
33     } while (0)
34 
35 struct CallZipUnzipParam {
36     std::string src;
37     std::string dest;
38     OPTIONS options;
39 };
40 
41 struct AsyncZipCallbackInfo {
42     napi_async_work asyncWork;
43     CallZipUnzipParam param;
44     std::shared_ptr<ZlibCallbackInfo> zlibCallbackInfo;
45     int executeResult = 0;
46 };
47 bool UnwrapIntValue(napi_env env, napi_value jsValue, int &result);
48 bool IsTypeForNapiValue(napi_env env, napi_value param, napi_valuetype expectType);
49 std::string UnwrapStringFromJS(napi_env env, napi_value param, const std::string &defaultValue);
50 napi_value GetCallbackErrorValue(napi_env env, int errCode);
51 void SetNamedProperty(napi_env env, napi_value obj, const char *propName, const int propValue);
52 
53 }  // namespace LIBZIP
54 }  // namespace AppExecFwk
55 }  // namespace OHOS
56 #endif  // OHOS_APPEXECFWK_LIBZIP_COMMON_H