1 /* 2 * Copyright (c) 2021-2024 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 OHOS_INPUT_DEVICE_EVENT_H 17 #define OHOS_INPUT_DEVICE_EVENT_H 18 19 #include <functional> 20 #include <list> 21 #include <map> 22 #include <mutex> 23 #include <vector> 24 25 #include "nocopyable.h" 26 27 #include "i_input_device_listener.h" 28 #include "input_device.h" 29 30 namespace OHOS { 31 namespace MMI { 32 class NetPacket; 33 class InputDeviceImpl final { 34 public: 35 static InputDeviceImpl& GetInstance(); 36 DISALLOW_COPY_AND_MOVE(InputDeviceImpl); 37 ~InputDeviceImpl() = default; 38 39 using FunInputDevInfo = std::function<void(std::shared_ptr<InputDevice>)>; 40 using FunInputDevIds = std::function<void(std::vector<int32_t>&)>; 41 using FunInputDevKeys = std::function<void(std::vector<bool>&)>; 42 using FunKeyboardTypes = std::function<void(int32_t)>; 43 using InputDevListenerPtr = std::shared_ptr<IInputDeviceListener>; 44 45 int32_t RegisterDevListener(const std::string &type, InputDevListenerPtr listener); 46 int32_t UnregisterDevListener(const std::string &type, InputDevListenerPtr listener = nullptr); 47 int32_t GetInputDeviceIds(FunInputDevIds callback); 48 int32_t GetInputDevice(int32_t deviceId, FunInputDevInfo callback); 49 int32_t SupportKeys(int32_t deviceId, std::vector<int32_t> keyCodes, FunInputDevKeys callback); 50 int32_t GetKeyboardType(int32_t deviceId, FunKeyboardTypes callback); 51 int32_t SetKeyboardRepeatDelay(int32_t delay); 52 int32_t SetKeyboardRepeatRate(int32_t rate); 53 int32_t GetKeyboardRepeatDelay(std::function<void(int32_t)> callback); 54 int32_t GetKeyboardRepeatRate(std::function<void(int32_t)> callback); 55 void OnInputDevice(int32_t userData, std::shared_ptr<InputDevice> devData); 56 void OnInputDeviceIds(int32_t userData, std::vector<int32_t> &ids); 57 void OnSupportKeys(int32_t userData, std::vector<bool> &keystrokeAbility); 58 void OnDevListener(int32_t deviceId, const std::string &type); 59 void OnKeyboardType(int32_t userData, int32_t keyboardType); 60 int32_t GetUserData(); 61 62 private: 63 InputDeviceImpl() = default; 64 std::map<std::string, std::list<InputDevListenerPtr>> devListener_ = { { "change", {} } }; 65 int32_t userData_ { 0 }; 66 bool isListeningProcess_ { false }; 67 std::mutex mtx_; 68 }; 69 } // namespace MMI 70 } // namespace OHOS 71 #define INPUT_DEVICE_IMPL OHOS::MMI::InputDeviceImpl::GetInstance() 72 #endif // OHOS_INPUT_DEVICE_EVENT_H