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