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#ifndef VIRTUAL_DEVICE_H
17c29fa5a6Sopenharmony_ci#define VIRTUAL_DEVICE_H
18c29fa5a6Sopenharmony_ci
19c29fa5a6Sopenharmony_ci#include "nocopyable.h"
20c29fa5a6Sopenharmony_ci#include "virtual_device_config.h"
21c29fa5a6Sopenharmony_ci
22c29fa5a6Sopenharmony_cinamespace OHOS {
23c29fa5a6Sopenharmony_cinamespace MMI {
24c29fa5a6Sopenharmony_ciclass VirtualDevice {
25c29fa5a6Sopenharmony_cipublic:
26c29fa5a6Sopenharmony_ci    static std::vector<std::string> BrowseDirectory(const std::string& filePath);
27c29fa5a6Sopenharmony_ci    static std::string ReadFile(const std::string& filePath);
28c29fa5a6Sopenharmony_ci    static int32_t GetFileSize(const std::string& filePath);
29c29fa5a6Sopenharmony_ci    static std::string ReadUinputToolFile(const std::string& filePath);
30c29fa5a6Sopenharmony_ci    static bool ClearFileResidues(const std::string& fileName);
31c29fa5a6Sopenharmony_ci    static bool CreateHandle(const std::string& deviceArgv);
32c29fa5a6Sopenharmony_ci    static bool AddDevice(const std::string& startDeviceName);
33c29fa5a6Sopenharmony_ci    static bool CloseDevice(const std::string& closeDeviceName, const std::vector<std::string>& deviceList);
34c29fa5a6Sopenharmony_ci    static bool CheckCommand(int32_t argc, char **argv);
35c29fa5a6Sopenharmony_ci    static bool SelectOptions(int32_t argc, char **argv, int32_t &opt);
36c29fa5a6Sopenharmony_ci    static bool ListOption(int32_t argc, char **argv);
37c29fa5a6Sopenharmony_ci    static bool StartOption(int32_t argc, char **argv);
38c29fa5a6Sopenharmony_ci    static bool CloseOption(int32_t argc, char **argv);
39c29fa5a6Sopenharmony_ci    static bool HelpOption(int32_t argc, char **argv);
40c29fa5a6Sopenharmony_ci    static void ShowUsage();
41c29fa5a6Sopenharmony_ci    VirtualDevice(const std::string& deviceName, uint16_t busType, uint16_t vendorId, uint16_t productId);
42c29fa5a6Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(VirtualDevice);
43c29fa5a6Sopenharmony_ci    virtual ~VirtualDevice();
44c29fa5a6Sopenharmony_ci    bool SetUp();
45c29fa5a6Sopenharmony_ci    void Close();
46c29fa5a6Sopenharmony_ci    bool CreateKey();
47c29fa5a6Sopenharmony_ci    bool SetAbsResolution();
48c29fa5a6Sopenharmony_ci    bool SetPhys(const std::string& deviceName);
49c29fa5a6Sopenharmony_ci    bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
50c29fa5a6Sopenharmony_ci    void SetDeviceId();
51c29fa5a6Sopenharmony_ci
52c29fa5a6Sopenharmony_ciprotected:
53c29fa5a6Sopenharmony_ci    void SetResolution(const ResolutionInfo& resolutionInfo);
54c29fa5a6Sopenharmony_ci    void SetAbsValue(const AbsInfo& absInfo);
55c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetAbs() const;
56c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetEventTypes() const;
57c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetKeys() const;
58c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetLeds() const;
59c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetMiscellaneous() const;
60c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetProperties() const;
61c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetRelBits() const;
62c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetRepeats() const;
63c29fa5a6Sopenharmony_ci    virtual const std::vector<uint32_t>& GetSwitches() const;
64c29fa5a6Sopenharmony_ci
65c29fa5a6Sopenharmony_ciprotected:
66c29fa5a6Sopenharmony_ci    int32_t fd_ { -1 };
67c29fa5a6Sopenharmony_ci    std::string deviceName_;
68c29fa5a6Sopenharmony_ci    const uint16_t busTtype_ { 0 };
69c29fa5a6Sopenharmony_ci    const uint16_t vendorId_ { 0 };
70c29fa5a6Sopenharmony_ci    const uint16_t productId_ { 0 };
71c29fa5a6Sopenharmony_ci    const uint16_t version_ { 0 };
72c29fa5a6Sopenharmony_ci    struct uinput_user_dev uinputDev_ {};
73c29fa5a6Sopenharmony_ci    struct uinput_abs_setup uinputAbs_ {};
74c29fa5a6Sopenharmony_ci    std::vector<uinput_abs_setup> absInit_;
75c29fa5a6Sopenharmony_ci    std::vector<uint32_t> eventTypes_;
76c29fa5a6Sopenharmony_ci    std::vector<uint32_t> keys_;
77c29fa5a6Sopenharmony_ci    std::vector<uint32_t> properties_;
78c29fa5a6Sopenharmony_ci    std::vector<uint32_t> abs_;
79c29fa5a6Sopenharmony_ci    std::vector<uint32_t> relBits_;
80c29fa5a6Sopenharmony_ci    std::vector<uint32_t> leds_;
81c29fa5a6Sopenharmony_ci    std::vector<uint32_t> miscellaneous_;
82c29fa5a6Sopenharmony_ci    std::vector<uint32_t> switches_;
83c29fa5a6Sopenharmony_ci    std::vector<uint32_t> repeats_;
84c29fa5a6Sopenharmony_ci};
85c29fa5a6Sopenharmony_ci} // namespace MMI
86c29fa5a6Sopenharmony_ci} // namespace OHOS
87c29fa5a6Sopenharmony_ci#endif // VIRTUAL_DEVICE_H
88