From cc7a687057752445b7efad3b57032a51f0aa7028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cry521=E2=80=9D?= Date: Sat, 7 Oct 2023 19:51:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?input=E6=AD=BB=E4=BA=A1=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “ry521” --- .../include/distributed_input_sink_handler.h | 8 ++++ .../src/distributed_input_sink_handler.cpp | 44 ++++++++++++++++++- .../distributed_input_source_handler.h | 10 +++++ .../src/distributed_input_source_handler.cpp | 44 ++++++++++++++++++- 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/sinkhandler/include/distributed_input_sink_handler.h b/sinkhandler/include/distributed_input_sink_handler.h index 58477d3..86090ee 100644 --- a/sinkhandler/include/distributed_input_sink_handler.h +++ b/sinkhandler/include/distributed_input_sink_handler.h @@ -27,6 +27,7 @@ #include "system_ability_load_callback_stub.h" #include "distributed_input_client.h" +#include "i_distributed_sink_input.h" namespace OHOS { namespace DistributedHardware { @@ -38,6 +39,7 @@ public: int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; + void OnRemoteSinkSvrDied(const wptr &remote); void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); public: @@ -63,10 +65,16 @@ public: }; private: + class DInputSinkSvrRecipient : public IRemoteObject::DeathRecipient { + public: + void OnRemoteDied(const wptr &remote) override; + }; DistributedInputSinkHandler() = default; ~DistributedInputSinkHandler(); OHOS::sptr sysSinkCallback = nullptr; + sptr dInputSinkProxy_ = nullptr; + sptr sinkSvrRecipient_ = nullptr; std::mutex proxyMutex_; std::condition_variable proxyConVar_; }; diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index a6a49f5..d8d78de 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -64,9 +64,19 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string ¶ms) void DistributedInputSinkHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { - DHLOGD("FinishStartSA"); + DHLOGI("DInputSinkHandler FinishStartSA"); std::unique_lock lock(proxyMutex_); + if (sinkSvrRecipient_ == nullptr) { + DHLOGE("sinkSvrRecipient is nullptr."); + return; + } + remoteObject -> AddDeathRecipient(sinkSvrRecipient_); + dInputSinkProxy_ = iface_cast(remoteObject); DInputSAManager::GetInstance().SetDInputSinkProxy(remoteObject); + if ((dInputSinkProxy_ == nullptr) || (dInputSinkProxy_ ->AsObject() == nullptr)) { + DHLOGE("Faild to get input sink proxy."); + return; + } DistributedInputClient::GetInstance().InitSink(); proxyConVar_.notify_all(); } @@ -100,6 +110,38 @@ void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilityFail(int32_t DHLOGE("DistributedInputSinkHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId); } +void DistributedInputSinkHandler::DInputSinkSvrRecipient::OnRemoteDied(const wptr &remote) +{ + if (remote == nullptr) { + DHLOGI("OnRemoteDied remote is nullptr."); + return; + } + DHLOGI("DInputSinkSvrRecipient OnRemoteDied."); + DistributedInputSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote); +} + +void DistributedInputSinkHandler::OnRemoteSinkSvrDied(const wptr &remote) +{ + DHLOGI("DInputSinkHandle OnRemoteSinkSvrDied."); + std::lock_guard lock(proxyMutex_); + if (dInputSinkProxy_ == nullptr) { + DHLOGE("dInputSinkProxy_ is nullptr."); + return; + } + sptr remoteObject = remote.promote(); + if (remoteObject == nullptr) { + DHLOGE("OnRemoteDied remote promoted failed"); + return; + } + + if (dInputSinkProxy_ ->AsObject() != remoteObject) { + DHLOGE("OnRemoteSinkSvrDied not found remote object."); + return; + } + dInputSinkProxy_->AsObject()->RemoveDeathRecipient(sinkSvrRecipient_); + dInputSinkProxy_ = nullptr; +} + IDistributedHardwareSink *GetSinkHardwareHandler() { return &DistributedInputSinkHandler::GetInstance(); diff --git a/sourcehandler/include/distributed_input_source_handler.h b/sourcehandler/include/distributed_input_source_handler.h index 3a2e634..fb96f65 100644 --- a/sourcehandler/include/distributed_input_source_handler.h +++ b/sourcehandler/include/distributed_input_source_handler.h @@ -28,6 +28,8 @@ #include "distributed_input_client.h" #include "distributed_input_source_manager.h" +#include "i_distributed_source_input.h" +#include "load_d_input_source_callback.h" namespace OHOS { namespace DistributedHardware { @@ -44,6 +46,7 @@ public: int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) override; void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); + void OnRemoteSourceSvrDied(const wptr &remote); public: @@ -70,10 +73,17 @@ public: private: DistributedInputSourceHandler() = default; ~DistributedInputSourceHandler(); + class DInputSourceSvrRecipient : public IRemoteObject::DeathRecipient { + public: + void OnRemoteDied(const wptr &remote) override; + }; OHOS::sptr sysSourceCallback = nullptr; std::mutex proxyMutex_; std::condition_variable proxyConVar_; + sptr dInputSourceProxy_ = nullptr; + sptr dInputSourceCallback_ = nullptr; + sptr sourceSvrRecipient_ = nullptr; }; #ifdef __cplusplus diff --git a/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp index 55267c8..23d3bdf 100644 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ b/sourcehandler/src/distributed_input_source_handler.cpp @@ -63,9 +63,19 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string ¶ms) void DistributedInputSourceHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { - DHLOGD("FinishStartSA"); + DHLOGI("DInputSourceHandle FinishStartSA"); std::unique_lock lock(proxyMutex_); + if (sourceSvrRecipient_ == nullptr) { + DHLOGE("sourceSvrRecipient is nullptr."); + return; + } + remoteObject -> AddDeathRecipient(sourceSvrRecipient_); + dInputSourceProxy_ = iface_cast(remoteObject); DInputSAManager::GetInstance().SetDInputSourceProxy(remoteObject); + if ((dInputSourceProxy_ == nullptr) || (dInputSourceProxy_ ->AsObject() == nullptr)) { + DHLOGE("Faild to get input source proxy."); + return; + } DistributedInputClient::GetInstance().InitSource(); proxyConVar_.notify_all(); } @@ -107,6 +117,38 @@ void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilityFail(int3 DHLOGE("DistributedInputSourceHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId); } +void DistributedInputSourceHandler::DInputSourceSvrRecipient::OnRemoteDied(const wptr &remote) +{ + if (remote == nullptr) { + DHLOGI("OnRemoteDied remote is nullptr."); + return; + } + DHLOGI("DInputSourceSvrRecipient OnRemoteDied."); + DistributedInputSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote); +} + +void DistributedInputSourceHandler::OnRemoteSourceSvrDied(const wptr &remote) +{ + DHLOGI("OnRemoteSourceSvrDied."); + std::lock_guard lock(proxyMutex_); + if (dInputSourceProxy_ == nullptr) { + DHLOGE("dInputSourceProxy is nullptr."); + return; + } + sptr remoteObject = remote.promote(); + if (remoteObject == nullptr) { + DHLOGE("OnRemoteDied remote promoted failed"); + return; + } + + if (dInputSourceProxy_ ->AsObject() != remoteObject) { + DHLOGE("OnRemoteSourceSvrDied not found remote object."); + return; + } + dInputSourceProxy_->AsObject()->RemoveDeathRecipient(sourceSvrRecipient_); + dInputSourceProxy_ = nullptr; +} + IDistributedHardwareSource *GetSourceHardwareHandler() { return &DistributedInputSourceHandler::GetInstance(); -- Gitee From 5a4234930c482486693bc332b9cb1eab72082a69 Mon Sep 17 00:00:00 2001 From: ry521 Date: Sun, 8 Oct 2023 02:00:22 +0000 Subject: [PATCH 2/5] update sinkhandler/src/distributed_input_sink_handler.cpp. Signed-off-by: ry521 --- sinkhandler/src/distributed_input_sink_handler.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index d8d78de..817b90f 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -65,15 +65,15 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string ¶ms) void DistributedInputSinkHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { DHLOGI("DInputSinkHandler FinishStartSA"); - std::unique_lock lock(proxyMutex_); + std::lock_guard lock(proxyMutex_); if (sinkSvrRecipient_ == nullptr) { DHLOGE("sinkSvrRecipient is nullptr."); return; } - remoteObject -> AddDeathRecipient(sinkSvrRecipient_); + remoteObject->AddDeathRecipient(sinkSvrRecipient_); dInputSinkProxy_ = iface_cast(remoteObject); DInputSAManager::GetInstance().SetDInputSinkProxy(remoteObject); - if ((dInputSinkProxy_ == nullptr) || (dInputSinkProxy_ ->AsObject() == nullptr)) { + if ((dInputSinkProxy_ == nullptr) || (dInputSinkProxy_->AsObject() == nullptr)) { DHLOGE("Faild to get input sink proxy."); return; } @@ -113,7 +113,7 @@ void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilityFail(int32_t void DistributedInputSinkHandler::DInputSinkSvrRecipient::OnRemoteDied(const wptr &remote) { if (remote == nullptr) { - DHLOGI("OnRemoteDied remote is nullptr."); + DHLOGE("OnRemoteDied remote is nullptr."); return; } DHLOGI("DInputSinkSvrRecipient OnRemoteDied."); -- Gitee From 1feebc3ba5b3bef5162728fea227a3262f3c5345 Mon Sep 17 00:00:00 2001 From: ry521 Date: Sun, 8 Oct 2023 02:03:51 +0000 Subject: [PATCH 3/5] update sourcehandler/src/distributed_input_source_handler.cpp. Signed-off-by: ry521 --- sourcehandler/src/distributed_input_source_handler.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp index 23d3bdf..7de6d30 100644 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ b/sourcehandler/src/distributed_input_source_handler.cpp @@ -64,15 +64,15 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string ¶ms) void DistributedInputSourceHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { DHLOGI("DInputSourceHandle FinishStartSA"); - std::unique_lock lock(proxyMutex_); + std::lock_guard lock(proxyMutex_); if (sourceSvrRecipient_ == nullptr) { DHLOGE("sourceSvrRecipient is nullptr."); return; } - remoteObject -> AddDeathRecipient(sourceSvrRecipient_); + remoteObject->AddDeathRecipient(sourceSvrRecipient_); dInputSourceProxy_ = iface_cast(remoteObject); DInputSAManager::GetInstance().SetDInputSourceProxy(remoteObject); - if ((dInputSourceProxy_ == nullptr) || (dInputSourceProxy_ ->AsObject() == nullptr)) { + if ((dInputSourceProxy_ == nullptr) || (dInputSourceProxy_->AsObject() == nullptr)) { DHLOGE("Faild to get input source proxy."); return; } @@ -120,7 +120,7 @@ void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilityFail(int3 void DistributedInputSourceHandler::DInputSourceSvrRecipient::OnRemoteDied(const wptr &remote) { if (remote == nullptr) { - DHLOGI("OnRemoteDied remote is nullptr."); + DHLOGE("OnRemoteDied remote is nullptr."); return; } DHLOGI("DInputSourceSvrRecipient OnRemoteDied."); @@ -141,7 +141,7 @@ void DistributedInputSourceHandler::OnRemoteSourceSvrDied(const wptrAsObject() != remoteObject) { + if (dInputSourceProxy_->AsObject() != remoteObject) { DHLOGE("OnRemoteSourceSvrDied not found remote object."); return; } -- Gitee From 3f618a7b23a153d71fe67569cdc938f8ca47c371 Mon Sep 17 00:00:00 2001 From: ry521 Date: Sun, 8 Oct 2023 02:15:22 +0000 Subject: [PATCH 4/5] update sourcehandler/src/distributed_input_source_handler.cpp. Signed-off-by: ry521 --- sourcehandler/src/distributed_input_source_handler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sourcehandler/src/distributed_input_source_handler.cpp b/sourcehandler/src/distributed_input_source_handler.cpp index 7de6d30..b5b7c7c 100644 --- a/sourcehandler/src/distributed_input_source_handler.cpp +++ b/sourcehandler/src/distributed_input_source_handler.cpp @@ -135,6 +135,10 @@ void DistributedInputSourceHandler::OnRemoteSourceSvrDied(const wptrAsObject() == nullptr) { + DHLOGE("AsObject is nullptr."); + return; + } sptr remoteObject = remote.promote(); if (remoteObject == nullptr) { DHLOGE("OnRemoteDied remote promoted failed"); -- Gitee From fb9cd5843a2c60c4fc5d204926096150c401abf1 Mon Sep 17 00:00:00 2001 From: ry521 Date: Sun, 8 Oct 2023 02:17:28 +0000 Subject: [PATCH 5/5] update sinkhandler/src/distributed_input_sink_handler.cpp. Signed-off-by: ry521 --- sinkhandler/src/distributed_input_sink_handler.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sinkhandler/src/distributed_input_sink_handler.cpp b/sinkhandler/src/distributed_input_sink_handler.cpp index 817b90f..20a5a13 100644 --- a/sinkhandler/src/distributed_input_sink_handler.cpp +++ b/sinkhandler/src/distributed_input_sink_handler.cpp @@ -128,13 +128,17 @@ void DistributedInputSinkHandler::OnRemoteSinkSvrDied(const wptr DHLOGE("dInputSinkProxy_ is nullptr."); return; } + if (dInputSinkProxy_->AsObject() == nullptr) { + DHLOGE("AsObject is nullptr."); + return; + } sptr remoteObject = remote.promote(); if (remoteObject == nullptr) { DHLOGE("OnRemoteDied remote promoted failed"); return; } - if (dInputSinkProxy_ ->AsObject() != remoteObject) { + if (dInputSinkProxy_->AsObject() != remoteObject) { DHLOGE("OnRemoteSinkSvrDied not found remote object."); return; } -- Gitee