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 INPUT_EVENT_HANDLER_H 17 #define INPUT_EVENT_HANDLER_H 18 19 #include <memory> 20 21 #include "singleton.h" 22 23 #include "event_dispatch_handler.h" 24 #include "event_filter_handler.h" 25 #include "event_interceptor_handler.h" 26 #include "event_monitor_handler.h" 27 #include "event_normalize_handler.h" 28 #include "i_event_filter.h" 29 #include "i_input_event_handler.h" 30 #include "key_command_handler.h" 31 #include "key_subscriber_handler.h" 32 #include "mouse_event_normalize.h" 33 #include "switch_subscriber_handler.h" 34 35 namespace OHOS { 36 namespace MMI { 37 using EventFun = std::function<int32_t(libinput_event *event)>; 38 using NotifyDeviceChange = std::function<void(int32_t, int32_t, char *)>; 39 class InputEventHandler final { 40 DECLARE_DELAYED_SINGLETON(InputEventHandler); 41 public: 42 DISALLOW_COPY_AND_MOVE(InputEventHandler); 43 void Init(UDSServer& udsServer); 44 void OnEvent(void *event); 45 UDSServer *GetUDSServer() const; 46 47 std::shared_ptr<EventNormalizeHandler> GetEventNormalizeHandler() const; 48 std::shared_ptr<EventInterceptorHandler> GetInterceptorHandler() const; 49 std::shared_ptr<KeySubscriberHandler> GetSubscriberHandler() const; 50 std::shared_ptr<SwitchSubscriberHandler> GetSwitchSubscriberHandler() const; 51 std::shared_ptr<KeyCommandHandler> GetKeyCommandHandler() const; 52 std::shared_ptr<EventMonitorHandler> GetMonitorHandler() const; 53 std::shared_ptr<EventFilterHandler> GetFilterHandler() const; 54 55 private: 56 int32_t BuildInputHandlerChain(); 57 58 UDSServer *udsServer_ { nullptr }; 59 std::shared_ptr<EventNormalizeHandler> eventNormalizeHandler_ { nullptr }; 60 std::shared_ptr<EventFilterHandler> eventFilterHandler_ { nullptr }; 61 std::shared_ptr<EventInterceptorHandler> eventInterceptorHandler_ { nullptr }; 62 std::shared_ptr<KeySubscriberHandler> eventSubscriberHandler_ { nullptr }; 63 std::shared_ptr<SwitchSubscriberHandler> switchEventSubscriberHandler_ { nullptr }; 64 std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler_ { nullptr }; 65 std::shared_ptr<EventMonitorHandler> eventMonitorHandler_ { nullptr }; 66 67 uint64_t idSeed_ { 0 }; 68 }; 69 #define InputHandler ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance() 70 } // namespace MMI 71 } // namespace OHOS 72 #endif // INPUT_EVENT_HANDLER_H 73