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 <functional> 19 #include <thread> 20 21 #include <libudev.h> 22 #include <sys/epoll.h> 23 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 { 31 public: 32 static void LoginfoPackagingTool(struct libinput_event *event); 33 static int32_t DeviceLedUpdate(struct libinput_device *device, int32_t funcKey, bool isEnable); 34 LibinputAdapter(); 35 DISALLOW_COPY_AND_MOVE(LibinputAdapter); 36 virtual ~LibinputAdapter(); 37 bool Init(FunInputEvent funInputEvent, const std::string& seat_id = "seat0"); 38 void EventDispatch(struct epoll_event& ev); 39 void Stop(); 40 void ProcessPendingEvents(); 41 void ReloadDevice(); 42 void RetriggerHotplugEvents(); 43 GetInputFd()44 int32_t GetInputFd() const 45 { 46 return fd_; 47 } 48 49 protected: 50 void OnEventHandler(); 51 52 protected: 53 int32_t fd_ { -1 }; 54 udev *udev_ { nullptr }; 55 libinput *input_ { nullptr }; 56 57 FunInputEvent funInputEvent_; 58 std::string seat_id_; 59 }; 60 } // namespace MMI 61 } // namespace OHOS 62 #endif // S_INPUT_H