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 17 #ifndef SPECIAL_INPUT_DEVICE_PARSER_H 18 #define SPECIAL_INPUT_DEVICE_PARSER_H 19 20 #include <shared_mutex> 21 #include <string> 22 #include <map> 23 24 #include "json_parser.h" 25 #include "cJSON.h" 26 27 namespace OHOS { 28 namespace MMI { 29 30 class SpecialInputDeviceParser { 31 public: 32 SpecialInputDeviceParser(const SpecialInputDeviceParser&) = delete; 33 SpecialInputDeviceParser& operator=(const SpecialInputDeviceParser&) = delete; 34 static SpecialInputDeviceParser& GetInstance(); 35 int32_t Init(); 36 int32_t IsPointerDevice(const std::string &name, bool &isPointerDevice); 37 std::string GetInputDevName(const std::string &alias); 38 39 private: 40 SpecialInputDeviceParser() = default; 41 ~SpecialInputDeviceParser() = default; 42 43 struct ExactlyMatchInputDevice { 44 std::string devName; 45 bool isMouse { false }; 46 }; 47 48 struct ContainMatchInputDevice { 49 std::vector<std::string> keywords; 50 bool isMouse { false }; 51 }; 52 53 struct SpecialInputDevice { 54 std::string inputDevAlias; 55 std::string inputDevName; 56 }; 57 58 private: 59 int32_t ParseExactlyMatch(const JsonParser &jsonParser); 60 int32_t ParseContainMatch(const JsonParser &jsonParser); 61 int32_t ParseSpecialInputDevice(const JsonParser &jsonParser); 62 int32_t ParseExactlyMatchItem(const cJSON *json, ExactlyMatchInputDevice &deviceProp); 63 int32_t ParseContainMatchItem(const cJSON *json, ContainMatchInputDevice &deviceProp); 64 int32_t ParseSpecialInputDeviceItem(const cJSON *json, SpecialInputDevice &specialInputDev); 65 bool IsAllKeywordsMatched(const std::string &name, const std::vector<std::string> &keywords); 66 void PrintSpecialInputDevice(); 67 68 private: 69 std::map<std::string, ExactlyMatchInputDevice> exactlyMatchInputDevice_; 70 std::vector<ContainMatchInputDevice> containMatchInputDevice_; 71 std::map<std::string, std::string> specialInputDevices_; 72 std::shared_mutex lock_; 73 std::atomic_bool isInitialized_ { false }; 74 }; 75 } // namespace MMI 76 } // namespace OHOS 77 #define SPECIAL_INPUT_DEVICE_PARSER OHOS::MMI::SpecialInputDeviceParser::GetInstance() 78 #endif // SPECIAL_INPUT_DEVICE_PARSER_H