diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index 3989f932..5068be78 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -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; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 4bb28b1a..9e791ece 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -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; } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index 2a8232b1..c99d698e 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -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); } /**