diff --git a/bundle.json b/bundle.json index 5b8a73709cf39522cf6296adba2b1b2befd6597d..190949305c688aba02fdbf94876775ca873e7fdc 100644 --- a/bundle.json +++ b/bundle.json @@ -37,9 +37,12 @@ "bundle_framework", "napi", "dsoftbus", + "drivers_interface_distributed_audio", + "drivers_interface_distributed_camera", "eventhandler", "hitrace", "c_utils", + "hdf_core", "hilog", "cJSON", "samgr", @@ -136,6 +139,7 @@ "header_files": [ "constants.h", "device_type.h", + "dhardware_descriptor.h", "dhardware_ipc_interface_code.h", "distributed_hardware_errno.h", "iav_trans_control_center_callback.h", @@ -144,6 +148,7 @@ "idistributed_hardware_source.h", "idistributed_hardware.h", "ihardware_handler.h", + "ihardware_status_listener.h", "ipublisher_listener.h", "single_instance.h" ], diff --git a/common/utils/include/dhardware_ipc_interface_code.h b/common/utils/include/dhardware_ipc_interface_code.h index 902c02a08ecb3d7636c79101658bd7837834e36e..67a54efcfd1fff84dfcaf595ea2eda40f93836c5 100644 --- a/common/utils/include/dhardware_ipc_interface_code.h +++ b/common/utils/include/dhardware_ipc_interface_code.h @@ -43,6 +43,8 @@ enum class DHMsgInterfaceCode : uint32_t { DISABLE_SINK = 480019, ENABLE_SOURCE = 480020, DISABLE_SOURCE = 480021, + LOAD_HDF = 480022, + UNLOAD_HDF = 480023, NOTIFY_SOURCE_DEVICE_REMOTE_DMSDP_STARTED = 1, }; } // namespace DistributedHardware diff --git a/common/utils/include/distributed_hardware_errno.h b/common/utils/include/distributed_hardware_errno.h index c3c8d47513fde0f2062b4d2928b4b37731d7f8ba..f235ec62d3a16a2ff7c48c1ae6b7724d812e15f6 100644 --- a/common/utils/include/distributed_hardware_errno.h +++ b/common/utils/include/distributed_hardware_errno.h @@ -95,6 +95,11 @@ namespace DistributedHardware { constexpr int32_t ERR_DH_FWK_SERVICE_MSG_INVALID = -10809; constexpr int32_t ERR_DH_FWK_AVTRANS_CALLBACK_IS_NULL = -10810; constexpr int32_t ERR_DH_FWK_GETDISTRIBUTEDHARDWARE_TIMEOUT = -10811; + constexpr int32_t ERR_DH_FWK_STATUS_LISTENER_IS_NULL = -10812; + constexpr int32_t ERR_DH_FWK_REGISTER_HDF_LISTENER_FAIL = -10813; + constexpr int32_t ERR_DH_FWK_LOAD_HDF_FAIL = -10814; + constexpr int32_t ERR_DH_FWK_LOAD_HDF_TIMEOUT = -10815; + constexpr int32_t ERR_DH_FWK_NO_HDF_SUPPORT = -10816; /* AccessManager errno, range: [-10900, -10999] */ constexpr int32_t ERR_DH_FWK_ACCESS_INIT_DM_FAILED = -10900; diff --git a/common/utils/include/idistributed_hardware.h b/common/utils/include/idistributed_hardware.h index e17488b9d7696b128cf587913a2136c18aecbdd9..c46f6431ed80e1784bea150abf1a38956dc66e2e 100644 --- a/common/utils/include/idistributed_hardware.h +++ b/common/utils/include/idistributed_hardware.h @@ -63,6 +63,8 @@ public: virtual int32_t DisableSink(const std::vector &descriptors) = 0; virtual int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) = 0; virtual int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) = 0; + virtual int32_t LoadDistributedHDF(const DHType dhType) = 0; + virtual int32_t UnLoadDistributedHDF(const DHType dhType) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h index d2744e90ae8325ccaf4618ae051ae412b1ce5771..bb7d6678544e9bf9991f774c20b028c4891c7b6c 100644 --- a/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h +++ b/interfaces/inner_kits/include/distributed_hardware_fwk_kit.h @@ -238,6 +238,22 @@ public: */ API_EXPORT int32_t DisableSource(const std::string &networkId, const std::vector &descriptors); + /** + * @brief Load distributed HDF. + * + * @param dhType distributed hardware type. + * @return Returns 0 if success. + */ + API_EXPORT int32_t LoadDistributedHDF(const DHType dhType); + + /** + * @brief Unload distributed HDF. + * + * @param dhType distributed hardware type. + * @return Returns 0 if success. + */ + API_EXPORT int32_t UnLoadDistributedHDF(const DHType dhType); + private: /** * @brief Determine whether the topic is valid. diff --git a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h b/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h index 90937e86472e681bc581ab49c035420aac3309d4..7fba9350aa2e6e319acf3783f4afe9e547aeda88 100644 --- a/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h +++ b/interfaces/inner_kits/include/ipc/distributed_hardware_proxy.h @@ -57,6 +57,8 @@ public: int32_t DisableSink(const std::vector &descriptors) override; int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) override; int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) override; + int32_t LoadDistributedHDF(const DHType dhType) override; + int32_t UnLoadDistributedHDF(const DHType dhType) override; private: int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index 91ea88ca18963ff81e1adff3e1c26a84fde9b169..0d3b02ed123b0d47e4af8c65dbf5daad252846c6 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -380,5 +380,13 @@ int32_t DistributedHardwareFwkKit::DisableSource( } return DHFWKSAManager::GetInstance().GetDHFWKProxy()->DisableSource(networkId, descriptors); } +int32_t DistributedHardwareFwkKit::LoadDistributedHDF(const DHType dhType) +{ + return NO_ERROR; +} +int32_t DistributedHardwareFwkKit::UnLoadDistributedHDF(const DHType dhType) +{ + return NO_ERROR; +} } // DistributedHardware } // OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index 47ee352db885aa38588b58f8b7ae2fa6008c8d69..c1bb07ca70c2845216b454aeca73b6cac459f6d4 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -827,6 +827,14 @@ int32_t DistributedHardwareProxy::DisableSource( return reply.ReadInt32(); } +int32_t DistributedHardwareProxy::LoadDistributedHDF(const DHType dhType) +{ + return NO_ERROR; +} +int32_t DistributedHardwareProxy::UnLoadDistributedHDF(const DHType dhType) +{ + return NO_ERROR; +} int32_t DistributedHardwareProxy::ReadDescriptors(MessageParcel &data, std::vector &descriptors) { int32_t size = data.ReadInt32(); diff --git a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h index 7639175f2aaac9a861f6d58b847f179a0a0785be..0f5f633f943e2e932b4b00f53c6bd7793796216b 100644 --- a/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h +++ b/interfaces/inner_kits/test/unittest/common/ipc/dhfwk_sa_manager/include/dhfwk_sa_manager_test.h @@ -191,6 +191,18 @@ int32_t DisableSource(const std::string &networkId, const std::vector &descriptors); int32_t EnableSource(const std::string &networkId, const std::vector &descriptors); int32_t DisableSource(const std::string &networkId, const std::vector &descriptors); + int32_t LoadDistributedHDF(const DHType dhType); + int32_t UnLoadDistributedHDF(const DHType dhType); }; class TestDistributedHardwareStub2 : public TestDistributedHardwareStub { diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 624c00e18506e9773c76ed065bdb58436fb1439d..50559348202a69d32c1eb87ab1093c707513eeea 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -262,6 +262,7 @@ private: void RecoverAutoEnableSource(DHType dhType); void RecoverActiveEnableSink(DHType dhType); void RecoverActiveEnableSource(DHType dhType); + void ResetHdfLoadRefCount(DHType dhType); private: std::map compSource_; std::shared_mutex compSourceMutex_; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h index c535261565401fe474c15190c31d0aa249706880..840a09fea6165a27eae840793787903b422b5a2d 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_service.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_service.h @@ -62,6 +62,8 @@ public: int32_t DisableSink(const std::vector &descriptors) override; int32_t EnableSource(const std::string &networkId, const std::vector &descriptors) override; int32_t DisableSource(const std::string &networkId, const std::vector &descriptors) override; + int32_t LoadDistributedHDF(const DHType dhType) override; + int32_t UnLoadDistributedHDF(const DHType dhType) override; protected: void OnStart() override; diff --git a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h b/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h index 4f3641d0cdc0715daee986fc27a2adf9bb9027dc..21a325bcf73ee68ccc905289173b2763e1cdaa08 100644 --- a/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h +++ b/services/distributedhardwarefwkservice/include/distributed_hardware_stub.h @@ -50,6 +50,8 @@ private: int32_t DisableSinkInner(MessageParcel &data, MessageParcel &reply); int32_t EnableSourceInner(MessageParcel &data, MessageParcel &reply); int32_t DisableSourceInner(MessageParcel &data, MessageParcel &reply); + int32_t LoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply); + int32_t UnLoadDistributedHDFInner(MessageParcel &data, MessageParcel &reply); int32_t ReadDescriptors(MessageParcel &data, std::vector &descriptors); int32_t WriteDescriptors(MessageParcel &data, const std::vector &descriptors); diff --git a/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h b/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h new file mode 100644 index 0000000000000000000000000000000000000000..fa51ef279d6d624f6eadaf19555bf9c7e051361a --- /dev/null +++ b/services/distributedhardwarefwkservice/include/hdfoperate/daudio_hdf_operate.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2022-2025 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_DAUDIO_HDF_OPERATE_H +#define OHOS_DAUDIO_HDF_OPERATE_H + +#include +#include +#include + +#include "iservstat_listener_hdi.h" +#include "idevmgr_hdi.h" +#include "iservmgr_hdi.h" +#include "single_instance.h" +#include + +namespace OHOS { +namespace DistributedHardware { +const std::string AUDIO_SERVICE_NAME = "daudio_primary_service"; +const std::string AUDIOEXT_SERVICE_NAME = "daudio_ext_service"; +constexpr uint16_t AUDIO_INVALID_VALUE = 0xffff; +constexpr int32_t AUDIO_WAIT_TIME = 5000; +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using OHOS::HDI::ServiceManager::V1_0::IServiceManager; +using OHOS::HDI::ServiceManager::V1_0::IServStatListener; +using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; +using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioManager; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::IDAudioHdfCallback; +using OHOS::HDI::DistributedAudio::Audioext::V2_0::DAudioEvent; + +class FwkDAudioHdfCallback; +class DaudioHdfOperate { +DECLARE_SINGLE_INSTANCE(DaudioHdfOperate); + +public: + int32_t LoadDaudioHDFImpl(); + int32_t UnLoadDaudioHDFImpl(); + void ResetRefCount(); + +private: + int32_t WaitLoadService(const std::string& servName); + OHOS::sptr MakeServStatListener(); + int32_t LoadDevice(); + int32_t UnLoadDevice(); + int32_t RegisterHdfListener(); + int32_t UnRegisterHdfListener(); + +private: + OHOS::sptr devmgr_; + OHOS::sptr servMgr_; + OHOS::sptr audioSrvHdf_; + OHOS::sptr fwkDAudioHdfCallback_; + std::atomic audioServStatus_ = AUDIO_INVALID_VALUE; + std::atomic audioextServStatus_ = AUDIO_INVALID_VALUE; + std::condition_variable hdfOperateCon_; + std::mutex hdfOperateMutex_; + int32_t hdfLoadRef_ = 0; + std::mutex hdfLoadRefMutex_; +}; + +class DAudioHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { +public: + using StatusCallback = std::function; + explicit DAudioHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) + { + } + ~DAudioHdfServStatListener() override = default; + void OnReceive(const ServiceStatus& status) override; + +private: + StatusCallback callback_; +}; + +class FwkDAudioHdfCallback : public IDAudioHdfCallback { +protected: + int32_t NotifyEvent(int32_t devId, const DAudioEvent& event) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DAUDIO_HDF_OPERATE_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h b/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h new file mode 100644 index 0000000000000000000000000000000000000000..f7cf7099081b68713d42667ef789facb5b8f114a --- /dev/null +++ b/services/distributedhardwarefwkservice/include/hdfoperate/dcamera_hdf_operate.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022-2025 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_DCAMERA_HDF_OPERATE_H +#define OHOS_DCAMERA_HDF_OPERATE_H + +#include +#include +#include + +#include "iservstat_listener_hdi.h" +#include "idevmgr_hdi.h" +#include "iservmgr_hdi.h" +#include "single_instance.h" +#include "v1_1/id_camera_provider.h" + +namespace OHOS { +namespace DistributedHardware { +using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; +using OHOS::HDI::ServiceManager::V1_0::IServiceManager; +using OHOS::HDI::ServiceManager::V1_0::IServStatListener; +using OHOS::HDI::ServiceManager::V1_0::ServiceStatus; +using OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub; +using OHOS::HDI::DistributedCamera::V1_1::IDCameraProvider; +using OHOS::HDI::DistributedCamera::V1_1::IDCameraHdfCallback; +using OHOS::HDI::DistributedCamera::V1_1::DCameraHDFEvent; +const std::string CAMERA_SERVICE_NAME = "distributed_camera_service"; +const std::string PROVIDER_SERVICE_NAME = "distributed_camera_provider_service"; +constexpr uint16_t CAMERA_INVALID_VALUE = 0xffff; +constexpr int32_t CAMERA_WAIT_TIME = 2000; + +class FwkDCameraHdfCallback; +class DCameraHdfOperate { +DECLARE_SINGLE_INSTANCE(DCameraHdfOperate); + +public: + int32_t LoadDcameraHDFImpl(); + int32_t UnLoadDcameraHDFImpl(); + void ResetRefCount(); + +private: + int32_t WaitLoadCameraService(); + int32_t WaitLoadProviderService(); + OHOS::sptr MakeServStatListener(); + int32_t LoadDevice(); + int32_t UnLoadDevice(); + int32_t RegisterHdfListener(); + int32_t UnRegisterHdfListener(); + +private: + OHOS::sptr fwkDCameraHdfCallback_; + std::atomic cameraServStatus_ = CAMERA_INVALID_VALUE; + std::atomic providerServStatus_ = CAMERA_INVALID_VALUE; + std::condition_variable hdfOperateCon_; + std::mutex hdfOperateMutex_; + int32_t hdfLoadRef_ = 0; + std::mutex hdfLoadRefMutex_; +}; + +class DCameraHdfServStatListener : public OHOS::HDI::ServiceManager::V1_0::ServStatListenerStub { +public: + using StatusCallback = std::function; + explicit DCameraHdfServStatListener(StatusCallback callback) : callback_(std::move(callback)) + { + } + ~DCameraHdfServStatListener() override = default; + void OnReceive(const ServiceStatus& status) override; + +private: + StatusCallback callback_; +}; + +class FwkDCameraHdfCallback : public IDCameraHdfCallback { +protected: + int32_t NotifyEvent(int32_t devId, const DCameraHDFEvent& event) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_HDF_OPERATE_H \ No newline at end of file diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index bc63bfd32eb30daf8b48eaecc4f66acac5539bc6..d17ecb2c00bb2e9626cde8af8850181d38e7d746 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -550,5 +550,13 @@ int32_t DistributedHardwareService::DisableSource( } return DH_FWK_SUCCESS; } +int32_t DistributedHardwareService::LoadDistributedHDF(const DHType dhType) +{ + return ERR_DH_FWK_NO_HDF_SUPPORT; +} +int32_t DistributedHardwareService::UnLoadDistributedHDF(const DHType dhType) +{ + return ERR_DH_FWK_NO_HDF_SUPPORT; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h index 9e6d4975c98a8056493d3fe57d9a276b27a8c3b7..0f84636a6d9bf163fbaa67b17fe10e681433dba2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwarestub/include/distributed_hardware_stub_test.h @@ -185,6 +185,18 @@ int32_t DisableSource(const std::string &networkId, const std::vector {