mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
Description: adapting to special peripherals
Match-id-bab91f702220d1c54456820132b3ce16a652d629
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <linux/uinput.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
@@ -115,6 +117,8 @@ namespace DistributedInput {
|
||||
/* The input device is external (not built-in). */
|
||||
constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000;
|
||||
|
||||
constexpr uint32_t MAX_SIZE_OF_DEVICE_NAME = UINPUT_MAX_NAME_SIZE - 1;
|
||||
|
||||
const std::string DH_ID_PREFIX = "Input_";
|
||||
|
||||
const std::string DINPUT_SPLIT_COMMA = ", ";
|
||||
@@ -179,10 +183,10 @@ namespace DistributedInput {
|
||||
* Input device Info retrieved from the kernel.
|
||||
*/
|
||||
struct InputDevice {
|
||||
inline InputDevice() : name(""), location(""), uniqueId(""), bus(0), vendor(0), product(0),
|
||||
inline InputDevice() : name(""), physicalPath(""), uniqueId(""), bus(0), vendor(0), product(0),
|
||||
version(0), descriptor(""), classes(0) {}
|
||||
std::string name;
|
||||
std::string location;
|
||||
std::string physicalPath;
|
||||
std::string uniqueId;
|
||||
uint16_t bus;
|
||||
uint16_t vendor;
|
||||
|
||||
@@ -535,12 +535,12 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier)
|
||||
identifier.product = inputId.product;
|
||||
identifier.vendor = inputId.vendor;
|
||||
identifier.version = inputId.version;
|
||||
// Get device physical location.
|
||||
// Get device physical physicalPath.
|
||||
if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) {
|
||||
DHLOGE("could not get location for %s\n", ConvertErrNo().c_str());
|
||||
DHLOGE("could not get physicalPath for %s\n", ConvertErrNo().c_str());
|
||||
} else {
|
||||
buffer[sizeof(buffer) - 1] = '\0';
|
||||
identifier.location = buffer;
|
||||
identifier.physicalPath = buffer;
|
||||
}
|
||||
// Get device unique id.
|
||||
if (ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) {
|
||||
@@ -695,9 +695,10 @@ void InputHub::GenerateDescriptor(InputDevice& identifier) const
|
||||
if (!identifier.uniqueId.empty()) {
|
||||
rawDescriptor += "uniqueId:";
|
||||
rawDescriptor += identifier.uniqueId;
|
||||
} else if (!identifier.location.empty()) {
|
||||
rawDescriptor += "location:";
|
||||
rawDescriptor += identifier.location;
|
||||
}
|
||||
if (!identifier.physicalPath.empty()) {
|
||||
rawDescriptor += "physicalPath:";
|
||||
rawDescriptor += identifier.physicalPath;
|
||||
}
|
||||
if (!identifier.name.empty()) {
|
||||
rawDescriptor += "name:";
|
||||
@@ -1071,7 +1072,7 @@ void InputHub::RecordDeviceLog(const int32_t deviceId, const std::string& device
|
||||
" version %04x\n",
|
||||
identifier.bus, identifier.vendor, identifier.product, identifier.version);
|
||||
DHLOGI(" name: \"%s\"\n", identifier.name.c_str());
|
||||
DHLOGI(" location: \"%s\"\n", identifier.location.c_str());
|
||||
DHLOGI(" physicalPath: \"%s\"\n", identifier.physicalPath.c_str());
|
||||
DHLOGI(" unique id: \"%s\"\n", identifier.uniqueId.c_str());
|
||||
DHLOGI(" descriptor: \"%s\"\n", GetAnonyString(identifier.descriptor).c_str());
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ void DistributedInputHandler::StructTransJson(const InputDevice& pBuf, std::stri
|
||||
GetAnonyString(pBuf.descriptor).c_str());
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson["name"] = pBuf.name;
|
||||
tmpJson["location"] = pBuf.location;
|
||||
tmpJson["physicalPath"] = pBuf.physicalPath;
|
||||
tmpJson["uniqueId"] = pBuf.uniqueId;
|
||||
tmpJson["bus"] = pBuf.bus;
|
||||
tmpJson["vendor"] = pBuf.vendor;
|
||||
|
||||
@@ -132,7 +132,7 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st
|
||||
GetAnonyString(pBuf.descriptor).c_str());
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson["name"] = pBuf.name;
|
||||
tmpJson["location"] = pBuf.location;
|
||||
tmpJson["physicalPath"] = pBuf.physicalPath;
|
||||
tmpJson["uniqueId"] = pBuf.uniqueId;
|
||||
tmpJson["bus"] = pBuf.bus;
|
||||
tmpJson["vendor"] = pBuf.vendor;
|
||||
|
||||
@@ -73,7 +73,7 @@ void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string&
|
||||
{
|
||||
nlohmann::json recMsg = nlohmann::json::parse(str);
|
||||
recMsg.at("name").get_to(pBuf.name);
|
||||
recMsg.at("location").get_to(pBuf.location);
|
||||
recMsg.at("physicalPath").get_to(pBuf.physicalPath);
|
||||
recMsg.at("uniqueId").get_to(pBuf.uniqueId);
|
||||
recMsg.at("bus").get_to(pBuf.bus);
|
||||
recMsg.at("vendor").get_to(pBuf.vendor);
|
||||
|
||||
@@ -103,6 +103,9 @@ bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId)
|
||||
}
|
||||
|
||||
deviceName_ = VIRTUAL_DEVICE_NAME + deviceName_;
|
||||
if (deviceName_.size() > MAX_SIZE_OF_DEVICE_NAME) {
|
||||
deviceName_ = deviceName_.substr(0, MAX_SIZE_OF_DEVICE_NAME);
|
||||
}
|
||||
if (strncpy_s(dev_.name, sizeof(dev_.name), deviceName_.c_str(), deviceName_.size()) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware01, testin
|
||||
pBuffer.vendor = 0x1234;
|
||||
pBuffer.product = 0xfedc;
|
||||
pBuffer.version = 1;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "1";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD;
|
||||
pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
|
||||
@@ -80,7 +80,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware02, testin
|
||||
pBuffer.vendor = 0x1222;
|
||||
pBuffer.product = 0xfeda;
|
||||
pBuffer.version = 2;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "2";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR;
|
||||
pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
|
||||
@@ -101,7 +101,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware03, testin
|
||||
pBuffer.vendor = 0x1233;
|
||||
pBuffer.product = 0xfedb;
|
||||
pBuffer.version = 3;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "3";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH;
|
||||
pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
|
||||
|
||||
+4
-4
@@ -169,7 +169,7 @@ int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pB
|
||||
{
|
||||
nlohmann::json tmpJson;
|
||||
tmpJson["name"] = pBuf.name;
|
||||
tmpJson["location"] = pBuf.location;
|
||||
tmpJson["physicalPath"] = pBuf.physicalPath;
|
||||
tmpJson["uniqueId"] = pBuf.uniqueId;
|
||||
tmpJson["bus"] = pBuf.bus;
|
||||
tmpJson["vendor"] = pBuf.vendor;
|
||||
@@ -198,7 +198,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testi
|
||||
pBuffer.vendor = 0x1233;
|
||||
pBuffer.product = 0xfedb;
|
||||
pBuffer.version = 3;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "3";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH;
|
||||
pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
|
||||
@@ -222,7 +222,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware02, testi
|
||||
pBuffer.vendor = 0x1222;
|
||||
pBuffer.product = 0xfeda;
|
||||
pBuffer.version = 2;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "2";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR;
|
||||
pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
|
||||
@@ -244,7 +244,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware03, testi
|
||||
pBuffer.vendor = 0x1234;
|
||||
pBuffer.product = 0xfedc;
|
||||
pBuffer.version = 1;
|
||||
pBuffer.location = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1";
|
||||
pBuffer.uniqueId = "1";
|
||||
pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD;
|
||||
pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
|
||||
|
||||
@@ -129,16 +129,17 @@ std::string GetNodeDesc(std::string parameters)
|
||||
{
|
||||
nlohmann::json parObj = nlohmann::json::parse(parameters);
|
||||
std::string nodeName = "N/A";
|
||||
std::string location = "N/A";
|
||||
std::string physicalPath = "N/A";
|
||||
int32_t classes = -1;
|
||||
|
||||
if (parObj.find("name") != parObj.end() && parObj.find("location") != parObj.end() &&
|
||||
if (parObj.find("name") != parObj.end() && parObj.find("physicalPath") != parObj.end() &&
|
||||
parObj.find("classes") != parObj.end()) {
|
||||
nodeName = parObj.at("name").get<std::string>();
|
||||
location = parObj.at("location").get<std::string>();
|
||||
physicalPath = parObj.at("physicalPath").get<std::string>();
|
||||
classes = parObj.at("classes").get<int32_t>();
|
||||
}
|
||||
return "{ nodeName: " + nodeName + ", location: " + location + ", classes: " + std::to_string(classes) + " }";
|
||||
return "{ nodeName: " + nodeName + ", physicalPath: " + physicalPath + ", classes: " +
|
||||
std::to_string(classes) + " }";
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
Reference in New Issue
Block a user