代码优化

issue: https://gitee.com/openharmony/ability_dmsfwk/issues/I8N0IR

Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
m30043719 2023-12-09 15:36:18 +08:00
parent eb9fd313ef
commit 34a049bca9
7 changed files with 76 additions and 6 deletions

View File

@ -83,6 +83,7 @@ ohos_shared_library("distributedschedsvr") {
"src/distributedWant/distributed_want_params.cpp",
"src/distributedWant/distributed_want_params_wrapper.cpp",
"src/distributed_device_node_listener.cpp",
"src/distributed_event_died_listener.cpp",
"src/distributed_sched_adapter.cpp",
"src/distributed_sched_continuation.cpp",
"src/distributed_sched_dumper.cpp",

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DISTRIBUTED_EVENT_DEID_LISTENER_H
#define OHOS_DISTRIBUTED_EVENT_DEID_LISTENER_H
#include "iremote_object.h"
namespace OHOS {
namespace DistributedSchedule {
class DistributedEventDiedListener : public IRemoteObject::DeathRecipient {
public:
DistributedEventDiedListener() = default;
virtual ~DistributedEventDiedListener() = default;
void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // OHOS_DISTRIBUTED_EVENT_DEID_LISTENER_H

View File

@ -20,6 +20,7 @@
#include <map>
#include <mutex>
#include "distributed_event_died_listener.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "refbase.h"
@ -78,6 +79,7 @@ private:
int32_t currSessionId_ = 1;
std::map<int32_t, sptr<IRemoteObject>> continuationMap_;
std::map<std::string, std::vector<sptr<IRemoteObject>>> continuationCallbackMap_;
sptr<DistributedEventDiedListener> diedListener_;
std::map<int32_t, sptr<IRemoteObject>> callbackMap_;
std::map<int32_t, bool> freeInstall_;
std::map<int32_t, bool> cleanMission_;

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributed_event_died_listener.h"
#include "distributed_sched_service.h"
#include "dtbschedmgr_log.h"
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string TAG = "DistributedEventDiedListener";
const std::string DSCHED_EVENT_KEY = "IDSchedEventListener";
}
void DistributedEventDiedListener::OnRemoteDied(const wptr<IRemoteObject>& remote)
{
HILOGI("DistributedEventDiedListener called");
DistributedSchedService::GetInstance().UnRegisterDSchedEventListener(DSCHED_EVENT_KEY, remote.promote());
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -34,6 +34,7 @@ void DSchedContinuation::Init(const FuncContinuationCallback& contCallback)
{
auto runner = EventRunner::Create("dsched_continuation");
continuationHandler_ = std::make_shared<ContinuationHandler>(runner, shared_from_this(), contCallback);
diedListener_ = new DistributedEventDiedListener();
}
bool DSchedContinuation::PushAbilityToken(int32_t sessionId, const sptr<IRemoteObject>& abilityToken)
@ -135,7 +136,7 @@ bool DSchedContinuation::IsInContinuationProgress(int32_t missionId)
std::lock_guard<std::mutex> autoLock(continuationLock_);
auto iterSession = callbackMap_.find(missionId);
if (iterSession != callbackMap_.end()) {
HILOGE("Continuation in progress, missionId:%{public}d exist!", missionId);
HILOGW("Continuation in progress, missionId:%{public}d exist!", missionId);
return true;
}
return false;
@ -167,12 +168,13 @@ bool DSchedContinuation::PushCallback(const std::string& type, const sptr<IRemot
std::vector<sptr<IRemoteObject>> vecCallback = continuationCallbackMap_[type];
for (auto ele = vecCallback.begin(); ele != vecCallback.end(); ++ele) {
if ((*ele) == callback) {
HILOGE("type:%{public}s, callback is exists!", type.c_str());
HILOGE("type:%{public}s, callback already exists!", type.c_str());
return false;
}
}
vecCallback.push_back(callback);
continuationCallbackMap_[type] = vecCallback;
callback->AddDeathRecipient(diedListener_);
return true;
}
@ -261,7 +263,7 @@ int32_t DSchedContinuation::NotifyDSchedEventResult(const std::string& type, int
HILOGI("GetCallback IDSchedEventListener");
std::vector<sptr<IRemoteObject>> vecCallback = GetCallback(type);
if (vecCallback.empty()) {
HILOGE("NotifyMissionCenterResult IDSchedEventListener is null");
HILOGW("No listening has been registered, no need to report events");
return INVALID_PARAMETERS_ERR;
}
int32_t error = -1;

View File

@ -344,7 +344,7 @@ int32_t DistributedSchedContinueManager::DealFocusedBusiness(const int32_t missi
info_.currentIsContinuable = isMissionContinuable;
}
if (!isMissionContinuable) {
HILOGE("Mission is not continuable, task abort, missionId: %{public}d", missionId);
HILOGW("Mission is not continuable, task abort, missionId: %{public}d", missionId);
return REMOTE_DEVICE_BIND_ABILITY_ERR;
}
std::string bundleName = info.want.GetBundle();
@ -446,7 +446,7 @@ int32_t DistributedSchedContinueManager::DealUnfocusedBusiness(const int32_t mis
std::string bundleName;
int32_t ret = GetBundleName(missionId, bundleName);
if (ret != ERR_OK) {
HILOGE("Get bundleName failed, mission is not continuable, missionId: %{public}d, ret: %{public}d",
HILOGW("Get bundleName failed, mission is not continuable, missionId: %{public}d, ret: %{public}d",
missionId, ret);
return ret;
}
@ -647,7 +647,7 @@ int32_t DistributedSchedContinueManager::DealSetMissionContinueStateBusiness(con
}
if (!info_.currentIsContinuable) {
HILOGE("mission is not continuable, broadcast task abort, missionId: %{public}d", missionId);
HILOGW("mission is not continuable, broadcast task abort, missionId: %{public}d", missionId);
return INVALID_PARAMETERS_ERR;
}

View File

@ -118,6 +118,7 @@ dtbschedmgr_sources = [
"${distributed_service}/dtbschedmgr/src/distributedWant/distributed_want_params.cpp",
"${distributed_service}/dtbschedmgr/src/distributedWant/distributed_want_params_wrapper.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_device_node_listener.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_event_died_listener.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_adapter.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_continuation.cpp",
"${distributed_service}/dtbschedmgr/src/distributed_sched_dumper.cpp",