change jianshiyijian

Signed-off-by: l30054665 <lishang21@huawei.com>
This commit is contained in:
l30054665
2024-02-02 11:20:47 +08:00
parent 08fbd5698d
commit f1526d1c37
4 changed files with 80 additions and 58 deletions
@@ -18,6 +18,7 @@
#include <atomic>
#include <mutex>
#include <set>
#include "i_distributed_source_input.h"
#include "i_distributed_sink_input.h"
@@ -46,6 +47,11 @@ public:
bool HasDInputSinkProxy();
bool SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject);
void RegisterEventHandler(std::shared_ptr<AppExecFwk::EventHandler> handler);
int32_t RestoreRegisterListenerAndCallback();
void AddSimEventListenerToCache(sptr<ISimulationEventListener> listener);
void RemoveSimEventListenerFromCache(sptr<ISimulationEventListener> listener);
void AddSessionStateCbToCache(const sptr<ISessionStateCallback> callback);
void RemoveSessionStateCbFromCache();
public:
class SystemAbilityListener : public SystemAbilityStatusChangeStub {
@@ -54,6 +60,12 @@ public:
void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
};
private:
std::mutex simEventListenerCacheMtx_;
std::set<sptr<ISimulationEventListener>> simEventListenerCache_;
std::mutex sessionStateCbCacheMtx_;
sptr<ISessionStateCallback> sessionStateCbCache_ = nullptr;
private:
DInputSAManager() = default;
~DInputSAManager() = default;
@@ -115,7 +115,6 @@ public:
void CheckSinkRegisterCallback();
void CheckSharingDhIdsCallback();
void CheckSinkScreenInfoCallback();
int32_t RestoreRegisterListenerAndCallback();
public:
class RegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub {
@@ -191,8 +190,6 @@ private:
sptr<ISimulationEventListener> unregSimulationEventListener_ = nullptr;
std::set<sptr<ISharingDhIdListener>> sharingDhIdListeners_;
std::set<sptr<GetSinkScreenInfosCb>> getSinkScreenInfosCallbacks_;
std::set<sptr<ISimulationEventListener>> addSaListeners_;
sptr<ISessionStateCallback> addSaCallback_ = nullptr;
std::shared_ptr<DistributedInputClient::DInputClientEventHandler> eventHandler_;
@@ -223,8 +220,6 @@ private:
std::mutex sharingDhIdsMtx_;
// sharing local dhids
std::set<std::string> sharingDhIds_;
std::mutex addSaListenersMtx_;
std::mutex addSaCallbackMtx_;
};
} // namespace DistributedInput
} // namespace DistributedHardware
+59 -9
View File
@@ -21,7 +21,6 @@
#include "constants_dinput.h"
#include "dinput_errcode.h"
#include "dinput_log.h"
#include "distributed_input_client.h"
namespace OHOS {
namespace DistributedHardware {
@@ -80,10 +79,6 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent,
DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback();
if (result != DH_SUCCESS) {
DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result);
}
}
if (systemAbilityId == DISTRIBUTED_HARDWARE_INPUT_SINK_SA_ID) {
@@ -96,10 +91,6 @@ void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAb
DInputSAManager::GetInstance().eventHandler_->SendEvent(msgEvent,
DINPUT_CLIENT_HANDLER_MSG_DELAY_TIME, AppExecFwk::EventQueue::Priority::IMMEDIATE);
}
int32_t result = DistributedInputClient::GetInstance().RestoreRegisterListenerAndCallback();
if (result != DH_SUCCESS) {
DHLOGE("sink sa execute RestoreRegisterListenerAndCallback fail, result = %d", result);
}
}
DHLOGI("sa %d is added.", systemAbilityId);
}
@@ -284,6 +275,65 @@ bool DInputSAManager::SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject
}
return true;
}
int32_t DInputSAManager::RestoreRegisterListenerAndCallback()
{
DHLOGI("Restore RegisterPublisherListener");
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
int32_t result = DH_SUCCESS;
std::lock_guard<std::mutex> lock(simEventListenerCacheMtx_);
for (const auto& listener : simEventListenerCache_) {
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret);
}
}
DHLOGI("Restore RegisterSessionStateCb");
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("Restore RegisterSessionStateCb client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
{
std::lock_guard<std::mutex> lock(sessionStateCbCacheMtx_);
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(sessionStateCbCache_);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret);
}
return result;
}
}
void DHFWKSAManager::AddSimEventListenerToCache(sptr<ISimulationEventListener> listener)
{
std::lock_guard<std::mutex> simEventListenerLock(simEventListenerCacheMtx_);
simEventListenerCache_.insert(listener);
}
void DHFWKSAManager::RemoveSimEventListenerFromCache(sptr<ISimulationEventListener> listener)
{
std::lock_guard<std::mutex> simEventListenerLock(simEventListenerCacheMtx_);
simEventListenerCache_.erase(listener);
}
void DHFWKSAManager::AddSessionStateCbToCache(const sptr<ISessionStateCallback> callback)
{
std::lock_guard<std::mutex> sessionStateCbLock(sessionStateCbCacheMtx_);
sessionStateCbCache_ = callback;
}
void DHFWKSAManager::()
{
std::lock_guard<std::mutex> sessionStateCbLock(sessionStateCbCacheMtx_);
sessionStateCbCache_ = nullptr;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -28,6 +28,7 @@
#include "input_check_param.h"
#include "softbus_bus_center.h"
#include "white_list_util.h"
#include "dinput_sa_manager.h"
namespace OHOS {
namespace DistributedHardware {
@@ -128,6 +129,10 @@ void DistributedInputClient::DInputClientEventHandler::ProcessEvent(const AppExe
DHLOGI("DInputClientEventHandler ProcessEvent start eventId:%d.", eventId);
if (eventId == DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG) {
DistributedInputClient::GetInstance().CheckSourceRegisterCallback();
int32_t result = DInputSAManager::GetInstance().RestoreRegisterListenerAndCallback();
if (result != DH_SUCCESS) {
DHLOGE("source sa execute RestoreRegisterListenerAndCallback fail, result = %d", result);
}
return;
}
@@ -581,10 +586,9 @@ int32_t DistributedInputClient::RegisterSimulationEventListener(sptr<ISimulation
}
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
std::lock_guard<std::mutex> lock(addSaListenersMtx_);
if (ret == DH_SUCCESS) {
isSimulationEventCbReg = true;
addSaListeners_.insert(listener);
DInputSAManager::GetInstance().AddSimEventListenerToCache(listener);
} else {
isSimulationEventCbReg = false;
regSimulationEventListener_ = listener;
@@ -609,9 +613,7 @@ int32_t DistributedInputClient::UnregisterSimulationEventListener(sptr<ISimulati
if (ret != DH_SUCCESS) {
DHLOGE("UnregisterSimulationEventListener Failed, ret = %d", ret);
}
std::lock_guard<std::mutex> lock(addSaListenersMtx_);
addSaListeners_.erase(listener);
DInputSAManager::GetInstance().RemoveSimEventListenerFromCache(listener);
return ret;
}
@@ -754,8 +756,7 @@ int32_t DistributedInputClient::RegisterSessionStateCb(sptr<ISessionStateCallbac
DHLOGE("RegisterSessionStateCb callback is null.");
return ERR_DH_INPUT_CLIENT_REGISTER_SESSION_STATE_FAIL;
}
std::lock_guard<std::mutex> lock(addSaCallbackMtx_);
addSaCallback_ = (callback);
DInputSAManager::GetInstance().AddSessionStateCbToCache(listener);
return DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(callback);
}
@@ -765,45 +766,9 @@ int32_t DistributedInputClient::UnregisterSessionStateCb()
DHLOGE("DinputStart client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
std::lock_guard<std::mutex> lock(addSaCallbackMtx_);
addSaCallback_ = nullptr;
DInputSAManager::GetInstance().RemoveSessionStateCbFromCache(listener);
return DInputSAManager::GetInstance().dInputSourceProxy_->UnregisterSessionStateCb();
}
int32_t DistributedInputClient::RestoreRegisterListenerAndCallback()
{
DHLOGI("Restore RegisterPublisherListener");
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("RestoreRegisterSimulationEventListener proxy error, client fail");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
int32_t result = DH_SUCCESS;
std::lock_guard<std::mutex> lock(addSaListenersMtx_);
for (const auto& listener : addSaListeners_) {
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSimulationEventListener(listener);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSimulationEventListener fail, ret = %d", ret);
}
}
DHLOGI("Restore RegisterSessionStateCb");
if (!DInputSAManager::GetInstance().GetDInputSourceProxy()) {
DHLOGE("Restore RegisterSessionStateCb client fail.");
return ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL;
}
{
std::lock_guard<std::mutex> lock(addSaCallbackMtx_);
int32_t ret = DInputSAManager::GetInstance().dInputSourceProxy_->RegisterSessionStateCb(addSaCallback_);
if (ret != DH_SUCCESS) {
result = ret;
DHLOGE("SA execute RegisterSessionStateCb fail, ret = %d", ret);
}
return result;
}
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS