mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-08-26 19:07:09 -04:00
@@ -16,6 +16,7 @@
|
||||
#include "virtual_device.h"
|
||||
|
||||
#include <securec.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_log.h"
|
||||
@@ -30,6 +31,7 @@ namespace {
|
||||
constexpr uint32_t ABS_MAX_POS = 2;
|
||||
constexpr uint32_t ABS_FUZZ_POS = 3;
|
||||
constexpr uint32_t ABS_FLAT_POS = 4;
|
||||
constexpr uint32_t SLEEP_TIME_US = 10 * 1000;
|
||||
}
|
||||
VirtualDevice::VirtualDevice(const InputDevice &event) : deviceName_(event.name), busType_(event.bus),
|
||||
vendorId_(event.vendor), productId_(event.product), version_(event.version), classes_(event.classes)
|
||||
@@ -163,7 +165,7 @@ bool VirtualDevice::SetUp(const InputDevice &inputDevice, const std::string &dev
|
||||
return false;
|
||||
}
|
||||
DHLOGI("create fd %{public}d", fd_);
|
||||
|
||||
usleep(SLEEP_TIME_US);
|
||||
char sysfsDeviceName[16] = {0};
|
||||
if (ioctl(fd_, UI_GET_SYSNAME(sizeof(sysfsDeviceName)), sysfsDeviceName) < 0) {
|
||||
DHLOGE("Unable to get input device name");
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "nlohmann/json.hpp"
|
||||
#include "system_ability_definition.h"
|
||||
#include "string_ex.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "distributed_hardware_fwk_kit.h"
|
||||
#include "ipublisher_listener.h"
|
||||
@@ -44,6 +45,11 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
namespace {
|
||||
constexpr int32_t RAND_NUM_MIN = 0;
|
||||
constexpr int32_t RAND_NUM_MAX = 20;
|
||||
constexpr int32_t SLEEP_TIME_US = 1000;
|
||||
}
|
||||
REGISTER_SYSTEM_ABILITY_BY_ID(DistributedInputSourceManager, DISTRIBUTED_HARDWARE_INPUT_SOURCE_SA_ID, true);
|
||||
|
||||
DistributedInputSourceManager::DistributedInputSourceManager(int32_t saId, bool runOnCreate)
|
||||
@@ -265,6 +271,9 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st
|
||||
}
|
||||
DHLOGI("RegisterDistributedHardware called, deviceId: %{public}s, dhId: %{public}s, parameters: %{public}s",
|
||||
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str());
|
||||
int32_t randNumber = GenRandInt(RAND_NUM_MIN, RAND_NUM_MAX);
|
||||
usleep(randNumber * SLEEP_TIME_US);
|
||||
|
||||
std::lock_guard<std::mutex> lock(regDisHardwareMutex_);
|
||||
DInputClientRegistInfo info {devId, dhId, callback};
|
||||
regCallbacks_.push_back(info);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-2024 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
|
||||
@@ -68,6 +68,7 @@ std::string GetString(const std::vector<std::string> &vec);
|
||||
int32_t GetRandomInt32();
|
||||
std::string JointDhIds(const std::vector<std::string> &dhids);
|
||||
std::vector<std::string> SplitDhIdString(const std::string &dhIdsString);
|
||||
int32_t GenRandInt(int32_t randMin, int32_t randMax);
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -464,6 +464,14 @@ std::vector<std::string> SplitDhIdString(const std::string &dhIdsString)
|
||||
SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec);
|
||||
return dhIdsVec;
|
||||
}
|
||||
|
||||
int32_t GenRandInt(int32_t randMin, int32_t randMax)
|
||||
{
|
||||
std::random_device randDevice;
|
||||
std::mt19937 genRand(randDevice());
|
||||
std::uniform_int_distribution<int> disRand(randMin, randMax);
|
||||
return disRand(genRand);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user