From aaff3aaf7b7c6ac107980113f53a37cf4c62c3fb Mon Sep 17 00:00:00 2001 From: liuqian_herb <704938153@qq.com> Date: Mon, 25 Nov 2024 21:10:17 +0800 Subject: [PATCH] =?UTF-8?q?add=20clean=20Signed-off-by:=20zyjjjjjjjjjjjjjj?= =?UTF-8?q?jjj=20zhangyijiu1@huawei.com=20=EF=BC=88cherry=20picked=20commi?= =?UTF-8?q?t=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hci/hdi_service/hci_interface_impl.cpp | 2 -- .../implement/vendor_interface.cpp | 34 +++++++++++++------ .../hdi_service/implement/vendor_interface.h | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/bluetooth/hci/hdi_service/hci_interface_impl.cpp b/bluetooth/hci/hdi_service/hci_interface_impl.cpp index 97694cad15..10ae5bd47b 100644 --- a/bluetooth/hci/hdi_service/hci_interface_impl.cpp +++ b/bluetooth/hci/hdi_service/hci_interface_impl.cpp @@ -106,7 +106,6 @@ int32_t HciInterfaceImpl::Close() callbacks_ = nullptr; } VendorInterface::GetInstance()->CleanUp(); - VendorInterface::DestroyInstance(); return HDF_SUCCESS; } @@ -115,7 +114,6 @@ void HciInterfaceImpl::OnRemoteDied(const wptr &object) HDF_LOGI("HciInterfaceImpl %{public}s", __func__); callbacks_ = nullptr; VendorInterface::GetInstance()->CleanUp(); - VendorInterface::DestroyInstance(); } int32_t HciInterfaceImpl::AddHciDeathRecipient(const sptr& callbackObj) diff --git a/bluetooth/hci/hdi_service/implement/vendor_interface.cpp b/bluetooth/hci/hdi_service/implement/vendor_interface.cpp index 483a47151f..786df0fb97 100644 --- a/bluetooth/hci/hdi_service/implement/vendor_interface.cpp +++ b/bluetooth/hci/hdi_service/implement/vendor_interface.cpp @@ -71,16 +71,16 @@ bool VendorInterface::WatchHciChannel(const ReceiveCallback &receiveCallback) receiveCallback.onScoReceive, std::bind(&VendorInterface::OnEventReceived, this, std::placeholders::_1), receiveCallback.onIsoReceive); - watcher_.AddFdToWatcher(channel[0], std::bind(&Hci::H4Protocol::ReadData, h4, std::placeholders::_1)); + watcher_->AddFdToWatcher(channel[0], std::bind(&Hci::H4Protocol::ReadData, h4, std::placeholders::_1)); hci_ = h4; } else { auto mct = std::make_shared(channel, receiveCallback.onAclReceive, receiveCallback.onScoReceive, std::bind(&VendorInterface::OnEventReceived, this, std::placeholders::_1)); - watcher_.AddFdToWatcher( + watcher_->AddFdToWatcher( channel[hci_channels_t::HCI_ACL_IN], std::bind(&Hci::MctProtocol::ReadAclData, mct, std::placeholders::_1)); - watcher_.AddFdToWatcher( + watcher_->AddFdToWatcher( channel[hci_channels_t::HCI_EVT], std::bind(&Hci::MctProtocol::ReadEventData, mct, std::placeholders::_1)); hci_ = mct; } @@ -130,11 +130,13 @@ bool VendorInterface::Initialize( return false; } + watcher_ = std::make_shared(); + if (!WatchHciChannel(receiveCallback)) { return false; } - if (!watcher_.Start()) { + if (!watcher_->Start()) { HDF_LOGE("watcher start failed."); return false; } @@ -159,9 +161,9 @@ void VendorInterface::CleanUp() HDF_LOGE("VendorInterface::CleanUp, vendorInterface_ is nullptr."); return; } - - watcher_.Stop(); - + if (watcher_ != nullptr) { + watcher_->Stop(); + } vendorInterface_->op(BtOpcodeT::BT_OP_LPM_DISABLE, nullptr); vendorInterface_->op(BtOpcodeT::BT_OP_HCI_CHANNEL_CLOSE, nullptr); vendorInterface_->op(BtOpcodeT::BT_OP_POWER_OFF, nullptr); @@ -172,6 +174,12 @@ void VendorInterface::CleanUp() initializeCompleteCallback_ = nullptr; eventDataCallback_ = nullptr; dlclose(vendorHandle_); + vendorHandle_ = nullptr; + watcher_ = nullptr; + vendorSentOpcode_ = 0; + lpmTimer_ = 0; + wakeupLock_ = false; + activity_ = false; } size_t VendorInterface::SendPacket(Hci::HciPacketType type, const std::vector &packet) @@ -184,7 +192,10 @@ size_t VendorInterface::SendPacket(Hci::HciPacketType type, const std::vector lock(wakeupMutex_); activity_ = true; - watcher_.SetTimeout(std::chrono::milliseconds(lpmTimer_), std::bind(&VendorInterface::WatcherTimeout, this)); + if (watcher_ != nullptr) { + watcher_->SetTimeout( + std::chrono::milliseconds(lpmTimer_), std::bind(&VendorInterface::WatcherTimeout, this)); + } if (!wakeupLock_) { vendorInterface_->op(BtOpcodeT::BT_OP_WAKEUP_LOCK, nullptr); wakeupLock_ = true; @@ -213,9 +224,10 @@ void VendorInterface::OnInitCallback(BtOpResultT result) VendorInterface::GetInstance()->lpmTimer_ = lpmTimer; VendorInterface::GetInstance()->vendorInterface_->op(BtOpcodeT::BT_OP_LPM_ENABLE, nullptr); - - VendorInterface::GetInstance()->watcher_.SetTimeout(std::chrono::milliseconds(lpmTimer), - std::bind(&VendorInterface::WatcherTimeout, VendorInterface::GetInstance())); + if (VendorInterface::GetInstance()->watcher_ != nullptr) { + VendorInterface::GetInstance()->watcher_->SetTimeout(std::chrono::milliseconds(lpmTimer), + std::bind(&VendorInterface::WatcherTimeout, VendorInterface::GetInstance())); + } } void *VendorInterface::OnMallocCallback(int size) diff --git a/bluetooth/hci/hdi_service/implement/vendor_interface.h b/bluetooth/hci/hdi_service/implement/vendor_interface.h index 81c7dc56ce..6ea0bc7407 100644 --- a/bluetooth/hci/hdi_service/implement/vendor_interface.h +++ b/bluetooth/hci/hdi_service/implement/vendor_interface.h @@ -62,7 +62,7 @@ private: void* vendorHandle_ = nullptr; BtVendorInterfaceT *vendorInterface_ = nullptr; static BtVendorCallbacksT vendorCallbacks_; - HciWatcher watcher_; + std::shared_ptr watcher_; std::shared_ptr hci_ = nullptr; uint16_t vendorSentOpcode_ = 0; uint32_t lpmTimer_ = 0; -- Gitee