1 /* 2 * Copyright (c) 2025 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 PRE_MONITOR_MANAGER_H 17 #define PRE_MONITOR_MANAGER_H 18 19 #include <map> 20 #include "singleton.h" 21 22 #include "i_input_event_consumer.h" 23 24 namespace OHOS { 25 namespace MMI { 26 class PreMonitorManager final { 27 DECLARE_SINGLETON(PreMonitorManager); 28 29 public: 30 DISALLOW_MOVE(PreMonitorManager); 31 32 #ifdef OHOS_BUILD_ENABLE_KEYBOARD 33 void OnPreKeyEvent(std::shared_ptr<KeyEvent> keyEvent, int32_t handlerId); 34 #endif // OHOS_BUILD_ENABLE_KEYBOARD 35 #if defined(OHOS_BUILD_ENABLE_MONITOR) 36 void OnConnected(); 37 #endif // OHOS_BUILD_ENABLE_MONITOR 38 HandleEventType GetEventType() const; 39 int32_t AddHandler( 40 std::shared_ptr<IInputEventConsumer> consumer, HandleEventType eventType, std::vector<int32_t> keys); 41 int32_t RemoveHandler(int32_t handlerId); 42 43 private: 44 struct Handler { 45 int32_t handlerId_ { 0 }; 46 HandleEventType eventType_ { HANDLE_EVENT_TYPE_PRE_KEY }; 47 std::shared_ptr<IInputEventConsumer> callback_ { nullptr }; 48 std::vector<int32_t> keys_; 49 }; 50 51 private: 52 int32_t GetNextId(); CheckMonitorValid(TouchGestureType type,int32_t fingers)53 virtual bool CheckMonitorValid(TouchGestureType type, int32_t fingers) 54 { 55 return false; 56 } 57 int32_t AddLocal(int32_t handlerId, HandleEventType eventType, std::vector<int32_t> keys, 58 std::shared_ptr<IInputEventConsumer> consumer); 59 int32_t AddToServer(int32_t handlerId, HandleEventType eventType, std::vector<int32_t> keys); 60 int32_t RemoveLocal(int32_t handlerId); 61 int32_t RemoveFromServer(int32_t handlerId); 62 std::shared_ptr<IInputEventConsumer> FindHandler(int32_t handlerId); 63 64 private: 65 std::map<int32_t, Handler> monitorHandlers_; 66 int32_t nextId_ { 1 }; 67 std::mutex mtxHandlers_; 68 }; 69 #define PRE_MONITOR_MGR ::OHOS::Singleton<PreMonitorManager>::GetInstance() 70 } // namespace MMI 71 } // namespace OHOS 72 #endif // PRE_MONITOR_MANAGER_H 73