mirror of
https://gitee.com/openharmony/communication_ipc
synced 2025-03-02 13:48:44 +00:00
fix some logic problems
Signed-off-by: wanghaoxu <wanghaoxu1@huawei.com>
This commit is contained in:
parent
74064518ed
commit
3aaaa52df3
@ -169,8 +169,9 @@ private:
|
||||
struct DHandleEntryTxRx *replyMessage);
|
||||
bool ReStartRemoteListener();
|
||||
bool ReGrantPermission(const std::string &sessionName);
|
||||
bool IsSameLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId);
|
||||
// sptr<struct DHandleEntryTxRx> PopLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId);
|
||||
bool IsSameLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId,std::shared_ptr<DHandleEntryTxRx> loadSaItem);
|
||||
std::shared_ptr<struct DHandleEntryTxRx> PopLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId);
|
||||
void DeleteLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId);
|
||||
|
||||
|
||||
|
||||
|
@ -428,38 +428,63 @@ uint16_t DBinderService::AllocFreeSocketPort()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DBinderService::IsSameLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId)
|
||||
bool DBinderService::IsSameLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId,
|
||||
std::shared_ptr<DHandleEntryTxRx> loadSaItem)
|
||||
{
|
||||
if (static_cast<int32_t>(loadSaItem->stubIndex) == systemAbilityId &&
|
||||
loadSaItem->deviceIdInfo.fromDeviceId == srcNetworkId) {
|
||||
DBINDER_LOGI("match succeed");
|
||||
return true;
|
||||
}
|
||||
DBINDER_LOGE("match failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
void DBinderService::DeleteLoadSaItem(const std::string& srcNetworkId, int32_t systemAbilityId)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
for (auto it = loadSaReply_.begin(); it != loadSaReply_.end();) {
|
||||
if (static_cast<int32_t>((*it)->stubIndex) == systemAbilityId && (*it)->deviceIdInfo.fromDeviceId == srcNetworkId) {
|
||||
DBINDER_LOGI("match succeed!");
|
||||
return true;
|
||||
if (static_cast<int32_t>((*it)->stubIndex) == systemAbilityId &&
|
||||
(*it)->deviceIdInfo.fromDeviceId == srcNetworkId) {
|
||||
it = loadSaReply_.erase(it);
|
||||
}
|
||||
}
|
||||
DBINDER_LOGE("there is no target item in loadSaReply_");
|
||||
return false;
|
||||
DBINDER_LOGI("delete complete");
|
||||
}
|
||||
|
||||
std::shared_ptr<DHandleEntryTxRx> DBinderService::PopLoadSaItem(const std::string& srcNetworkId,
|
||||
int32_t systemAbilityId)
|
||||
{
|
||||
auto checkSaItem = [srcNetworkId, systemAbilityId, this](std::shared_ptr<DHandleEntryTxRx> loadSaItem) {
|
||||
return IsSameLoadSaItem(srcNetworkId, systemAbilityId, loadSaItem);
|
||||
};
|
||||
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
auto it = std::find_if(loadSaReply_.begin(), loadSaReply_.end(), checkSaItem);
|
||||
if (it == loadSaReply_.end()) {
|
||||
DBINDER_LOGE("findSaItem failed");
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<DHandleEntryTxRx> replymsg = (*it);
|
||||
it = loadSaReply_.erase(it);
|
||||
return replymsg;
|
||||
}
|
||||
|
||||
void DBinderService::LoadSystemAbilityComplete(const std::string& srcNetworkId, int32_t systemAbilityId,
|
||||
const sptr<IRemoteObject>& remoteObject)
|
||||
{
|
||||
if(remoteObject == nullptr) {
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
if (remoteObject == nullptr) {
|
||||
DBINDER_LOGW("GetSystemAbility from samgr error, saId:%{public}d, srcDevId:%{public}s",
|
||||
systemAbilityId, srcNetworkId.c_str());
|
||||
DeleteLoadSaItem(srcNetworkId, systemAbilityId);
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
std::shared_ptr<DHandleEntryTxRx> replyMessage = nullptr;
|
||||
// sptr<struct DHandleEntryTxRx> replyMessage = PopLoadSaItem(srcNetworkId, systemAbilityId);
|
||||
auto checkSaItem = [this](const std::string& srcNetworkId, int32_t systemAbilityId) {
|
||||
return IsSameLoadSaItem(srcNetworkId, systemAbilityId);
|
||||
};
|
||||
// std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
for (auto it = loadSaReply_.begin(); it != loadSaReply_.end();
|
||||
checkSaItem(srcNetworkId, systemAbilityId)) {
|
||||
std::shared_ptr<DHandleEntryTxRx> replyMessage = (*it);
|
||||
loadSaReply_.erase(it);
|
||||
while(true) {
|
||||
std::shared_ptr<struct DHandleEntryTxRx> replyMessage = PopLoadSaItem(srcNetworkId, systemAbilityId);
|
||||
if (replyMessage == nullptr) {
|
||||
return;
|
||||
}
|
||||
binder_uintptr_t binderObject = replyMessage->binderObject;
|
||||
std::string deviceId = replyMessage->deviceIdInfo.fromDeviceId;
|
||||
IPCObjectProxy *ipcProxy = reinterpret_cast<IPCObjectProxy *>(remoteObject.GetRefPtr());
|
||||
@ -511,20 +536,19 @@ bool DBinderService::OnRemoteInvokerMessage(const struct DHandleEntryTxRx *messa
|
||||
{
|
||||
int32_t systemAbilityId = static_cast<int32_t>(message->stubIndex);
|
||||
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
std::shared_ptr<struct DHandleEntryTxRx> replyMessage = std::make_shared<struct DHandleEntryTxRx>();
|
||||
if (memcpy_s(replyMessage.get(), sizeof(DHandleEntryTxRx), message, sizeof(DHandleEntryTxRx)) != 0) {
|
||||
DBINDER_LOGE("fail to copy memory");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool isSaAvailable = dbinderCallback_->LoadSystemAbilityFromRemote(replyMessage->deviceIdInfo.fromDeviceId,systemAbilityId);
|
||||
bool isSaAvailable = dbinderCallback_->LoadSystemAbilityFromRemote(replyMessage->deviceIdInfo.fromDeviceId,
|
||||
systemAbilityId);
|
||||
if(!isSaAvailable) {
|
||||
DBINDER_LOGE("fail to call the system ability");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::shared_mutex> lockGuard(loadSaMutex_);
|
||||
}
|
||||
loadSaReply_.push_back(std::shared_ptr<struct DHandleEntryTxRx>(replyMessage));
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user