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 S_INPUT_H 16 #define S_INPUT_H 17 #include <thread> 18 #include <libudev.h> 19 #include <functional> 20 #include <libinput.h> 21 #include <sys/epoll.h> 22 #include "nocopyable.h" 23 24 namespace OHOS { 25 namespace MMI { 26 typedef std::function<void(void *event)> FunInputEvent; 27 class SInput { 28 public: 29 SInput(); 30 DISALLOW_COPY_AND_MOVE(SInput); 31 virtual ~SInput(); 32 static void LoginfoPackagingTool(struct libinput_event *event); 33 bool Init(FunInputEvent funInputEvent, const std::string& seat_id = "seat0"); 34 void EventDispatch(struct epoll_event& ev); 35 void Stop(); 36 GetInputFd()37 int32_t GetInputFd() const 38 { 39 return fd_; 40 } 41 42 protected: 43 void OnEventHandler(); 44 45 protected: 46 int32_t fd_ = -1; 47 udev *udev_ = nullptr; 48 libinput *input_ = nullptr; 49 50 FunInputEvent funInputEvent_; 51 std::string seat_id_; 52 }; 53 } // namespace MMI 54 } // namespace OHOS 55 #endif // S_INPUT_H