检视意见修改

Signed-off-by: litiangang4 <litiangang4@huawei.com>
This commit is contained in:
litiangang4
2023-09-15 16:35:21 +08:00
parent b305d95d97
commit 368f2a8062
22 changed files with 197 additions and 200 deletions
+44 -43
View File
@@ -103,7 +103,7 @@ size_t InputHub::StartCollectInputEvents(RawEvent *buffer, size_t bufferSize)
ScanInputDevices(DEVICE_PATH);
}
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
while (!openingDevices_.empty()) {
std::unique_ptr<Device> device = std::move(*openingDevices_.rbegin());
openingDevices_.pop_back();
@@ -156,7 +156,7 @@ size_t InputHub::GetEvents(RawEvent *buffer, size_t bufferSize)
RawEvent* event = buffer;
size_t capacity = bufferSize;
while (pendingEventIndex_ < pendingEventCount_) {
std::unique_lock<std::mutex> my_lock(operationMutex_);
std::lock_guard<std::mutex> my_lock(operationMutex_);
const struct epoll_event& eventItem = mPendingEventItems[pendingEventIndex_++];
if (eventItem.data.fd == iNotifyFd_) {
if (eventItem.events & EPOLLIN) {
@@ -265,7 +265,7 @@ size_t InputHub::DeviceIsExists(InputDeviceEvent *buffer, size_t bufferSize)
size_t capacity = bufferSize;
// Report any devices that had last been added/removed.
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (auto it = closingDevices_.begin(); it != closingDevices_.end();) {
std::unique_ptr<Device> device = std::move(*it);
DHLOGI("Reporting device closed: id=%s, name=%s\n",
@@ -287,7 +287,7 @@ size_t InputHub::DeviceIsExists(InputDeviceEvent *buffer, size_t bufferSize)
}
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
while (!openingDevices_.empty()) {
std::unique_ptr<Device> device = std::move(*openingDevices_.rbegin());
openingDevices_.pop_back();
@@ -350,7 +350,7 @@ void InputHub::StopCollectInputHandler()
void InputHub::GetDeviceHandler()
{
while (pendingEventIndex_ < pendingEventCount_) {
std::unique_lock<std::mutex> my_lock(operationMutex_);
std::lock_guard<std::mutex> my_lock(operationMutex_);
const struct epoll_event& eventItem = mPendingEventItems[pendingEventIndex_++];
if (eventItem.data.fd == iNotifyFd_) {
if (eventItem.events & EPOLLIN) {
@@ -411,9 +411,9 @@ int32_t InputHub::RefreshEpollItem(bool isSleep)
std::vector<InputDevice> InputHub::GetAllInputDevices()
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
std::vector<InputDevice> vecDevice;
for (const auto& [id, device] : devices_) {
for (const auto &[id, device] : devices_) {
vecDevice.push_back(device->identifier);
}
return vecDevice;
@@ -422,17 +422,17 @@ std::vector<InputDevice> InputHub::GetAllInputDevices()
void InputHub::ScanInputDevices(const std::string &dirName)
{
DHLOGI("ScanInputDevices enter, dirName %s.", dirName.c_str());
std::vector<std::string> vecInputDevPath;
ScanInputDevicesPath(dirName, vecInputDevPath);
for (const auto &tempPath: vecInputDevPath) {
std::vector<std::string> inputDevPaths;
ScanInputDevicesPath(dirName, inputDevPaths);
for (const auto &tempPath: inputDevPaths) {
OpenInputDeviceLocked(tempPath);
}
}
bool InputHub::IsDeviceRegistered(const std::string &devicePath)
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (const auto& [deviceId, device] : devices_) {
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[deviceId, device] : devices_) {
if (device->path == devicePath) {
return true; // device was already registered
}
@@ -446,7 +446,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath)
return DH_SUCCESS;
}
std::unique_lock<std::mutex> my_lock(operationMutex_);
std::lock_guard<std::mutex> my_lock(operationMutex_);
DHLOGI("Opening device: %s", devicePath.c_str());
int fd = OpenInputDeviceFdByPath(devicePath);
if (fd == UN_INIT_FD_VALUE) {
@@ -823,7 +823,7 @@ int32_t InputHub::RegisterFdForEpoll(int fd)
void InputHub::AddDeviceLocked(std::unique_ptr<Device> device)
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
openingDevices_.push_back(std::move(device));
}
@@ -836,7 +836,7 @@ void InputHub::CloseDeviceLocked(Device &device)
UnregisterDeviceFromEpollLocked(device);
device.Close();
{
std::unique_lock<std::mutex> devicesLock(devicesMutex_);
std::lock_guard<std::mutex> devicesLock(devicesMutex_);
closingDevices_.push_back(std::move(devices_[device.id]));
devices_.erase(device.id);
}
@@ -936,7 +936,7 @@ void InputHub::CloseDeviceByPathLocked(const std::string &devicePath)
void InputHub::CloseAllDevicesLocked()
{
DHLOGI("Close All Devices");
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
while (!devices_.empty()) {
CloseDeviceForAllLocked(*(devices_.begin()->second));
}
@@ -944,8 +944,8 @@ void InputHub::CloseAllDevicesLocked()
InputHub::Device* InputHub::GetDeviceByPathLocked(const std::string &devicePath)
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (const auto& [id, device] : devices_) {
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->path == devicePath) {
return device.get();
}
@@ -955,8 +955,8 @@ InputHub::Device* InputHub::GetDeviceByPathLocked(const std::string &devicePath)
InputHub::Device* InputHub::GetDeviceByFdLocked(int fd)
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (const auto& [id, device] : devices_) {
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->fd == fd) {
return device.get();
}
@@ -967,8 +967,8 @@ InputHub::Device* InputHub::GetDeviceByFdLocked(int fd)
InputHub::Device* InputHub::GetSupportDeviceByFd(int fd)
{
DHLOGI("GetSupportDeviceByFd fd: %d", fd);
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (const auto& [id, device] : devices_) {
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device != nullptr && device->fd == fd) {
DHLOGI("GetSupportDeviceByFd device: %d, fd: %d, path: %s, dhId: %s, classes=0x%x", id, device->fd,
device->path.c_str(), GetAnonyString(device->identifier.descriptor).c_str(), device->classes);
@@ -1023,7 +1023,7 @@ AffectDhIds InputHub::SetSupportInputType(bool enabled, const uint32_t &inputTyp
AffectDhIds affDhIds;
inputTypes_ = inputTypes;
DHLOGI("SetSupportInputType: inputTypes=0x%x,", inputTypes_.load());
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->classes & inputTypes_) {
device->isShare = enabled;
@@ -1038,7 +1038,7 @@ AffectDhIds InputHub::SetSupportInputType(bool enabled, const uint32_t &inputTyp
AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector<std::string> dhIds)
{
AffectDhIds affDhIds;
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
DHLOGI("SetSharingDevices start");
for (auto dhId : dhIds) {
DHLOGI("SetSharingDevices dhId: %s, size: %d, enabled: %d", GetAnonyString(dhId).c_str(), devices_.size(),
@@ -1059,11 +1059,12 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector<std::string> d
return affDhIds;
}
void InputHub::GetShareMousePathByDhId(std::vector<std::string> dhIds, std::string &path, std::string &dhId)
void InputHub::GetSharedMousePathByDhId(const std::vector<std::string> &dhIds, std::string &sharedMousePath,
std::string &sharedMouseDhId)
{
DHLOGI("GetShareMousePathByDhId: devices_.size:%d,", devices_.size());
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (auto dhId_ : dhIds) {
DHLOGI("GetSharedMousePathByDhId: devices_.size:%d,", devices_.size());
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &dhId : dhIds) {
for (const auto &[id, device] : devices_) {
if (device == nullptr) {
DHLOGE("device is nullptr");
@@ -1071,23 +1072,23 @@ void InputHub::GetShareMousePathByDhId(std::vector<std::string> dhIds, std::stri
}
DHLOGI("descriptor:%s, isShare[%d], type[%d]", GetAnonyString(device->identifier.descriptor).c_str(),
device->isShare, device->classes);
if ((device->identifier.descriptor == dhId_) && ((device->classes & INPUT_DEVICE_CLASS_CURSOR) != 0 ||
if ((device->identifier.descriptor == dhId) && ((device->classes & INPUT_DEVICE_CLASS_CURSOR) != 0 ||
(device->classes & INPUT_DEVICE_CLASS_TOUCH) != 0 ||
((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) != 0 && IsTouchPad(device->identifier)))) {
dhId = dhId_;
path = device->path;
sharedMouseDhId = dhId;
sharedMousePath = device->path;
return; // return First shared mouse
}
}
}
}
void InputHub::GetShareKeyboardPathsByDhIds(std::vector<std::string> dhIds, std::vector<std::string> &shareDhidsPaths,
std::vector<std::string> &shareDhIds)
void InputHub::GetSharedKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &sharedKeyboardPaths, std::vector<std::string> &sharedKeyboardDhIds)
{
DHLOGI("GetShareKeyboardPathsByDhIds: devices_.size:%d,", devices_.size());
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
for (auto dhId_ : dhIds) {
DHLOGI("GetSharedKeyboardPathsByDhIds: devices_.size:%d,", devices_.size());
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &dhId : dhIds) {
for (const auto &[id, device] : devices_) {
if (device == nullptr) {
DHLOGE("device is nullptr");
@@ -1095,10 +1096,10 @@ void InputHub::GetShareKeyboardPathsByDhIds(std::vector<std::string> dhIds, std:
}
DHLOGI("descriptor:%s, isShare[%d], type[%d]", GetAnonyString(device->identifier.descriptor).c_str(),
device->isShare, device->classes);
if ((device->identifier.descriptor == dhId_) &&
if ((device->identifier.descriptor == dhId) &&
((device->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0)) {
shareDhIds.push_back(dhId_);
shareDhidsPaths.push_back(device->path);
sharedKeyboardDhIds.push_back(dhId);
sharedKeyboardPaths.push_back(device->path);
}
}
}
@@ -1120,7 +1121,7 @@ void InputHub::GetDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t,
dhType |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
}
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->classes & dhType) {
datas.insert(std::pair<int32_t, std::string>(device->fd, device->identifier.descriptor));
@@ -1131,7 +1132,7 @@ void InputHub::GetDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t,
void InputHub::GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas)
{
for (auto dhId : dhidsVec) {
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->identifier.descriptor == dhId) {
datas.insert(std::pair<int32_t, std::string>(device->fd, dhId));
@@ -1142,7 +1143,7 @@ void InputHub::GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<
bool InputHub::IsAllDevicesStoped()
{
std::unique_lock<std::mutex> deviceLock(devicesMutex_);
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[dhId, isShared] : sharedDHIds_) {
DHLOGI("the dhId: %s, isShared: %d", GetAnonyString(dhId).c_str(), isShared);
if (isShared) {
@@ -1250,7 +1251,7 @@ bool InputHub::CheckTouchPointRegion(struct input_event readBuffer[], const AbsI
{
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
for (const auto& [id, sinkInfo] : sinkInfos) {
for (const auto &[id, sinkInfo] : sinkInfos) {
auto info = sinkInfo.transformInfo;
if ((absInfo.absX >= info.sinkWinPhyX) && (absInfo.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
&& (absInfo.absY >= info.sinkWinPhyY) && (absInfo.absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
+4 -3
View File
@@ -52,9 +52,10 @@ public:
AffectDhIds SetSharingDevices(bool enabled, std::vector<std::string> dhIds);
void GetDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas);
void GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
void GetShareMousePathByDhId(std::vector<std::string> dhIds, std::string &path, std::string &dhId);
void GetShareKeyboardPathsByDhIds(std::vector<std::string> dhIds, std::vector<std::string> &shareDhidsPaths,
std::vector<std::string> &shareDhIds);
void GetSharedMousePathByDhId(const std::vector<std::string> &dhIds, std::string &sharedMousePath,
std::string &sharedMouseDhId);
void GetSharedKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &sharedKeyboardPaths, std::vector<std::string> &sharedKeyboardDhIds);
bool IsAllDevicesStoped();
void ScanInputDevices(const std::string &dirName);
@@ -196,7 +196,7 @@ bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &e
{
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
for (const auto& [id, sinkInfo] : sinkInfos) {
for (const auto &[id, sinkInfo] : sinkInfos) {
auto info = sinkInfo.transformInfo;
DHLOGI("event.absX:%d, info.sinkWinPhyX:%d, info.sinkProjPhyWidth:%d\n", event.absX, info.sinkWinPhyX,
info.sinkProjPhyWidth);
@@ -560,7 +560,7 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string &deviceId, const
bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &event)
{
std::lock_guard<std::mutex> lock(operationMutex_);
for (const auto& info : screenTransInfos) {
for (const auto &info : screenTransInfos) {
DHLOGI("sinkProjPhyWidth: %d sinkProjPhyHeight: %d", info.sinkProjPhyWidth, info.sinkProjPhyHeight);
if ((event.absX >= info.sinkWinPhyX) && (event.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
&& (event.absY >= info.sinkWinPhyY) && (event.absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
@@ -42,9 +42,9 @@ public:
void Release();
AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType);
AffectDhIds SetSharingDhIds(bool enabled, std::vector<std::string> dhIds);
void GetMouseNodePath(std::vector<std::string> dhIds, std::string &mouseNodePath, std::string &dhid);
void GetShareKeyboardPathsByDhIds(std::vector<std::string> dhIds, std::vector<std::string> &shareDhidsPaths,
std::vector<std::string> &shareDhIds);
void GetMouseNodePath(const std::vector<std::string> &dhIds, std::string &mouseNodePath, std::string &dhid);
void GetSharedKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &sharedKeyboardPaths, std::vector<std::string> &sharedKeyboardDhIds);
// false for sharing device exist, true for all devices stop sharing
bool IsAllDevicesStoped();
int32_t RegisterSharingDhIdListener(sptr<ISharingDhIdListener> sharingDhIdListener);
@@ -204,24 +204,24 @@ AffectDhIds DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector
return inputHub_->SetSharingDevices(enabled, dhIds);
}
void DistributedInputCollector::GetMouseNodePath(
std::vector<std::string> dhIds, std::string &mouseNodePath, std::string &dhid)
void DistributedInputCollector::GetMouseNodePath(const std::vector<std::string> &dhIds,
std::string &mouseNodePath, std::string &dhId)
{
if (inputHub_ == nullptr) {
DHLOGE("inputHub is nullptr!");
return;
}
inputHub_->GetShareMousePathByDhId(dhIds, mouseNodePath, dhid);
inputHub_->GetSharedMousePathByDhId(dhIds, mouseNodePath, dhId);
}
void DistributedInputCollector::GetShareKeyboardPathsByDhIds(std::vector<std::string> dhIds,
std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds)
void DistributedInputCollector::GetSharedKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &sharedKeyboardPaths, std::vector<std::string> &sharedKeyboardDhIds)
{
if (inputHub_ == nullptr) {
DHLOGE("inputHub is nullptr!");
return;
}
inputHub_->GetShareKeyboardPathsByDhIds(dhIds, shareDhidsPaths, shareDhIds);
inputHub_->GetSharedKeyboardPathsByDhIds(dhIds, sharedKeyboardPaths, sharedKeyboardDhIds);
}
bool DistributedInputCollector::IsAllDevicesStoped()
@@ -238,11 +238,11 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInput(
std::map<int32_t, std::string> deviceInfos;
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
deviceInfos);
for (auto deviceInfo : deviceInfos) {
for (const auto &deviceInfo : deviceInfos) {
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
std::vector<std::string> vecStr;
StringSplitToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_OUT, sessionId);
std::vector<std::string> devDhIds;
SplitStringToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, sessionId);
}
}
}
@@ -300,10 +300,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnStartRemoteInputDhid(con
return;
}
std::vector<std::string> vecStr;
StringSplitToVector(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_OUT, sessionId);
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
std::vector<std::string> devDhIds;
SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, sessionId);
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, devDhIds);
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
}
@@ -314,14 +314,14 @@ void DistributedInputSinkManager::DInputSinkListener::OnStopRemoteInputDhid(cons
DHLOGI("OnStopRemoteInputDhid called, sessionId: %d", sessionId);
std::vector<std::string> stopIndeedDhIds;
std::vector<std::string> stopOnCmdDhIds;
StringSplitToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
sinkManagerObj_->DeleteStopDhids(sessionId, stopOnCmdDhIds, stopIndeedDhIds);
(void)DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopIndeedDhIds);
AffectDhIds stopIndeedOnes;
stopIndeedOnes.noSharingDhIds = stopIndeedDhIds;
DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes);
DInputState::GetInstance().RecordDhids(stopOnCmdDhIds, DhidState::THROUGH_IN, -1);
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1);
if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) {
DHLOGE("All dhid stop sharing, sessionId: %d is closed.", sessionId);
@@ -367,10 +367,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartDhidRemoteInpu
return;
}
std::vector<std::string> vecStr;
StringSplitToVector(strDhids, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_OUT, toSinkSessionId);
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, vecStr);
std::vector<std::string> devDhIds;
SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, toSinkSessionId);
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(true, devDhIds);
sinkManagerObj_->StoreStartDhids(toSinkSessionId, affDhIds.sharingDhIds);
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
}
@@ -381,14 +381,14 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStopDhidRemoteInput
DHLOGI("onRelayStopDhidRemoteInput called, toSinkSessionId: %d", toSinkSessionId);
std::vector<std::string> stopIndeedDhIds;
std::vector<std::string> stopOnCmdDhIds;
StringSplitToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
SplitStringToVector(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds);
sinkManagerObj_->DeleteStopDhids(toSinkSessionId, stopOnCmdDhIds, stopIndeedDhIds);
AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopIndeedDhIds);
AffectDhIds stopIndeedOnes;
stopIndeedOnes.noSharingDhIds = stopIndeedDhIds;
DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes);
DInputState::GetInstance().RecordDhids(stopOnCmdDhIds, DhidState::THROUGH_IN, -1);
DInputState::GetInstance().RecordDhIds(stopOnCmdDhIds, DhIdState::THROUGH_IN, -1);
if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) {
DHLOGE("All dhid stop sharing, sessionId: %d is closed.", toSinkSessionId);
@@ -461,9 +461,9 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayStartTypeRemoteInpu
deviceInfos);
for (auto deviceInfo : deviceInfos) {
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
std::vector<std::string> vecStr;
StringSplitToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_OUT, toSinkSessionId);
std::vector<std::string> devDhIds;
SplitStringToVector(deviceInfo.second, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_OUT, toSinkSessionId);
}
}
@@ -935,7 +935,7 @@ void DistributedInputSinkManager::CallBackScreenInfoChange()
std::vector<std::vector<uint32_t>> transInfos;
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
std::vector<uint32_t> info;
for (const auto& [id, sinkInfo] : sinkInfos) {
for (const auto &[id, sinkInfo] : sinkInfos) {
info.clear();
info.emplace_back(sinkInfo.transformInfo.sinkWinPhyX);
info.emplace_back(sinkInfo.transformInfo.sinkWinPhyY);
@@ -945,7 +945,7 @@ void DistributedInputSinkManager::CallBackScreenInfoChange()
}
nlohmann::json screenMsg(transInfos);
std::string str = screenMsg.dump();
for (const auto& iter : getSinkScreenInfosCallbacks_) {
for (const auto &iter : getSinkScreenInfosCallbacks_) {
iter->OnResult(str);
}
}
@@ -957,7 +957,7 @@ void DistributedInputSinkManager::CleanExceptionalInfo(const SrcScreenInfo &srcS
int32_t sessionId = srcScreenInfo.sessionId;
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
for (const auto& [id, sinkInfo] : sinkInfos) {
for (const auto &[id, sinkInfo] : sinkInfos) {
auto srcInfo = sinkInfo.srcScreenInfo;
if ((std::strcmp(srcInfo.uuid.c_str(), uuid.c_str()) == 0) && (srcInfo.sessionId != sessionId)) {
DInputContext::GetInstance().RemoveSinkScreenInfo(id);
@@ -54,7 +54,7 @@ public:
void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId,
const std::string &sinkNodeDesc);
void GetVirtualKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds);
std::vector<std::string> &virKeyboardPaths, std::vector<std::string> &virKeyboardDhIds);
private:
DistributedInputInject();
@@ -34,7 +34,7 @@
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
const uint32_t DINPUT_NODE_MANAGER_SCAN_ALL_NODE = 1;
constexpr uint32_t DINPUT_NODE_MANAGER_SCAN_ALL_NODE = 1;
const std::string INPUT_NODE_DHID = "dhId";
class DistributedInputNodeManager {
public:
@@ -59,7 +59,7 @@ public:
void ProcessInjectEvent(const std::shared_ptr<RawEvent> &rawEvent);
void GetVirtualKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds);
std::vector<std::string> &virKeyboardPaths, std::vector<std::string> &virKeyboardDhIds);
void NotifyNodeMgrScanVirNode(const std::string &dhId);
class DInputNodeManagerEventHandler : public AppExecFwk::EventHandler {
@@ -89,7 +89,7 @@ private:
void OpenInputDevice(const std::string &devicePath, const std::string &dhId);
bool IsVirtualDev(int fd);
bool GetDevDhIdByFd(int fd, std::string &dhId, std::string &physicalPath);
void SetPathForDevMap(std::string &dhId, const std::string &devicePath);
void SetPathForDevMap(const std::string &dhId, const std::string &devicePath);
/* the key is dhId, and the value is virtualDevice */
std::map<std::string, std::unique_ptr<VirtualDevice>> virtualDeviceMap_;
@@ -39,11 +39,11 @@ public:
bool DoIoctl(int32_t fd, int32_t request, const uint32_t value);
bool CreateKey(const InputDevice &inputDevice);
void SetABSInfo(struct uinput_user_dev &inputUserDev, const InputDevice &inputDevice);
bool SetPhys(const std::string deviceName, std::string dhId);
bool SetPhys(const std::string &deviceName, const std::string &dhId);
bool SetUp(const InputDevice &inputDevice, const std::string &devId, const std::string &dhId);
bool InjectInputEvent(const input_event &event);
void SetNetWorkId(const std::string netWorkId);
void SetPath(const std::string path);
void SetNetWorkId(const std::string &netWorkId);
void SetPath(const std::string &path);
std::string GetNetWorkId();
std::string GetPath();
uint16_t GetClasses();
@@ -55,7 +55,7 @@ private:
int32_t fd_ = -1;
std::string deviceName_;
std::string netWorkId_;
std::string path_ {""};
std::string path_;
const uint16_t busType_;
const uint16_t vendorId_;
const uint16_t productId_;
@@ -257,14 +257,14 @@ int32_t DistributedInputInject::GetVirtualTouchScreenFd()
}
void DistributedInputInject::GetVirtualKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds)
std::vector<std::string> &virKeyboardPaths, std::vector<std::string> &virKeyboardDhIds)
{
std::lock_guard<std::mutex> lock(inputNodeManagerMutex_);
if (inputNodeManager_ == nullptr) {
DHLOGE("inputNodeManager is nullptr");
return;
}
inputNodeManager_->GetVirtualKeyboardPathsByDhIds(dhIds, shareDhidsPaths, shareDhIds);
inputNodeManager_->GetVirtualKeyboardPathsByDhIds(dhIds, virKeyboardPaths, virKeyboardDhIds);
}
void DistributedInputInject::NotifyNodeMgrScanVirNode(const std::string &dhId)
@@ -230,7 +230,7 @@ bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string &dhId, std:
return true;
}
void DistributedInputNodeManager::SetPathForDevMap(std::string &dhId, const std::string &devicePath)
void DistributedInputNodeManager::SetPathForDevMap(const std::string &dhId, const std::string &devicePath)
{
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
auto iter = virtualDeviceMap_.begin();
@@ -268,22 +268,22 @@ void DistributedInputNodeManager::OpenInputDevice(const std::string &devicePath,
}
void DistributedInputNodeManager::GetVirtualKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &shareDhidsPaths, std::vector<std::string> &shareDhIds)
std::vector<std::string> &virKeyboardPaths, std::vector<std::string> &virKeyboardDhIds)
{
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
for (auto dhId_ : dhIds) {
for (const auto &dhId : dhIds) {
auto iter = virtualDeviceMap_.begin();
while (iter != virtualDeviceMap_.end()) {
if (iter->second == nullptr) {
DHLOGE("device is nullptr");
continue;
}
if ((iter->first.compare(dhId_) == 0) &&
if ((iter->first.compare(dhId) == 0) &&
((iter->second->GetClasses() & INPUT_DEVICE_CLASS_KEYBOARD) != 0)) {
DHLOGI("Found vir keyboard path %s, dhid %s", iter->second->GetPath().c_str(),
GetAnonyString(dhId_).c_str());
shareDhidsPaths.push_back(iter->second->GetPath());
shareDhIds.push_back(dhId_);
GetAnonyString(dhId).c_str());
virKeyboardPaths.push_back(iter->second->GetPath());
virKeyboardDhIds.push_back(dhId);
}
iter++;
}
@@ -101,7 +101,7 @@ void VirtualDevice::SetABSInfo(struct uinput_user_dev &inputUserDev, const Input
}
}
bool VirtualDevice::SetPhys(const std::string deviceName, std::string dhId)
bool VirtualDevice::SetPhys(const std::string &deviceName, const std::string &dhId)
{
std::string phys;
phys.append(deviceName).append(pid_).append("/").append(pid_).append("|")
@@ -179,13 +179,13 @@ bool VirtualDevice::InjectInputEvent(const input_event &event)
return true;
}
void VirtualDevice::SetNetWorkId(const std::string netWorkId)
void VirtualDevice::SetNetWorkId(const std::string &netWorkId)
{
DHLOGI("SetNetWorkId %s\n", GetAnonyString(netWorkId).c_str());
netWorkId_ = netWorkId;
}
void VirtualDevice::SetPath(const std::string path)
void VirtualDevice::SetPath(const std::string &path)
{
path_ = path;
}
@@ -255,9 +255,9 @@ void DInputSourceListener::OnResponseStartRemoteInputDhid(
sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON);
}
std::vector<std::string> vecStr;
StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_IN, -1);
std::vector<std::string> devDhIds;
SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_IN, -1);
auto jsonArrayMsg = std::make_shared<nlohmann::json>();
nlohmann::json tmpJson;
@@ -1401,7 +1401,7 @@ void DistributedInputSourceManager::RunWhiteListCallback(const std::string &devI
DHLOGE("addWhiteListCallbacks_ is empty.");
return;
}
for (const auto& it : addWhiteListCallbacks_) {
for (const auto &it : addWhiteListCallbacks_) {
it->OnResult(devId, object);
}
}
@@ -1449,7 +1449,7 @@ void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devI
DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG delWhiteListCallback is null.");
return;
}
for (const auto& it : delWhiteListCallbacks_) {
for (const auto &it : delWhiteListCallbacks_) {
it->OnResult(devId);
}
return;
@@ -1490,7 +1490,7 @@ void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sink
const int32_t &status)
{
std::vector<std::string> dhidsVec;
StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
SplitStringToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_DHID_MSG dhIds:%s, vec-size:%d", GetAnonyString(dhIds).c_str(),
dhidsVec.size());
std::string localNetWorkId = GetLocalNetworkId();
@@ -1512,7 +1512,7 @@ void DistributedInputSourceManager::RunStopDhidCallback(const std::string &sinkI
const int32_t &status)
{
std::vector<std::string> dhidsVec;
StringSplitToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
SplitStringToVector(dhIds, INPUT_STRING_SPLIT_POINT, dhidsVec);
std::string localNetworkId = GetLocalNetworkId();
if (localNetworkId.empty()) {
return;
@@ -1533,7 +1533,7 @@ void DistributedInputSourceManager::RunRelayStartDhidCallback(const std::string
const int32_t status, const std::string &dhids)
{
std::vector<std::string> dhidsVec;
StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec);
SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec);
DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RELAY_STARTDHID_RESULT_MMI dhIds:%s, vec-size:%d",
dhids.c_str(), dhidsVec.size());
bool isCbRun = false;
@@ -1557,7 +1557,7 @@ void DistributedInputSourceManager::RunRelayStopDhidCallback(const std::string &
const int32_t status, const std::string &dhids)
{
std::vector<std::string> dhidsVec;
StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec);
SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, dhidsVec);
bool isCbRun = false;
for (std::vector<DInputClientStopDhidInfo>::iterator iter = relayStpDhidCallbacks_.begin();
iter != relayStpDhidCallbacks_.end(); ++iter) {
@@ -1951,7 +1951,7 @@ void DistributedInputSourceManager::DeviceOfflineListener::DeleteNodeInfoAndNoti
}
std::set<BeRegNodeInfo> nodeSet = sourceManagerContext_->GetSyncNodeInfo(offlineDevId);
std::string localNetWorkId = GetLocalNetworkId();
for (const auto& node : nodeSet) {
for (const auto &node : nodeSet) {
DHLOGI("DeleteNodeInfoAndNotify device: %s, dhId: %s", GetAnonyString(offlineDevId).c_str(),
GetAnonyString(node.dhId).c_str());
// Notify multimodal
@@ -296,9 +296,9 @@ int32_t DistributedInputSourceTransport::StartRemoteInputDhids(int32_t srcTsrcSe
}
DHLOGI("StartRemoteInputDhids srcTsrcSeId:%d, sinkSessionId:%d.", srcTsrcSeId, sinkSessionId);
std::vector<std::string> vecStr;
StringSplitToVector(dhids, INPUT_STRING_SPLIT_POINT, vecStr);
DInputState::GetInstance().RecordDhids(vecStr, DhidState::THROUGH_IN, -1);
std::vector<std::string> devDhIds;
SplitStringToVector(dhids, INPUT_STRING_SPLIT_POINT, devDhIds);
DInputState::GetInstance().RecordDhIds(devDhIds, DhIdState::THROUGH_IN, -1);
nlohmann::json jsonStr;
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_DHID_FOR_REL;
@@ -763,7 +763,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi
}
DHLOGI("StopRemoteInput sessionId:%d.", sessionId);
DInputState::GetInstance().RecordDhids(dhids, DhidState::THROUGH_OUT, -1);
DInputState::GetInstance().RecordDhIds(dhids, DhIdState::THROUGH_OUT, -1);
nlohmann::json jsonStr;
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID;
+15 -17
View File
@@ -21,6 +21,8 @@
#include <string>
#include <linux/input.h>
#include "single_instance.h"
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
@@ -29,40 +31,36 @@ namespace DistributedInput {
* THROUGH_IN : The state indicates the peripheral takes effect on the local device.
* THROUGH_OUT : The state indicates that the peripheral takes effect at the remote device.
*/
enum class DhidState {
enum class DhIdState {
THROUGH_IN = 0,
THROUGH_OUT,
};
class DInputState {
DECLARE_SINGLE_INSTANCE_BASE(DInputState);
public:
static DInputState &GetInstance()
{
static DInputState instance;
return instance;
};
int32_t Init();
int32_t Release();
int32_t RecordDhids(const std::vector<std::string> &dhids, DhidState state, const int32_t &sessionId);
int32_t RemoveDhids(const std::vector<std::string> &dhids);
DhidState GetStateByDhid(std::string &dhid);
int32_t RecordDhIds(const std::vector<std::string> &dhIds, DhIdState state, const int32_t sessionId);
int32_t RemoveDhIds(const std::vector<std::string> &dhIds);
DhIdState GetStateByDhid(const std::string &dhId);
private:
DInputState() = default;
~DInputState();
void CreateSpecialEventInjectThread(const int32_t &sessionId, const std::vector<std::string> &dhids);
void CheckKeyboardState(std::string &dhid, std::string &keyboardNodePath,
std::vector<uint32_t> &keyboardPressedKeys, int &fd);
void SpecEventInject(const int32_t &sessionId, std::vector<std::string> dhids);
void CreateSpecialEventInjectThread(const int32_t sessionId, const std::vector<std::string> &dhIds);
void CheckKeyboardState(const std::string &dhId, const std::string &keyboardNodePath,
std::vector<uint32_t> &pressedKeys, int &fd);
void SpecEventInject(const int32_t sessionId, const std::vector<std::string> &dhIds);
void RecordEventLog(const input_event &event);
void WriteEventToDev(int &fd, const input_event &event);
void CheckMouseKeyState(const int32_t &sessionId, const std::string &mouseNodePath,
void WriteEventToDev(const int fd, const input_event &event);
void SyncMouseKeyState(const int32_t sessionId, const std::string &mouseNodePath,
const std::string &mouseNodeDhId);
private:
std::mutex operationMutex_;
std::map<std::string, DhidState> dhidStateMap_;
std::map<std::string, DhIdState> dhIdStateMap_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
+57 -54
View File
@@ -33,6 +33,7 @@
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
IMPLEMENT_SINGLE_INSTANCE(DInputState);
DInputState::~DInputState()
{
Release();
@@ -47,52 +48,52 @@ int32_t DInputState::Init()
int32_t DInputState::Release()
{
DHLOGI("DInputState Release.");
std::unique_lock<std::mutex> mapLock(operationMutex_);
dhidStateMap_.clear();
std::lock_guard<std::mutex> mapLock(operationMutex_);
dhIdStateMap_.clear();
return DH_SUCCESS;
}
int32_t DInputState::RecordDhids(const std::vector<std::string> &dhids, DhidState state, const int32_t &sessionId)
int32_t DInputState::RecordDhIds(const std::vector<std::string> &dhIds, DhIdState state, const int32_t sessionId)
{
DHLOGI("RecordDhids dhids size = %zu", dhids.size());
std::unique_lock<std::mutex> mapLock(operationMutex_);
for (auto &dhid : dhids) {
DHLOGI("RecordDhIds dhIds size = %zu", dhIds.size());
std::lock_guard<std::mutex> mapLock(operationMutex_);
for (const auto &dhid : dhIds) {
DHLOGD("add dhid : %s, state : %d.", GetAnonyString(dhid).c_str(), state);
dhidStateMap_[dhid] = state;
dhIdStateMap_[dhid] = state;
}
if (state == DhidState::THROUGH_OUT) {
CreateSpecialEventInjectThread(sessionId, dhids);
if (state == DhIdState::THROUGH_OUT) {
CreateSpecialEventInjectThread(sessionId, dhIds);
}
return DH_SUCCESS;
}
int32_t DInputState::RemoveDhids(const std::vector<std::string> &dhids)
int32_t DInputState::RemoveDhIds(const std::vector<std::string> &dhIds)
{
DHLOGI("RemoveDhids dhids size = %zu", dhids.size());
std::unique_lock<std::mutex> mapLock(operationMutex_);
for (auto &dhid : dhids) {
DHLOGI("RemoveDhIds dhIds size = %zu", dhIds.size());
std::lock_guard<std::mutex> mapLock(operationMutex_);
for (const auto &dhid : dhIds) {
DHLOGD("delete dhid : %s", GetAnonyString(dhid).c_str());
dhidStateMap_.erase(dhid);
dhIdStateMap_.erase(dhid);
}
return DH_SUCCESS;
}
DhidState DInputState::GetStateByDhid(std::string &dhid)
DhIdState DInputState::GetStateByDhid(const std::string &dhId)
{
std::unique_lock<std::mutex> mapLock(operationMutex_);
if (dhidStateMap_.find(dhid) == dhidStateMap_.end()) {
DHLOGE("dhid : %s not exist.", GetAnonyString(dhid).c_str());
return DhidState::THROUGH_IN;
std::lock_guard<std::mutex> mapLock(operationMutex_);
if (dhIdStateMap_.find(dhId) == dhIdStateMap_.end()) {
DHLOGE("dhId : %s not exist.", GetAnonyString(dhId).c_str());
return DhIdState::THROUGH_IN;
}
return dhidStateMap_[dhid];
return dhIdStateMap_[dhId];
}
void DInputState::CreateSpecialEventInjectThread(const int32_t &sessionId, const std::vector<std::string> &dhids)
void DInputState::CreateSpecialEventInjectThread(const int32_t sessionId, const std::vector<std::string> &dhIds)
{
DHLOGI("CreateSpecialEventInjectThread enter, dhids.size = %d, sessionId = %d.", dhids.size(), sessionId);
DHLOGI("CreateSpecialEventInjectThread enter, dhIds.size = %d, sessionId = %d.", dhIds.size(), sessionId);
std::thread specEventInjectThread =
std::thread(&DInputState::SpecEventInject, this, sessionId, dhids);
std::thread(&DInputState::SpecEventInject, this, sessionId, dhIds);
int32_t ret = pthread_setname_np(specEventInjectThread.native_handle(), CHECK_KEY_STATUS_THREAD_NAME);
if (ret != 0) {
DHLOGE("specEventInjectThread setname failed.");
@@ -118,7 +119,7 @@ void DInputState::RecordEventLog(const input_event &event)
eventType.c_str(), event.code, event.value);
}
void DInputState::WriteEventToDev(int &fd, const input_event &event)
void DInputState::WriteEventToDev(const int fd, const input_event &event)
{
if (write(fd, &event, sizeof(event)) < static_cast<ssize_t>(sizeof(event))) {
DHLOGE("could not inject event, removed? (fd: %d)", fd);
@@ -127,33 +128,35 @@ void DInputState::WriteEventToDev(int &fd, const input_event &event)
RecordEventLog(event);
}
void DInputState::SpecEventInject(const int32_t &sessionId, std::vector<std::string> dhids)
void DInputState::SpecEventInject(const int32_t sessionId, const std::vector<std::string> &dhIds)
{
DHLOGI("SpecEveInject enter");
DHLOGI("SpecEveInject enter, sessionId %d, dhIds size %d", sessionId, dhIds.size());
// mouse event send to remote device
if (sessionId != -1) {
std::string mouseNodePath;
std::string mouseNodeDhId;
DistributedInputCollector::GetInstance().GetMouseNodePath(dhids, mouseNodePath, mouseNodeDhId);
CheckMouseKeyState(sessionId, mouseNodePath, mouseNodeDhId);
DistributedInputCollector::GetInstance().GetMouseNodePath(dhIds, mouseNodePath, mouseNodeDhId);
SyncMouseKeyState(sessionId, mouseNodePath, mouseNodeDhId);
}
// keyboard up event inject local device
std::vector<std::string> keyboardNodePaths;
std::vector<std::string> keyboardNodeDhIds;
DistributedInputCollector::GetInstance().GetShareKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds);
DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds);
DistributedInputCollector::GetInstance().GetSharedKeyboardPathsByDhIds(dhIds, keyboardNodePaths, keyboardNodeDhIds);
DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhIds, keyboardNodePaths, keyboardNodeDhIds);
size_t len = keyboardNodePaths.size();
for (size_t i = 0; i < len; ++i) {
std::vector<uint32_t> keyboardPressedKeys;
std::vector<uint32_t> pressedKeys;
int fd = UN_INIT_FD_VALUE;
CheckKeyboardState(keyboardNodeDhIds[i], keyboardNodePaths[i], keyboardPressedKeys, fd);
for (auto &code : keyboardPressedKeys) {
struct input_event event = {
.type = EV_KEY,
.code = code,
.value = KEY_UP_STATE
};
CheckKeyboardState(keyboardNodeDhIds[i], keyboardNodePaths[i], pressedKeys, fd);
struct input_event event = {
.type = EV_KEY,
.code = 0,
.value = KEY_UP_STATE
};
for (auto &code : pressedKeys) {
event.type = EV_KEY;
event.code = code;
WriteEventToDev(fd, event);
event.type = EV_SYN;
event.code = 0;
@@ -163,10 +166,10 @@ void DInputState::SpecEventInject(const int32_t &sessionId, std::vector<std::str
}
}
void DInputState::CheckKeyboardState(std::string &dhid, std::string &keyboardNodePath,
std::vector<uint32_t> &keyboardPressedKeys, int &fd)
void DInputState::CheckKeyboardState(const std::string &dhId, const std::string &keyboardNodePath,
std::vector<uint32_t> &pressedKeys, int &fd)
{
DHLOGI("CheckKeyboardState enter, dhid %s, keyboardNodePath %s.", GetAnonyString(dhid).c_str(),
DHLOGI("CheckKeyboardState enter, dhId %s, keyboardNodePath %s.", GetAnonyString(dhId).c_str(),
keyboardNodePath.c_str());
char canonicalPath[PATH_MAX] = {0x00};
if (keyboardNodePath.length() == 0 || keyboardNodePath.length() >= PATH_MAX ||
@@ -181,32 +184,32 @@ void DInputState::CheckKeyboardState(std::string &dhid, std::string &keyboardNod
}
uint32_t count = 0;
unsigned long keystate[NLONGS(KEY_CNT)] = { 0 };
unsigned long keyState[NLONGS(KEY_CNT)] = { 0 };
while (true) {
if (count > READ_RETRY_MAX) {
break;
}
int rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate);
int rc = ioctl(fd, EVIOCGKEY(sizeof(keyState)), keyState);
if (rc < 0) {
DHLOGE("read all key state failed, rc=%d ", rc);
count += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS));
continue;
}
for (int32_t yalv = 0; yalv < KEY_MAX; yalv++) {
if (BitIsSet(keystate, yalv)) {
DHLOGD("yalv = %d, not up.", yalv);
keyboardPressedKeys.push_back(yalv);
for (int32_t keyIndex = 0; keyIndex < KEY_MAX; keyIndex++) {
if (BitIsSet(keyState, keyIndex)) {
DHLOGD("keyIndex = %d, not up.", keyIndex);
pressedKeys.push_back(keyIndex);
}
}
break;
}
}
void DInputState::CheckMouseKeyState(const int32_t &sessionId, const std::string &mouseNodePath,
void DInputState::SyncMouseKeyState(const int32_t sessionId, const std::string &mouseNodePath,
const std::string &mouseNodeDhId)
{
DHLOGI("CheckMouseKeyState enter, mouseNodePath %s, mouseNodeDhId %s, sessionId %d.", mouseNodePath.c_str(),
DHLOGI("SyncMouseKeyState enter, mouseNodePath %s, mouseNodeDhId %s, sessionId %d.", mouseNodePath.c_str(),
GetAnonyString(mouseNodeDhId).c_str(), sessionId);
char canonicalPath[PATH_MAX] = {0x00};
if (mouseNodePath.length() == 0 || mouseNodePath.length() >= PATH_MAX ||
@@ -224,28 +227,28 @@ void DInputState::CheckMouseKeyState(const int32_t &sessionId, const std::string
int leftKeyVal = 0;
int rightKeyVal = 0;
int midKeyVal = 0;
unsigned long keystate[NLONGS(KEY_CNT)] = { 0 };
unsigned long keyState[NLONGS(KEY_CNT)] = { 0 };
while (true) {
if (count > READ_RETRY_MAX) {
break;
}
// Query all key state
int rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate);
int rc = ioctl(fd, EVIOCGKEY(sizeof(keyState)), keyState);
if (rc < 0) {
DHLOGE("read all key state failed, rc=%d ", rc);
count += 1;
std::this_thread::sleep_for(std::chrono::milliseconds(READ_SLEEP_TIME_MS));
continue;
}
leftKeyVal = BitIsSet(keystate, BTN_LEFT);
leftKeyVal = BitIsSet(keyState, BTN_LEFT);
if (leftKeyVal != 0) {
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, mouseNodeDhId, BTN_LEFT);
}
rightKeyVal = BitIsSet(keystate, BTN_RIGHT);
rightKeyVal = BitIsSet(keyState, BTN_RIGHT);
if (rightKeyVal != 0) {
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, mouseNodeDhId, BTN_RIGHT);
}
midKeyVal = BitIsSet(keystate, BTN_MIDDLE);
midKeyVal = BitIsSet(keyState, BTN_MIDDLE);
if (midKeyVal != 0) {
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, mouseNodeDhId, BTN_MIDDLE);
}
@@ -29,6 +29,7 @@
#include "event_handler.h"
#include "nlohmann/json.hpp"
#include "securec.h"
#include "single_instance.h"
#include "dinput_sink_manager_callback.h"
#include "dinput_source_manager_callback.h"
@@ -40,12 +41,9 @@ namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
class DistributedInputTransportBase {
DECLARE_SINGLE_INSTANCE_BASE(DistributedInputTransportBase);
public:
static DistributedInputTransportBase &GetInstance();
~DistributedInputTransportBase();
int32_t Init();
int32_t StartSession(const std::string &remoteDevId);
void StopSession(const std::string &remoteDevId);
@@ -67,6 +65,8 @@ public:
int32_t SendMsg(int32_t sessionId, std::string &message);
private:
DistributedInputTransportBase() = default;
~DistributedInputTransportBase();
int32_t CheckDeviceSessionState(const std::string &remoteDevId);
bool CheckRecivedData(const std::string &message);
void HandleSession(int32_t sessionId, const std::string &message);
@@ -63,13 +63,7 @@ static SessionAttribute g_sessionAttr = {
LINK_TYPE_BR
}
};
DistributedInputTransportBase &DistributedInputTransportBase::GetInstance()
{
static DistributedInputTransportBase instance;
return instance;
}
IMPLEMENT_SINGLE_INSTANCE(DistributedInputTransportBase);
DistributedInputTransportBase::~DistributedInputTransportBase()
{
DHLOGI("Release Transport Session");
+2 -2
View File
@@ -50,9 +50,9 @@ std::string GetNodeDesc(std::string parameters);
std::string GetAnonyString(const std::string &value);
std::string GetAnonyInt32(const int32_t value);
std::string Sha256(const std::string &string);
void CloseFd(int &fd);
void CloseFd(int fd);
int BitIsSet(const unsigned long *array, int bit);
void StringSplitToVector(const std::string &str, const char split, std::vector<std::string> &vecStr);
void SplitStringToVector(const std::string &str, const char split, std::vector<std::string> &vecStr);
int OpenInputDeviceFdByPath(const std::string &devicePath);
std::string ConvertErrNo();
void ScanInputDevicesPath(const std::string &dirName, std::vector<std::string> &vecInputDevPath);
+3 -3
View File
@@ -293,7 +293,7 @@ std::string Sha256(const std::string &in)
return reinterpret_cast<char*>(out);
}
void CloseFd(int &fd)
void CloseFd(int fd)
{
if (fd < 0) {
DHLOGE("No fd need to beclosed.");
@@ -308,10 +308,10 @@ int BitIsSet(const unsigned long *array, int bit)
return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS)));
}
void StringSplitToVector(const std::string &str, const char split, std::vector<std::string> &vecStr)
void SplitStringToVector(const std::string &str, const char split, std::vector<std::string> &vecStr)
{
if (str.empty()) {
DHLOGE("StringSplitToVector param str is error.");
DHLOGE("SplitStringToVector param str is error.");
return;
}
std::string strTmp = str + split;