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 POWERMGR_POWER_MANAGER_RUNNINGLOCK_NAPI_H
17 #define POWERMGR_POWER_MANAGER_RUNNINGLOCK_NAPI_H
18 
19 #include <memory>
20 
21 #include "napi/native_api.h"
22 #include "napi/native_common.h"
23 #include "napi/native_node_api.h"
24 
25 #include "async_callback_info.h"
26 #include "running_lock.h"
27 
28 namespace OHOS {
29 namespace PowerMgr {
30 class RunningLockNapi {
31 public:
32     static napi_value Create(napi_env& env, napi_callback_info& info, napi_ref& napiRunningLockIns);
33     static napi_value IsSupported(napi_env env, napi_callback_info info);
34     static napi_value Hold(napi_env env, napi_callback_info info);
35     static napi_value IsHolding(napi_env env, napi_callback_info info);
36     static napi_value UnHold(napi_env env, napi_callback_info info);
37 
38 private:
39     static napi_value CreateAsyncCallback(
40         napi_env& env, napi_value argv[], std::unique_ptr<AsyncCallbackInfo>& asyncInfo);
41     static napi_value CreatePromise(napi_env& env, napi_value argv[], std::unique_ptr<AsyncCallbackInfo>& asyncInfo);
42 
43     static void AsyncWork(napi_env& env, std::unique_ptr<AsyncCallbackInfo>& asyncInfo, const std::string& resourceName,
44         napi_async_execute_callback execute, napi_async_complete_callback complete);
45     static std::shared_ptr<RunningLock> UnwrapRunningLock(napi_env& env, napi_value& thisArg);
46 };
47 } // namespace PowerMgr
48 } // namespace OHOS
49 
50 #endif // POWERMGR_POWER_MANAGER_RUNNINGLOCK_NAPI_H
51