From 3a5ff56076d8a0738455c4dc67a0b78fd6fc5e53 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Mon, 29 Jan 2024 20:37:09 +0800 Subject: [PATCH 1/6] Modify Indent Signed-off-by: l30054665 --- .../sink/sinkmanager/src/distributed_input_sink_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 2c87c73..c5126bd 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -619,9 +619,9 @@ int32_t DistributedInputSinkManager::Init() DHLOGI("init InputCollector."); int result = DistributedInputCollector::GetInstance().StartCollectionThread( DistributedInputSinkTransport::GetInstance().GetEventHandler()); - if (result != DH_SUCCESS) { - DHLOGE("init InputCollector error."); - } + if (result != DH_SUCCESS) { + DHLOGE("init InputCollector error."); + } return DH_SUCCESS; } -- Gitee From 536d071ee0a452cafa895c8bd8af49beb9f29690 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 30 Jan 2024 16:37:13 +0800 Subject: [PATCH 2/6] Monitor key changes Signed-off-by: l30054665 --- common/include/input_hub.cpp | 14 ++++++++++++-- services/state/include/dinput_sink_state.h | 1 + services/state/src/dinput_sink_state.cpp | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index ef403e1..c2e6500 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -35,6 +35,7 @@ #include "dinput_log.h" #include "dinput_sink_state.h" #include "dinput_utils_tool.h" +#include "dinput_sink_state.h" namespace OHOS { namespace DistributedHardware { @@ -143,8 +144,17 @@ size_t InputHub::StartCollectInputEvents(RawEvent *buffer, size_t bufferSize) break; } - if (RefreshEpollItem(false) < 0) { - break; + bool flag = false; + std::map dhIdStateMap = DInputSinkState::GetInstance().GetDhIdStateMap(); + for (auto it : dhIdStateMap) { + if (it.second == DhIdState::THROUGH_OUT) { + flag = true; + } else { + flag = false; + } + if (RefreshEpollItem(flag) < 0) { + break; + } } } diff --git a/services/state/include/dinput_sink_state.h b/services/state/include/dinput_sink_state.h index 5844b1f..bfa3cce 100644 --- a/services/state/include/dinput_sink_state.h +++ b/services/state/include/dinput_sink_state.h @@ -47,6 +47,7 @@ public: int32_t RecordDhIds(const std::vector &dhIds, DhIdState state, const int32_t sessionId); int32_t RemoveDhIds(const std::vector &dhIds); DhIdState GetStateByDhid(const std::string &dhId); + std::map GetDhIdStateMap(); void AddKeyDownState(struct RawEvent event); void RemoveKeyDownState(struct RawEvent event); diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 5311a2b..131dbed 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -97,6 +97,11 @@ DhIdState DInputSinkState::GetStateByDhid(const std::string &dhId) return dhIdStateMap_[dhId]; } +std::map DInputSinkState::GetDhIdStateMap() +{ + return dhIdStateMap_; +} + void DInputSinkState::SimulateMouseBtnMouseUpState(const std::string &dhId, const struct RawEvent &event) { DHLOGI("Sinmulate Mouse BTN_MOUSE UP state to source, dhId: %s", dhId.c_str()); -- Gitee From faf9d3b55319a6846c4e074ebaef9e9334c9adbd Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 30 Jan 2024 19:41:26 +0800 Subject: [PATCH 3/6] Monitor key changes Signed-off-by: l30054665 --- common/include/input_hub.cpp | 16 +++++----------- services/state/include/dinput_sink_state.h | 4 +++- services/state/src/dinput_sink_state.cpp | 19 ++++++++++++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index c2e6500..bcb49b4 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -144,17 +144,10 @@ size_t InputHub::StartCollectInputEvents(RawEvent *buffer, size_t bufferSize) break; } - bool flag = false; - std::map dhIdStateMap = DInputSinkState::GetInstance().GetDhIdStateMap(); - for (auto it : dhIdStateMap) { - if (it.second == DhIdState::THROUGH_OUT) { - flag = true; - } else { - flag = false; - } - if (RefreshEpollItem(flag) < 0) { - break; - } + bool flag = DInputSinkState::GetInstance().IsInThroughtOut(); + + if (RefreshEpollItem(flag) < 0) { + break; } } @@ -485,6 +478,7 @@ int32_t InputHub::RefreshEpollItem(bool isSleep) } else { // Some events occurred. pendingEventCount_ = pollResult; + DHLOGE("Number of events is: %d", pollResult); } if (isSleep) { usleep(SLEEP_TIME_US); diff --git a/services/state/include/dinput_sink_state.h b/services/state/include/dinput_sink_state.h index bfa3cce..aa41ec9 100644 --- a/services/state/include/dinput_sink_state.h +++ b/services/state/include/dinput_sink_state.h @@ -47,7 +47,9 @@ public: int32_t RecordDhIds(const std::vector &dhIds, DhIdState state, const int32_t sessionId); int32_t RemoveDhIds(const std::vector &dhIds); DhIdState GetStateByDhid(const std::string &dhId); - std::map GetDhIdStateMap(); + + /* Is some dhid in through out to the other side */ + bool IsInThroughtOut(); void AddKeyDownState(struct RawEvent event); void RemoveKeyDownState(struct RawEvent event); diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 131dbed..01f7eac 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -97,11 +97,6 @@ DhIdState DInputSinkState::GetStateByDhid(const std::string &dhId) return dhIdStateMap_[dhId]; } -std::map DInputSinkState::GetDhIdStateMap() -{ - return dhIdStateMap_; -} - void DInputSinkState::SimulateMouseBtnMouseUpState(const std::string &dhId, const struct RawEvent &event) { DHLOGI("Sinmulate Mouse BTN_MOUSE UP state to source, dhId: %s", dhId.c_str()); @@ -247,6 +242,20 @@ void DInputSinkState::ClearDeviceStates() std::lock_guard mapLock(keyDownStateMapMtx_); keyDownStateMap_.clear(); } + +bool DInputSinkState::IsInThroughtOut() +{ + std::lock_guard mapLock(operationMutex_); + bool flag = false; + for (auto it : dhIdStateMap_) { + if (it.second == DhIdState::THROUGH_OUT) { + flag = true; + break; + } + } + DHLOGI("IsInThroughtOut: %d", flag); + return flag; +} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOSs \ No newline at end of file -- Gitee From e772ea0adbda723e75403ba80cb14cb305dab81b Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 30 Jan 2024 20:21:52 +0800 Subject: [PATCH 4/6] Monitor key changes Signed-off-by: l30054665 --- common/include/input_hub.cpp | 5 ++--- services/state/src/dinput_sink_state.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index bcb49b4..ea541bc 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -145,8 +145,7 @@ size_t InputHub::StartCollectInputEvents(RawEvent *buffer, size_t bufferSize) } bool flag = DInputSinkState::GetInstance().IsInThroughtOut(); - - if (RefreshEpollItem(flag) < 0) { + if (RefreshEpollItem(!flag) < 0) { break; } } @@ -478,7 +477,7 @@ int32_t InputHub::RefreshEpollItem(bool isSleep) } else { // Some events occurred. pendingEventCount_ = pollResult; - DHLOGE("Number of events is: %d", pollResult); + DHLOGD("Number of events is: %d", pollResult); } if (isSleep) { usleep(SLEEP_TIME_US); diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 01f7eac..6bb3265 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -253,7 +253,7 @@ bool DInputSinkState::IsInThroughtOut() break; } } - DHLOGI("IsInThroughtOut: %d", flag); + DHLOGD("IsInThroughtOut: %d", flag); return flag; } } // namespace DistributedInput -- Gitee From 3dfae91d6b5f91a0f1dabae64f6af50b4df339ff Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 30 Jan 2024 20:23:26 +0800 Subject: [PATCH 5/6] change Signed-off-by: l30054665 --- common/include/input_hub.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index ea541bc..f6da779 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -35,7 +35,6 @@ #include "dinput_log.h" #include "dinput_sink_state.h" #include "dinput_utils_tool.h" -#include "dinput_sink_state.h" namespace OHOS { namespace DistributedHardware { -- Gitee From ef180d1d84b7ef0bcddc51ae71d3b20c5c002488 Mon Sep 17 00:00:00 2001 From: l30054665 Date: Tue, 30 Jan 2024 22:25:54 +0800 Subject: [PATCH 6/6] kongge Signed-off-by: l30054665 --- services/state/src/dinput_sink_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 6bb3265..b56ac00 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -251,7 +251,7 @@ bool DInputSinkState::IsInThroughtOut() if (it.second == DhIdState::THROUGH_OUT) { flag = true; break; - } + } } DHLOGD("IsInThroughtOut: %d", flag); return flag; -- Gitee