1/*
2 * Copyright (c) 2021-2024 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 LIBINPUT_ADAPTER_H
17#define LIBINPUT_ADAPTER_H
18
19#include <array>
20#include <functional>
21#include <thread>
22#include <unordered_map>
23
24#include "hotplug_detector.h"
25#include "libinput.h"
26#include "nocopyable.h"
27
28namespace OHOS {
29namespace MMI {
30typedef std::function<void(void *event, int64_t frameTime)> FunInputEvent;
31class LibinputAdapter final {
32public:
33    static int32_t DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool isEnable);
34    LibinputAdapter() = default;
35    DISALLOW_COPY_AND_MOVE(LibinputAdapter);
36    ~LibinputAdapter() = default;
37    bool Init(FunInputEvent funInputEvent);
38    void EventDispatch(int32_t fd);
39    void Stop();
40    void ProcessPendingEvents();
41    void ReloadDevice();
42
43    auto GetInputFds() const
44    {
45        return std::array{fd_, hotplugDetector_.GetFd()};
46    }
47
48private:
49    void OnEventHandler();
50    void OnDeviceAdded(std::string path);
51    void OnDeviceRemoved(std::string path);
52    void InitRightButtonAreaConfig();
53
54    int32_t fd_ { -1 };
55    libinput *input_ { nullptr };
56
57    FunInputEvent funInputEvent_;
58
59    HotplugDetector hotplugDetector_;
60    std::unordered_map<std::string, libinput_device*> devices_;
61};
62} // namespace MMI
63} // namespace OHOS
64#endif // S_INPUT_H
65