mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
32d8d95355
Match-id-ac751a4511a3e385320912de43c9860f0c22a529
75 lines
2.2 KiB
C++
75 lines
2.2 KiB
C++
/*
|
|
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef OHOS_VIRTUAL_DEVICE_H
|
|
#define OHOS_VIRTUAL_DEVICE_H
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <dirent.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
#include <linux/input.h>
|
|
#include "linux/uinput.h"
|
|
|
|
#include "constants_dinput.h"
|
|
|
|
namespace OHOS {
|
|
namespace DistributedHardware {
|
|
namespace DistributedInput {
|
|
class VirtualDevice {
|
|
public:
|
|
VirtualDevice(const InputDevice& event);
|
|
virtual ~VirtualDevice();
|
|
bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
|
|
bool CreateKey();
|
|
bool SetPhys(const std::string deviceName);
|
|
bool SetUp(const std::string& devId, const std::string& dhId);
|
|
bool InjectInputEvent(const input_event& event);
|
|
void SetNetWorkId(const std::string netWorkId);
|
|
int32_t GetFd();
|
|
|
|
protected:
|
|
VirtualDevice();
|
|
virtual const std::vector<uint32_t>& GetEventTypes() const = 0;
|
|
virtual const std::vector<uint32_t>& GetKeys() const = 0;
|
|
virtual const std::vector<uint32_t>& GetProperties() const = 0;
|
|
virtual const std::vector<uint32_t>& GetAbs() const = 0;
|
|
virtual const std::vector<uint32_t>& GetRelBits() const = 0;
|
|
|
|
int32_t fd_ = -1;
|
|
std::string deviceName_;
|
|
std::string netWorkId_;
|
|
const uint16_t busType_;
|
|
const uint16_t vendorId_;
|
|
const uint16_t productId_;
|
|
const uint16_t version_;
|
|
struct uinput_user_dev dev_ {};
|
|
struct uinput_abs_setup absTemp_ = {};
|
|
std::vector<uinput_abs_setup> absInit_;
|
|
const std::string pid_ = std::to_string(getpid());
|
|
|
|
private:
|
|
void RecordEventLog(const input_event& event);
|
|
};
|
|
} // namespace DistributedInput
|
|
} // namespace DistributedHardware
|
|
} // namespace OHOS
|
|
|
|
#endif // OHOS_VIRTUAL_DEVICE_H
|