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