• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_subscriber_handler.h"
31 #include "key_command_handler.h"
32 #include "mouse_event_normalize.h"
33 
34 namespace OHOS {
35 namespace MMI {
36 using EventFun = std::function<int32_t(libinput_event *event)>;
37 using NotifyDeviceChange = std::function<void(int32_t, int32_t, char *)>;
38 class InputEventHandler final {
39     DECLARE_DELAYED_SINGLETON(InputEventHandler);
40 public:
41     DISALLOW_COPY_AND_MOVE(InputEventHandler);
42     void Init(UDSServer& udsServer);
43     void OnEvent(void *event);
44     UDSServer *GetUDSServer() const;
45 
46     std::shared_ptr<EventNormalizeHandler> GetEventNormalizeHandler() const;
47     std::shared_ptr<EventInterceptorHandler> GetInterceptorHandler() const;
48     std::shared_ptr<KeySubscriberHandler> GetSubscriberHandler() const;
49     std::shared_ptr<KeyCommandHandler> GetKeyCommandHandler() const;
50     std::shared_ptr<EventMonitorHandler> GetMonitorHandler() const;
51     std::shared_ptr<EventFilterHandler> GetFilterHandler() const;
52 #ifdef OHOS_BUILD_ENABLE_COOPERATE
53     void SetJumpInterceptState(bool isJump);
54     bool GetJumpInterceptState() const;
55 #endif // OHOS_BUILD_ENABLE_COOPERATE
56 
57 private:
58     int32_t BuildInputHandlerChain();
59 
60     UDSServer *udsServer_ { nullptr };
61     std::shared_ptr<EventNormalizeHandler> eventNormalizeHandler_ { nullptr };
62     std::shared_ptr<EventFilterHandler> eventFilterHandler_ { nullptr };
63     std::shared_ptr<EventInterceptorHandler> eventInterceptorHandler_ { nullptr };
64     std::shared_ptr<KeySubscriberHandler> eventSubscriberHandler_ { nullptr };
65     std::shared_ptr<KeyCommandHandler> eventKeyCommandHandler_ { nullptr };
66     std::shared_ptr<EventMonitorHandler> eventMonitorHandler_ { nullptr };
67 
68     uint64_t idSeed_ { 0 };
69 #ifdef OHOS_BUILD_ENABLE_COOPERATE
70     bool isJumpIntercept_ { false };
71 #endif // OHOS_BUILD_ENABLE_COOPERATE
72 };
73 #define InputHandler ::OHOS::DelayedSingleton<InputEventHandler>::GetInstance()
74 } // namespace MMI
75 } // namespace OHOS
76 #endif // INPUT_EVENT_HANDLER_H
77