1 /* 2 * Copyright (c) 2020-2021 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 GRAPHIC_LITE_INPUT_EVENT_HUB_H 17 #define GRAPHIC_LITE_INPUT_EVENT_HUB_H 18 19 #include <map> 20 #include "gfx_utils/input_event_info.h" 21 #include "input-event-codes.h" 22 #include "input_manager.h" 23 #include "securec.h" 24 25 namespace OHOS { 26 /** 27 * @brief Hub of input event. 28 */ 29 class InputEventHub { 30 using ReadCallback = void (*)(const RawEvent*); 31 public: 32 static InputEventHub* GetInstance(); 33 34 /** 35 * @brief SetUp hub. This operation will open all input devices. 36 * 37 */ 38 void SetUp(); 39 40 /** 41 * @brief TearDown hub. This operation will close all input devices. 42 * 43 */ 44 void TearDown(); 45 46 /** 47 * @brief Registration read callback. 48 * 49 * @param [in] callback callback of read callback. 50 * 51 * @returns return -1: register callback failed; return 0: register success. 52 */ RegisterReadCallback(const ReadCallback & callback)53 static int32_t RegisterReadCallback(const ReadCallback &callback) 54 { 55 if (callback == nullptr) { 56 return -1; 57 } 58 readCallback_ = callback; 59 return 0; 60 } 61 62 private: 63 static InputDevType GetDeviceType(uint32_t devIndex); 64 static void EventCallback(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex); 65 uint8_t ScanInputDevice(); 66 InputEventHub(); ~InputEventHub()67 ~InputEventHub() {} 68 69 InputEventHub(const InputEventHub&) = delete; 70 InputEventHub& operator=(const InputEventHub&) = delete; 71 InputEventHub(InputEventHub&&) = delete; 72 InputEventHub& operator=(InputEventHub&&) = delete; 73 74 uint32_t mountDevIndex_[MAX_INPUT_DEVICE_NUM]; 75 uint32_t openDev_; 76 RawEvent data_; 77 78 static IInputInterface* inputInterface_; 79 static InputEventCb callback_; 80 static ReadCallback readCallback_; 81 }; 82 } // namespace OHOS 83 #endif 84