解决重复初始化的异常问题

Signed-off-by: m30043719 <maxiaodong25@huawei.com>
This commit is contained in:
m30043719 2024-09-03 14:45:18 +08:00
parent 5993af7fb5
commit d3408acb00
6 changed files with 39 additions and 0 deletions

View File

@ -37,6 +37,10 @@ IMPLEMENT_SINGLE_INSTANCE(MMIAdapter);
void MMIAdapter::Init()
{
HILOGI("Init");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
mmiCallback_ = std::make_shared<MMIAdapter::MMIEventCallback>();
eventThread_ = std::thread(&MMIAdapter::StartEvent, this);
std::unique_lock<std::mutex> lock(eventMutex_);

View File

@ -199,6 +199,10 @@ void DSchedContinue::SetEventData()
int32_t DSchedContinue::Init()
{
HILOGI("DSchedContinue init start");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return ERR_OK;
}
auto dContinue = std::shared_ptr<DSchedContinue>(shared_from_this());
stateMachine_ = std::make_shared<DSchedContinueStateMachine>(dContinue);
if (direction_ == CONTINUE_SOURCE) {

View File

@ -52,6 +52,10 @@ IMPLEMENT_SINGLE_INSTANCE(DMSContinueRecvMgr);
void DMSContinueRecvMgr::Init()
{
HILOGI("Init start");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
{
std::shared_ptr<SoftbusAdapterListener> missionBroadcastListener =
std::make_shared<DistributedMissionBroadcastListener>();

View File

@ -53,6 +53,10 @@ IMPLEMENT_SINGLE_INSTANCE(DMSContinueSendMgr);
void DMSContinueSendMgr::Init()
{
HILOGI("Init start");
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
{
MMIAdapter::GetInstance().Init();
SoftbusAdapter::GetInstance().Init();

View File

@ -36,6 +36,10 @@ IMPLEMENT_SINGLE_INSTANCE(SoftbusAdapter);
void SoftbusAdapter::Init()
{
if (eventHandler_ != nullptr) {
HILOGI("Already inited, end.");
return;
}
eventThread_ = std::thread(&SoftbusAdapter::StartEvent, this);
std::unique_lock<std::mutex> lock(eventMutex_);
eventCon_.wait(lock, [this] {

View File

@ -97,6 +97,25 @@ HWTEST_F(DMSContinueManagerTest, testUnInit001, TestSize.Level3)
DTEST_LOG << "DMSContinueManagerTest testUnInit001 end" << std::endl;
}
/**
* @tc.name: testUnInit002
* @tc.desc: test UnInit
* @tc.type: FUNC
* @tc.require: I7F8KH
*/
HWTEST_F(DMSContinueManagerTest, testUnInit002, TestSize.Level3)
{
DTEST_LOG << "DMSContinueManagerTest testUnInit002 begin" << std::endl;
DistributedSchedUtil::MockManageMissions();
DMSContinueSendMgr::GetInstance().Init();
EXPECT_NE(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
DMSContinueSendMgr::GetInstance().UnInit();
EXPECT_EQ(DMSContinueSendMgr::GetInstance().eventHandler_, nullptr);
DTEST_LOG << "DMSContinueManagerTest testUnInit002 end" << std::endl;
}
/**
* @tc.name: testPostUnfocusedTaskWithDelay001
* @tc.desc: test PostUnfocusedTaskWithDelay