• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <unordered_set>
19 #include "common/input_device_manager.h"
20 #include "dock/pointer_input_device.h"
21 #include "macros_updater.h"
22 #include "pointers_input_device.h"
23 #include "v1_0/iinput_interfaces.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     class HdfInputEventCallback : public OHOS::HDI::Input::V1_0::IInputCallback {
32     public:
33         HdfInputEventCallback() = default;
34         ~HdfInputEventCallback() override = default;
35         int32_t EventPkgCallback(const std::vector<OHOS::HDI::Input::V1_0::EventPackage> &pkgs,
36             uint32_t devIndex) override;
37         int32_t HotPlugCallback(const OHOS::HDI::Input::V1_0::HotPlugEvent &event) override;
38     };
39     void RegisterAddInputDeviceHelper(AddInputDeviceFunc ptr);
40     void RegisterHandleEventHelper(HandlePointersEventFunc ptr);
41     InputEvent() = default;
42     virtual ~InputEvent() = default;
43     static InputEvent &GetInstance();
44     int HandleInputEvent(const struct input_event *iev, uint32_t type);
45     void GetInputDeviceType(uint32_t devIndex, uint32_t &type);
46     /**
47      * @brief Init input device driver.
48      */
49     int HdfInit();
50 
51 private:
52     OHOS::sptr<OHOS::HDI::Input::V1_0::IInputCallback> callback_ {nullptr};
53     OHOS::sptr<OHOS::HDI::Input::V1_0::IInputInterfaces> inputInterface_ = nullptr;
54     std::unordered_map<uint32_t, uint32_t> devTypeMap_{};
55     AddInputDeviceFunc addInputDeviceHelper_;
56     HandlePointersEventFunc handlePointersEventHelper_;
57 };
58 } // namespace Updater
59 #endif // UPDATER_UI_INPUT_EVENT_H