• 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 #ifndef JS_EVENT_TARGET_H
17 #define JS_EVENT_TARGET_H
18 
19 #include <map>
20 #include <uv.h>
21 
22 #include "libmmi_util.h"
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 #include "utils/log.h"
26 #include "input_device_impl.h"
27 #include "define_multimodal.h"
28 #include "error_multimodal.h"
29 
30 namespace OHOS {
31 namespace MMI {
32 class JsEventTarget {
33 public:
34     static void EmitJsIdsAsync(int32_t userData, std::vector<int32_t> ids);
35     static void CallIdsAsyncWork(uv_work_t *work, int32_t status);
36 
37     static void EmitJsIdsPromise(int32_t userData, std::vector<int32_t> ids);
38     static void CallIdsPromiseWork(uv_work_t *work, int32_t status);
39 
40     static void EmitJsDevAsync(int32_t userData, std::shared_ptr<InputDeviceImpl::InputDeviceInfo> device);
41     static void CallDevAsyncWork(uv_work_t *work, int32_t status);
42 
43     static void EmitJsDevPromise(int32_t userData, std::shared_ptr<InputDeviceImpl::InputDeviceInfo> device);
44     static void CallDevPromiseWork(uv_work_t *work, int32_t status);
45 
46     napi_value CreateCallbackInfo(napi_env env, napi_value handle);
47     void ResetEnv();
48     static bool CheckEnv(napi_env env);
49 
50     struct CallbackInfo {
51         napi_ref ref = nullptr;
52         napi_async_work asyncWork = nullptr;
53         napi_deferred deferred = nullptr;
54         napi_value promise = nullptr;
55         std::vector<int32_t> ids = {0};
56         std::shared_ptr<InputDeviceImpl::InputDeviceInfo> device = nullptr;
57     };
58     struct DeviceType {
59         std::string deviceTypeName;
60         uint32_t typeBit;
61     };
62 
63     static constexpr uint32_t EVDEV_UDEV_TAG_KEYBOARD = (1 << 1);
64     static constexpr uint32_t EVDEV_UDEV_TAG_MOUSE = (1 << 2);
65     static constexpr uint32_t EVDEV_UDEV_TAG_TOUCHPAD = (1 << 3);
66     static constexpr uint32_t EVDEV_UDEV_TAG_TOUCHSCREEN = (1 << 4);
67     static constexpr uint32_t EVDEV_UDEV_TAG_TABLET = (1 << 5);
68     static constexpr uint32_t EVDEV_UDEV_TAG_JOYSTICK = (1 << 6);
69     static constexpr uint32_t EVDEV_UDEV_TAG_ACCELEROMETER = (1 << 7);
70     static constexpr uint32_t EVDEV_UDEV_TAG_TABLET_PAD = (1 << 8);
71     static constexpr uint32_t EVDEV_UDEV_TAG_POINTINGSTICK = (1 << 9);
72     static constexpr uint32_t EVDEV_UDEV_TAG_TRACKBALL = (1 << 10);
73     static constexpr uint32_t EVDEV_UDEV_TAG_SWITCH = (1 << 11);
74 
75     static napi_env env_;
76     static int32_t userData_;
77 };
78 } // namespace MMI
79 } // namespace OHOS
80 
81 #endif // JS_EVENT_TARGET_H