1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#include "get_device_object.h" 17c29fa5a6Sopenharmony_ci 18c29fa5a6Sopenharmony_ci#include <chrono> 19c29fa5a6Sopenharmony_ci#include <regex> 20c29fa5a6Sopenharmony_ci#include <thread> 21c29fa5a6Sopenharmony_ci 22c29fa5a6Sopenharmony_ci#undef MMI_LOG_TAG 23c29fa5a6Sopenharmony_ci#define MMI_LOG_TAG "GetDeviceObject" 24c29fa5a6Sopenharmony_ci 25c29fa5a6Sopenharmony_cinamespace OHOS { 26c29fa5a6Sopenharmony_cinamespace MMI { 27c29fa5a6Sopenharmony_cinamespace { 28c29fa5a6Sopenharmony_cibool IsKeyboardDevice(const std::string &deviceName) 29c29fa5a6Sopenharmony_ci{ 30c29fa5a6Sopenharmony_ci std::regex regExp("keyboard model[1-3]"); 31c29fa5a6Sopenharmony_ci return std::regex_match(deviceName, regExp); 32c29fa5a6Sopenharmony_ci} 33c29fa5a6Sopenharmony_ci 34c29fa5a6Sopenharmony_cibool IsMouseDevice(const std::string &deviceName) 35c29fa5a6Sopenharmony_ci{ 36c29fa5a6Sopenharmony_ci std::regex regExp("(knob model[1-3])|(trackpad model[1-2])"); 37c29fa5a6Sopenharmony_ci return std::regex_match(deviceName, regExp); 38c29fa5a6Sopenharmony_ci} 39c29fa5a6Sopenharmony_ci} // namespace 40c29fa5a6Sopenharmony_ci 41c29fa5a6Sopenharmony_ciDeviceBase* GetDeviceObject::CreateDeviceObject(const std::string deviceName) 42c29fa5a6Sopenharmony_ci{ 43c29fa5a6Sopenharmony_ci DeviceBase* deviceBasePtr = nullptr; 44c29fa5a6Sopenharmony_ci if (deviceName == "finger") { 45c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingFingerDevice(); 46c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 47c29fa5a6Sopenharmony_ci } else if (deviceName == "pen") { 48c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingPenDevice(); 49c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 50c29fa5a6Sopenharmony_ci } else if (deviceName == "pad") { 51c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingPadDevice(); 52c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 53c29fa5a6Sopenharmony_ci } else if (deviceName == "touch") { 54c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingTouchScreenDevice(); 55c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 56c29fa5a6Sopenharmony_ci } else if (deviceName == "gamePad") { 57c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingGamePadDevice(); 58c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 59c29fa5a6Sopenharmony_ci } else if (deviceName == "joystick") { 60c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingJoystickDevice(); 61c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 62c29fa5a6Sopenharmony_ci } else if (IsKeyboardDevice(deviceName)) { 63c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice(); 64c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 65c29fa5a6Sopenharmony_ci } else if ((deviceName == "mouse") || (deviceName == "trackball")) { 66c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingMouseDevice(); 67c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 68c29fa5a6Sopenharmony_ci } else if (deviceName == "remoteControl") { 69c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice(); 70c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 71c29fa5a6Sopenharmony_ci } else if (IsMouseDevice(deviceName)) { 72c29fa5a6Sopenharmony_ci deviceBasePtr = new (std::nothrow) ProcessingMouseDevice(); 73c29fa5a6Sopenharmony_ci CHKPP(deviceBasePtr); 74c29fa5a6Sopenharmony_ci } else { 75c29fa5a6Sopenharmony_ci MMI_HILOGI("Not supported device :%s", deviceName.c_str()); 76c29fa5a6Sopenharmony_ci } 77c29fa5a6Sopenharmony_ci 78c29fa5a6Sopenharmony_ci return deviceBasePtr; 79c29fa5a6Sopenharmony_ci} 80c29fa5a6Sopenharmony_ci} // namespace MMI 81c29fa5a6Sopenharmony_ci} // namespace OHOS 82