• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)28 bool 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)34 bool 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)41 DeviceBase* GetDeviceObject::CreateDeviceObject(const std::string &deviceName)
42 {
43     DeviceBase* deviceBasePtr = nullptr;
44     if (deviceName == "finger") {
45         deviceBasePtr = new (std::nothrow) ProcessingFingerDevice();
46     } else if (deviceName == "pen") {
47         deviceBasePtr = new (std::nothrow) ProcessingPenDevice();
48     } else if (deviceName == "pad") {
49         deviceBasePtr = new (std::nothrow) ProcessingPadDevice();
50     } else if (deviceName == "touch") {
51         deviceBasePtr = new (std::nothrow) ProcessingTouchScreenDevice();
52     } else if (deviceName == "gamePad") {
53         deviceBasePtr = new (std::nothrow) ProcessingGamePadDevice();
54     } else if (deviceName == "joystick") {
55         deviceBasePtr = new (std::nothrow) ProcessingJoystickDevice();
56     } else if (IsKeyboardDevice(deviceName)) {
57         deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice();
58     } else if ((deviceName == "mouse") || (deviceName == "trackball")) {
59         deviceBasePtr = new (std::nothrow) ProcessingMouseDevice();
60     } else if (deviceName == "remoteControl") {
61         deviceBasePtr = new (std::nothrow) ProcessingKeyboardDevice();
62     } else if (IsMouseDevice(deviceName)) {
63         deviceBasePtr = new (std::nothrow) ProcessingMouseDevice();
64     } else {
65         MMI_HILOGI("Not supported device :%s", deviceName.c_str());
66     }
67     CHKPP(deviceBasePtr);
68     return deviceBasePtr;
69 }
70 } // namespace MMI
71 } // namespace OHOS
72