1 /*
2  * Copyright (c) 2021-2023 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 UPDATER_UI_INPUT_EVENT_H
16 #define UPDATER_UI_INPUT_EVENT_H
17 #include <linux/input.h>
18 #include "common/input_device_manager.h"
19 #include "dock/pointer_input_device.h"
20 #include "input_manager.h"
21 #include "macros_updater.h"
22 #include <unordered_set>
23 #include "pointers_input_device.h"
24 
25 namespace Updater {
26 using AddInputDeviceFunc = std::function<void()>;
27 using HandlePointersEventFunc = std::function<void(const input_event &ev, uint32_t type)>;
28 class InputEvent {
29     DISALLOW_COPY_MOVE(InputEvent);
30 public:
31     void RegisterAddInputDeviceHelper(AddInputDeviceFunc ptr);
32     void RegisterHandleEventHelper(HandlePointersEventFunc ptr);
33     InputEvent() = default;
34     virtual ~InputEvent() = default;
35     static InputEvent &GetInstance();
36     int HandleInputEvent(const struct input_event *iev, uint32_t type);
37     void GetInputDeviceType(uint32_t devIndex, uint32_t &type);
38     static void ReportEventPkgCallback(const InputEventPackage **pkgs, const uint32_t count, uint32_t devIndex);
39     /**
40      * @brief Init input device driver.
41      */
42     int HdfInit();
43 
44 private:
45     IInputInterface *inputInterface_;
46     InputEventCb callback_;
47     std::unordered_map<uint32_t, uint32_t> devTypeMap_{};
48     AddInputDeviceFunc addInputDeviceHelper_;
49     HandlePointersEventFunc handlePointersEventHelper_;
50 };
51 } // namespace Updater
52 #endif // UPDATER_UI_INPUT_EVENT_H