• 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 #ifndef INPUT_EVENT_MONITOR_MANAGER_H
16 #define INPUT_EVENT_MONITOR_MANAGER_H
17 
18 #include "key_event.h"
19 #include "pointer_event.h"
20 #include "multimodal_event_handler.h"
21 #include "proto.h"
22 #include "singleton.h"
23 
24 #include <list>
25 
26 namespace OHOS {
27 namespace MMI {
28 struct MonitorItem {
29     int32_t id;
30     std::function<void (std::shared_ptr<OHOS::MMI::KeyEvent>)> keyEventMonitor;
31     bool operator == (const MonitorItem& item) const
32     {
33         return id == item.id;
34     }
35     std::string name;
36     std::function<void (std::shared_ptr<OHOS::MMI::PointerEvent>)> TouchPadEventMonitor;
37 };
38 
39 class InputEventMonitorManager {
40 public:
41     InputEventMonitorManager();
42     virtual ~InputEventMonitorManager();
43 
44     int32_t AddInputEventMontior(std::function<void (std::shared_ptr<OHOS::MMI::KeyEvent>)> keyEventMonitor);
45     void RemoveInputEventMontior(int32_t monitorId);
46     int32_t OnMonitorInputEvent(std::shared_ptr<OHOS::MMI::KeyEvent> keyEvent);
47 
48     int32_t AddInputEventTouchpadMontior(std::function<void (std::shared_ptr<OHOS::MMI::PointerEvent>)>
49                                         TouchPadEventMonitor);
50     void RemoveInputEventTouchpadMontior(int32_t monitorId);
51     int32_t OnTouchpadMonitorInputEvent(std::shared_ptr<OHOS::MMI::PointerEvent> pointerEvent);
52 
53 public:
54     static constexpr int32_t INVALID_MONITOR_ID { -1 };
55 
56 private:
57     std::list<MonitorItem> monitors_;
58 };
59 } // namespace MMI
60 } // namespace OHOS
61 #define InputMonitorMgr OHOS::Singleton<OHOS::MMI::InputEventMonitorManager>::GetInstance()
62 #endif // INPUT_EVENT_MONITOR_MANAGER_H
63