优化ComponentManger初始化流程

Signed-off-by: li-tiangang4 <litiangang4@huawei.com>
This commit is contained in:
li-tiangang4 2024-09-12 11:28:14 +08:00
parent b3af831f59
commit 76f4d8045b
3 changed files with 13 additions and 23 deletions

View File

@ -36,8 +36,7 @@ namespace DistributedHardware {
constexpr int32_t ERR_DH_FWK_VERSION_DEVICE_ID_NOT_EXIST = -10200;
/* ComponentManager errno, range: [-10300, -10399] */
constexpr int32_t ERR_DH_FWK_COMPONENT_INIT_SOURCE_FAILED = -10300;
constexpr int32_t ERR_DH_FWK_COMPONENT_INIT_SINK_FAILED = -10301;
constexpr int32_t ERR_DH_FWK_COMPONENT_INIT_HANDLER_FAILED = -10301;
constexpr int32_t ERR_DH_FWK_COMPONENT_ENABLE_FAILED = -10302;
constexpr int32_t ERR_DH_FWK_COMPONENT_DISABLE_FAILED = -10303;
constexpr int32_t ERR_DH_FWK_COMPONENT_ENABLE_TIMEOUT = -10304;

View File

@ -91,13 +91,13 @@ int32_t ComponentManager::Init()
DHTraceStart(COMPONENT_INIT_START);
int32_t ret = InitComponentHandler();
if (ret != DH_FWK_SUCCESS) {
DHLOGE("Init Component Handler failed, ret: %d", ret);
DHLOGE("Init Component Handler failed, ret: %{public}d", ret);
return ret;
}
ret = InitSAMonitor();
if (ret != DH_FWK_SUCCESS) {
DHLOGE("Init SA monitor failed, ret: %d", ret);
DHLOGE("Init SA monitor failed, ret: %{public}d", ret);
return ret;
}
@ -115,18 +115,12 @@ int32_t ComponentManager::Init()
int32_t ComponentManager::InitComponentHandler()
{
if (!InitCompSource()) {
DHLOGE("InitCompSource failed.");
DHLOGI("start.");
if (!InitCompSource() && !InitCompSink()) {
DHLOGE("InitComponentHandler failed.");
DHTraceEnd();
return ERR_DH_FWK_COMPONENT_INIT_SOURCE_FAILED;
return ERR_DH_FWK_COMPONENT_INIT_HANDLER_FAILED;
}
if (!InitCompSink()) {
DHLOGE("InitCompSink failed.");
compSource_.clear();
DHTraceEnd();
return ERR_DH_FWK_COMPONENT_INIT_SINK_FAILED;
}
return DH_FWK_SUCCESS;
}

View File

@ -125,22 +125,19 @@ void ComponentManagerTest::TearDown()
HWTEST_F(ComponentManagerTest, init_test_001, TestSize.Level0)
{
auto ret = ComponentManager::GetInstance().Init();
EXPECT_EQ(ERR_DH_FWK_COMPONENT_INIT_SOURCE_FAILED, ret);
EXPECT_EQ(ERR_DH_FWK_COMPONENT_INIT_HANDLER_FAILED, ret);
}
/**
* @tc.name: init_test_002
* @tc.desc: Verify the Init function
* @tc.name: InitComponentHandler_test_001
* @tc.desc: Verify the InitComponentHandler function
* @tc.type: FUNC
* @tc.require: AR000GHSK5
*/
HWTEST_F(ComponentManagerTest, init_test_002, TestSize.Level0)
HWTEST_F(ComponentManagerTest, InitComponentHandler_test_001, TestSize.Level0)
{
MockIDistributedHardwareSource cameraSource;
ComponentManager::GetInstance().compSource_.insert(std::make_pair(DHType::CAMERA, &cameraSource));
auto ret = ComponentManager::GetInstance().Init();
EXPECT_EQ(ERR_DH_FWK_COMPONENT_INIT_SINK_FAILED, ret);
auto ret = ComponentManager::GetInstance().InitComponentHandler();
EXPECT_EQ(ERR_DH_FWK_COMPONENT_INIT_HANDLER_FAILED, ret);
}
/**