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 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 28 namespace OHOS { 29 namespace MMI { 30 typedef std::function<void(void *event, int64_t frameTime)> FunInputEvent; 31 class LibinputAdapter final { 32 public: 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 GetInputFds()43 auto GetInputFds() const 44 { 45 return std::array{fd_, hotplugDetector_.GetFd()}; 46 } 47 48 private: 49 void OnEventHandler(); 50 void OnDeviceAdded(std::string path); 51 void OnDeviceRemoved(std::string path); 52 53 int32_t fd_ { -1 }; 54 libinput *input_ { nullptr }; 55 56 FunInputEvent funInputEvent_; 57 58 HotplugDetector hotplugDetector_; 59 std::unordered_map<std::string, libinput_device*> devices_; 60 }; 61 } // namespace MMI 62 } // namespace OHOS 63 #endif // S_INPUT_H