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 16 #include "get_device_object.h" 17 18 #include <chrono> 19 #include <regex> 20 #include <thread> 21 22 #undef MMI_LOG_TAG 23 #define MMI_LOG_TAG "GetDeviceObject" 24 25 namespace OHOS { 26 namespace MMI { 27 namespace { IsKeyboardDevice(const std::string & deviceName)28bool IsKeyboardDevice(const std::string &deviceName) 29 { 30 std::regex regExp("keyboard model[1-3]"); 31 return std::regex_match(deviceName, regExp); 32 } 33 IsMouseDevice(const std::string & deviceName)34bool IsMouseDevice(const std::string& deviceName) 35 { 36 std::regex regExp("(knob model[1-3])|(trackpad model[1-2])"); 37 return std::regex_match(deviceName, regExp); 38 } 39 } // namespace 40 CreateDeviceObject(const std::string deviceName)41DeviceBase* GetDeviceObject::CreateDeviceObject(const std::string deviceName) 42 { 43 DeviceBase* deviceBasePtr = nullptr; 44 if (deviceName == "finger") { 45 deviceBasePtr = new (std::nothrow) ProcessingFingerDevice(); 46 CHKPP(deviceBasePtr); 47 } else if (deviceName == "pen") { 48 deviceBasePtr = new (std::nothrow) ProcessingPenDevice(); 49 CHKPP(deviceBasePtr); 50 } else if (deviceName == "pad") { 51 deviceBasePtr = new (std::nothrow) ProcessingPadDevice(); 52 CHKPP(deviceBasePtr); 53 } else if (deviceName == "touch") { 54 deviceBasePtr = new (std::nothrow) ProcessingTouchScreenDevice(); 55 CHKPP(deviceBasePtr); 56 } else if (deviceName == "gamePad") { 57 deviceBasePtr = new (std::nothrow) ProcessingGamePadDevice(); 58 CHKPP(deviceBasePtr); 59 } else if (deviceName == "joystick") { 60 deviceBasePtr = new (std::nothrow) ProcessingJoystickDevice(); 61 CHKPP(deviceBasePtr); 62 } else if (IsKeyboardDevice(deviceName)) { 63 deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice(); 64 CHKPP(deviceBasePtr); 65 } else if ((deviceName == "mouse") || (deviceName == "trackball")) { 66 deviceBasePtr = new (std::nothrow) ProcessingMouseDevice(); 67 CHKPP(deviceBasePtr); 68 } else if (deviceName == "remoteControl") { 69 deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice(); 70 CHKPP(deviceBasePtr); 71 } else if (IsMouseDevice(deviceName)) { 72 deviceBasePtr = new (std::nothrow) ProcessingMouseDevice(); 73 CHKPP(deviceBasePtr); 74 } else { 75 MMI_HILOGI("Not supported device :%s", deviceName.c_str()); 76 } 77 78 return deviceBasePtr; 79 } 80 } // namespace MMI 81 } // namespace OHOS 82