• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "js_input_device_manager.h"
17 
18 namespace OHOS {
19 namespace MMI {
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "JsInputDeviceManager" };
22 }
GetDeviceIds(napi_env env,napi_value handle)23 napi_value JsInputDeviceManager::GetDeviceIds(napi_env env, napi_value handle)
24 {
25     napi_value ret = CreateCallbackInfo(env, handle);
26     auto &instance = InputDeviceImpl::GetInstance();
27     if (handle == nullptr) {
28         CHKPP(ret);
29         instance.GetInputDeviceIdsAsync(JsEventTarget::userData_ - 1, EmitJsIdsPromise);
30         return ret;
31     }
32     instance.GetInputDeviceIdsAsync(JsEventTarget::userData_ - 1, EmitJsIdsAsync);
33     return nullptr;
34 }
35 
GetDevice(int32_t id,napi_env env,napi_value handle)36 napi_value JsInputDeviceManager::GetDevice(int32_t id, napi_env env, napi_value handle)
37 {
38     napi_value ret = CreateCallbackInfo(env, handle);
39     auto &instance = InputDeviceImpl::GetInstance();
40     if (handle == nullptr) {
41         instance.GetInputDeviceAsync(JsEventTarget::userData_ - 1, id, EmitJsDevPromise);
42         return ret;
43     }
44     instance.GetInputDeviceAsync(JsEventTarget::userData_ - 1, id, EmitJsDevAsync);
45     return nullptr;
46 }
47 
ResetEnv()48 void JsInputDeviceManager::ResetEnv()
49 {
50     JsEventTarget::ResetEnv();
51 }
52 } // namespace MMI
53 } // namespace OHOS