From ab3e882bdc15cd2ef2972224305d5f116a04733d Mon Sep 17 00:00:00 2001 From: xxxx Date: Mon, 29 Aug 2022 20:32:08 +0800 Subject: [PATCH] Description: modify just stop one dhid, all dhid stoped Match-id-6a64fb681bf999b88ac9af4daaf9142e5cd7ac24 --- common/include/input_hub.cpp | 2 +- common/include/input_hub.h | 2 +- .../include/distributed_input_collector.h | 3 ++- .../src/distributed_input_collector.cpp | 4 ++-- .../src/distributed_input_sink_manager.cpp | 15 +++++++++------ .../src/distributed_input_source_manager.cpp | 1 - utils/src/dinput_utils_tool.cpp | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 2fc49aa..7b19bac 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -1032,7 +1032,7 @@ void InputHub::GetDevicesInfoByDhId(std::vector dhidsVec, std::map< } } -bool InputHub::GetAllDevicesStoped() +bool InputHub::IsAllDevicesStoped() { std::unique_lock deviceLock(devicesMutex_); for (const auto &[id, device] : devices_) { diff --git a/common/include/input_hub.h b/common/include/input_hub.h index fb847cd..ef08dca 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -47,7 +47,7 @@ public: void GetDevicesInfoByType(int32_t inputTypes, std::map &datas); void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); void GetShareMousePathByDhId(std::vector dhIds, std::string &path, std::string &dhId); - bool GetAllDevicesStoped(); + bool IsAllDevicesStoped(); void ScanInputDevices(const std::string& dirname); private: diff --git a/services/sink/inputcollector/include/distributed_input_collector.h b/services/sink/inputcollector/include/distributed_input_collector.h index 4382c04..0403fae 100644 --- a/services/sink/inputcollector/include/distributed_input_collector.h +++ b/services/sink/inputcollector/include/distributed_input_collector.h @@ -40,7 +40,8 @@ public: void SetSharingTypes(const uint32_t &inputType); void SetSharingDhIds(bool enabled, std::vector dhIds); void GetMouseNodePath(std::vector dhIds, std::string &mouseNodePath, std::string &dhid); - bool GetAllDevicesStoped(); + // false for sharing device exist, true for all devices stop sharing + bool IsAllDevicesStoped(); private: DistributedInputCollector(); diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 9d72e2c..008114d 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -172,9 +172,9 @@ void DistributedInputCollector::GetMouseNodePath( inputHub_->GetShareMousePathByDhId(dhIds, mouseNodePath, dhid); } -bool DistributedInputCollector::GetAllDevicesStoped() +bool DistributedInputCollector::IsAllDevicesStoped() { - return inputHub_->GetAllDevicesStoped(); + return inputHub_->IsAllDevicesStoped(); } } // namespace DistributedInput } // namespace DistributedHardware diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index f52eb95..8fa0f07 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -171,8 +171,8 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( const int32_t& sessionId, const uint32_t& inputTypes) { - DHLOGI("onStopRemoteInput called, sessionId: %s, inputTypes: %d", - GetAnonyInt32(sessionId).c_str(), inputTypes); + DHLOGI("onStopRemoteInput called, sessionId: %s, inputTypes: %d, curInputTypes: %d", + GetAnonyInt32(sessionId).c_str(), inputTypes, sinkManagerObj_->GetInputTypes()); sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - (sinkManagerObj_->GetInputTypes() & inputTypes)); @@ -185,7 +185,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( std::string smsg = jsonStr.dump(); DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped(); + bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); if (isAllClosed) { DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); if (DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession() == @@ -250,8 +250,11 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(cons StringSplitToSet(strDhids, INPUT_STRING_SPLIT_POINT, setStr); sinkManagerObj_->DeleteStopDhids(sessionId, setStr, stopStr); DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopStr); - DHLOGE("onStopRemoteInputDhid called, sessionId: %d is closed.", sessionId); - DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId); + + if (DistributedInputCollector::GetInstance().IsAllDevicesStoped()) { + DHLOGE("onStopRemoteInputDhid called, all dhid stop sharing, sessionId: %d is closed.", sessionId); + DistributedInputSinkSwitch::GetInstance().StopSwitch(sessionId); + } nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_DHID_ONSTOP; @@ -260,7 +263,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(cons std::string smsg = jsonStr.dump(); DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg); - bool isAllClosed = DistributedInputCollector::GetInstance().GetAllDevicesStoped(); + bool isAllClosed = DistributedInputCollector::GetInstance().IsAllDevicesStoped(); if (isAllClosed) { DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); sinkManagerObj_->SetInputTypes(static_cast(DInputDeviceType::NONE)); diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 3f03e06..8d91821 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -39,7 +39,6 @@ #include "distributed_input_inject.h" #include "distributed_input_source_proxy.h" #include "distributed_input_source_transport.h" -#include "dinput_utils_tool.h" #include "hisysevent_util.h" #include "hidumper.h" #include "ipublisher_listener.h" diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 8770177..4d411d1 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -137,7 +137,7 @@ std::string GetNodeDesc(std::string parameters) nodeName = parObj.at("name").get(); classes = parObj.at("classes").get(); } - return "{ NodeName: " + nodeName + ", classes: " + std::to_string(classes) + " }"; + return "{ nodeName: " + nodeName + ", classes: " + std::to_string(classes) + " }"; } } // namespace DistributedInput } // namespace DistributedHardware