• 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 
16 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_KITS_NAPI_INCLUDE_COMMON_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_KITS_NAPI_INCLUDE_COMMON_H
18 
19 #include <string_ex.h>
20 
21 #include "napi/native_api.h"
22 #include "napi/native_node_api.h"
23 
24 #include "bgtaskmgr_inner_errors.h"
25 #include "delay_suspend_info.h"
26 
27 namespace OHOS {
28 namespace BackgroundTaskMgr {
29 struct CallbackPromiseInfo {
30     napi_ref callback = nullptr;
31     napi_deferred deferred = nullptr;
32     bool isCallback = false;
33     int errorCode = 0;
34 };
35 
36 class Common {
37 public:
38     static napi_value NapiGetboolean(napi_env env, const bool &isValue);
39 
40     static napi_value NapiGetNull(napi_env env);
41 
42     static napi_value NapiGetUndefined(napi_env env);
43 
44     static napi_value GetCallbackErrorValue(napi_env env, int errCode);
45 
46     static napi_value GetExpireCallbackValue(napi_env env, int errCode, const napi_value &value);
47 
48     static void PaddingCallbackPromiseInfo(
49         const napi_env &env, const napi_ref &callback, CallbackPromiseInfo &info, napi_value &promise);
50 
51     static void ReturnCallbackPromise(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result);
52 
53     static void SetCallback(
54         const napi_env &env, const napi_ref &callbackIn, const int &errorCode, const napi_value &result);
55 
56     static void SetCallback(
57         const napi_env &env, const napi_ref &callbackIn, const napi_value &result);
58 
59     static napi_value SetPromise(const napi_env &env, const CallbackPromiseInfo &info, const napi_value &result);
60 
61     static napi_value JSParaError(const napi_env &env, const napi_ref &callback);
62 
63     static napi_value GetU16StringValue(const napi_env &env, const napi_value &value, std::u16string &result);
64 
65     static napi_value GetInt32NumberValue(const napi_env &env, const napi_value &value, int32_t &result);
66 
67     static napi_value SetDelaySuspendInfo(
68         const napi_env &env, std::shared_ptr<DelaySuspendInfo>& delaySuspendInfo, napi_value &result);
69 };
70 }  // namespace BackgroundTaskMgr
71 }  // namespace OHOS
72 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_KITS_NAPI_INCLUDE_COMMON_H