!79 input死亡监听

Merge pull request !79 from ry521/master
This commit is contained in:
openharmony_ci
2023-10-08 06:40:05 +00:00
committed by Gitee
4 changed files with 114 additions and 4 deletions
@@ -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 &params) override;
int32_t UnsubscribeLocalHardware(const std::string &dhId) override;
void OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote);
void FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject);
public:
@@ -63,10 +65,16 @@ public:
};
private:
class DInputSinkSvrRecipient : public IRemoteObject::DeathRecipient {
public:
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
};
DistributedInputSinkHandler() = default;
~DistributedInputSinkHandler();
OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSinkCallback = nullptr;
sptr<IDistributedSinkInput> dInputSinkProxy_ = nullptr;
sptr<DInputSinkSvrRecipient> sinkSvrRecipient_ = nullptr;
std::mutex proxyMutex_;
std::condition_variable proxyConVar_;
};
@@ -64,9 +64,19 @@ int32_t DistributedInputSinkHandler::InitSink(const std::string &params)
void DistributedInputSinkHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::unique_lock<std::mutex> lock(proxyMutex_);
DHLOGI("DInputSinkHandler FinishStartSA");
std::lock_guard<std::mutex> lock(proxyMutex_);
if (sinkSvrRecipient_ == nullptr) {
DHLOGE("sinkSvrRecipient is nullptr.");
return;
}
remoteObject->AddDeathRecipient(sinkSvrRecipient_);
dInputSinkProxy_ = iface_cast<IDistributedSinkInput>(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,42 @@ void DistributedInputSinkHandler::SALoadSinkCb::OnLoadSystemAbilityFail(int32_t
DHLOGE("DistributedInputSinkHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId);
}
void DistributedInputSinkHandler::DInputSinkSvrRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
if (remote == nullptr) {
DHLOGE("OnRemoteDied remote is nullptr.");
return;
}
DHLOGI("DInputSinkSvrRecipient OnRemoteDied.");
DistributedInputSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote);
}
void DistributedInputSinkHandler::OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote)
{
DHLOGI("DInputSinkHandle OnRemoteSinkSvrDied.");
std::lock_guard<std::mutex> lock(proxyMutex_);
if (dInputSinkProxy_ == nullptr) {
DHLOGE("dInputSinkProxy_ is nullptr.");
return;
}
if (dInputSinkProxy_->AsObject() == nullptr) {
DHLOGE("AsObject is nullptr.");
return;
}
sptr<IRemoteObject> 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();
@@ -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 &params, const sptr<IRemoteObject> &remoteObject);
void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote);
public:
@@ -70,10 +73,17 @@ public:
private:
DistributedInputSourceHandler() = default;
~DistributedInputSourceHandler();
class DInputSourceSvrRecipient : public IRemoteObject::DeathRecipient {
public:
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
};
OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSourceCallback = nullptr;
std::mutex proxyMutex_;
std::condition_variable proxyConVar_;
sptr<IDistributedSourceInput> dInputSourceProxy_ = nullptr;
sptr<LoadDInputSourceCallback> dInputSourceCallback_ = nullptr;
sptr<DInputSourceSvrRecipient> sourceSvrRecipient_ = nullptr;
};
#ifdef __cplusplus
@@ -63,9 +63,19 @@ int32_t DistributedInputSourceHandler::InitSource(const std::string &params)
void DistributedInputSourceHandler::FinishStartSA(const std::string &params, const sptr<IRemoteObject> &remoteObject)
{
DHLOGD("FinishStartSA");
std::unique_lock<std::mutex> lock(proxyMutex_);
DHLOGI("DInputSourceHandle FinishStartSA");
std::lock_guard<std::mutex> lock(proxyMutex_);
if (sourceSvrRecipient_ == nullptr) {
DHLOGE("sourceSvrRecipient is nullptr.");
return;
}
remoteObject->AddDeathRecipient(sourceSvrRecipient_);
dInputSourceProxy_ = iface_cast<IDistributedSourceInput>(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,42 @@ void DistributedInputSourceHandler::SALoadSourceCb::OnLoadSystemAbilityFail(int3
DHLOGE("DistributedInputSourceHandler OnLoadSystemAbilityFail. systemAbilityId=%d", systemAbilityId);
}
void DistributedInputSourceHandler::DInputSourceSvrRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
if (remote == nullptr) {
DHLOGE("OnRemoteDied remote is nullptr.");
return;
}
DHLOGI("DInputSourceSvrRecipient OnRemoteDied.");
DistributedInputSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote);
}
void DistributedInputSourceHandler::OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote)
{
DHLOGI("OnRemoteSourceSvrDied.");
std::lock_guard<std::mutex> lock(proxyMutex_);
if (dInputSourceProxy_ == nullptr) {
DHLOGE("dInputSourceProxy is nullptr.");
return;
}
if (dInputSourceProxy_->AsObject() == nullptr) {
DHLOGE("AsObject is nullptr.");
return;
}
sptr<IRemoteObject> 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();