From 13638bc12db9db2ba1dd7b5ce487136a9ed99a10 Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 17 Nov 2023 20:51:48 +0800 Subject: [PATCH] save obsever with smart ptr Signed-off-by: lee --- frameworks/inner/c_adapter/ohos_bt_gap.cpp | 5 ++- frameworks/inner/src/bluetooth_a2dp_snk.cpp | 16 ++++---- frameworks/inner/src/bluetooth_a2dp_src.cpp | 16 ++++---- frameworks/inner/src/bluetooth_avrcp_ct.cpp | 18 ++++---- frameworks/inner/src/bluetooth_avrcp_tg.cpp | 19 ++++----- frameworks/inner/src/bluetooth_hfp_ag.cpp | 17 +++----- frameworks/inner/src/bluetooth_hfp_hf.cpp | 14 ++++--- frameworks/inner/src/bluetooth_hid_host.cpp | 14 ++++--- frameworks/inner/src/bluetooth_host.cpp | 41 +++++++------------ frameworks/inner/src/bluetooth_opp.cpp | 14 ++++--- frameworks/inner/src/bluetooth_pan.cpp | 14 ++++--- .../js/napi/include/napi_bluetooth_a2dp_snk.h | 2 +- .../js/napi/include/napi_bluetooth_a2dp_src.h | 2 +- .../js/napi/include/napi_bluetooth_avrcp_ct.h | 2 +- .../js/napi/include/napi_bluetooth_avrcp_tg.h | 2 +- .../js/napi/include/napi_bluetooth_hfp_ag.h | 2 +- .../js/napi/include/napi_bluetooth_hfp_hf.h | 2 +- .../js/napi/include/napi_bluetooth_hid_host.h | 2 +- .../js/napi/include/napi_bluetooth_opp.h | 2 +- .../js/napi/include/napi_bluetooth_pan.h | 2 +- .../napi/src/a2dp/napi_bluetooth_a2dp_src.cpp | 8 ++-- .../napi/src/access/napi_bluetooth_access.cpp | 9 ++-- .../connection/napi_bluetooth_connection.cpp | 13 +++--- .../js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp | 9 ++-- .../js/napi/src/hfp/napi_bluetooth_hfp_hf.cpp | 9 ++-- .../napi/src/hid/napi_bluetooth_hid_host.cpp | 15 +++---- .../js/napi/src/napi_bluetooth_a2dp_snk.cpp | 8 ++-- .../js/napi/src/napi_bluetooth_avrcp_ct.cpp | 14 +++---- .../js/napi/src/napi_bluetooth_avrcp_tg.cpp | 8 ++-- frameworks/js/napi/src/napi_bluetooth_opp.cpp | 12 +++--- .../js/napi/src/pan/napi_bluetooth_pan.cpp | 14 +++---- .../inner_api/include/bluetooth_a2dp_snk.h | 4 +- .../inner_api/include/bluetooth_a2dp_src.h | 4 +- .../inner_api/include/bluetooth_avrcp_ct.h | 4 +- .../inner_api/include/bluetooth_avrcp_tg.h | 4 +- .../include/bluetooth_ble_advertiser.h | 16 ++++---- .../inner_api/include/bluetooth_hfp_ag.h | 4 +- .../inner_api/include/bluetooth_hfp_hf.h | 4 +- .../inner_api/include/bluetooth_hid_host.h | 4 +- interfaces/inner_api/include/bluetooth_host.h | 6 +-- interfaces/inner_api/include/bluetooth_opp.h | 4 +- interfaces/inner_api/include/bluetooth_pan.h | 4 +- 42 files changed, 187 insertions(+), 196 deletions(-) diff --git a/frameworks/inner/c_adapter/ohos_bt_gap.cpp b/frameworks/inner/c_adapter/ohos_bt_gap.cpp index 2f557581..412f3b17 100644 --- a/frameworks/inner/c_adapter/ohos_bt_gap.cpp +++ b/frameworks/inner/c_adapter/ohos_bt_gap.cpp @@ -263,8 +263,8 @@ public: } }; -static BluetoothHostObserverWapper g_hostObserver; -static std::shared_ptr g_remoteDeviceObserver; +static std::shared_ptr g_hostObserver = nullptr; +static std::shared_ptr g_remoteDeviceObserver = nullptr; bool EnableBle(void) { @@ -483,6 +483,7 @@ int GapRegisterCallbacks(BtGapCallBacks *func) g_BluetoothHost = &BluetoothHost::GetDefaultHost(); } g_GapCallback = func; + g_hostObserver = std::make_shared(); g_remoteDeviceObserver = std::make_shared(); g_BluetoothHost->RegisterObserver(g_hostObserver); g_BluetoothHost->RegisterRemoteDeviceObserver(g_remoteDeviceObserver); diff --git a/frameworks/inner/src/bluetooth_a2dp_snk.cpp b/frameworks/inner/src/bluetooth_a2dp_snk.cpp index 9cf8ad9f..553dc6ea 100644 --- a/frameworks/inner/src/bluetooth_a2dp_snk.cpp +++ b/frameworks/inner/src/bluetooth_a2dp_snk.cpp @@ -184,18 +184,18 @@ A2dpSink::~A2dpSink() HILOGD("start"); } -void A2dpSink::RegisterObserver(A2dpSinkObserver *observer) +void A2dpSink::RegisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - std::shared_ptr pointer(observer, [](A2dpSinkObserver *) {}); - pimpl->observers_.Register(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Register(observer); } -void A2dpSink::DeregisterObserver(A2dpSinkObserver *observer) +void A2dpSink::DeregisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - std::shared_ptr pointer(observer, [](A2dpSinkObserver *) {}); - pimpl->observers_.Deregister(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Deregister(observer); } int A2dpSink::GetDeviceState(const BluetoothRemoteDevice &device) const diff --git a/frameworks/inner/src/bluetooth_a2dp_src.cpp b/frameworks/inner/src/bluetooth_a2dp_src.cpp index 593d5ab2..2a328c28 100644 --- a/frameworks/inner/src/bluetooth_a2dp_src.cpp +++ b/frameworks/inner/src/bluetooth_a2dp_src.cpp @@ -205,18 +205,18 @@ void A2dpSource::Init() } } -void A2dpSource::RegisterObserver(A2dpSourceObserver *observer) +void A2dpSource::RegisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - std::shared_ptr pointer(observer, [](A2dpSourceObserver *) {}); - pimpl->observers_.Register(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Register(observer); } -void A2dpSource::DeregisterObserver(A2dpSourceObserver *observer) +void A2dpSource::DeregisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - std::shared_ptr pointer(observer, [](A2dpSourceObserver *) {}); - pimpl->observers_.Deregister(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Deregister(observer); } int A2dpSource::GetDevicesByStates(const std::vector &states, std::vector &devices) const diff --git a/frameworks/inner/src/bluetooth_avrcp_ct.cpp b/frameworks/inner/src/bluetooth_avrcp_ct.cpp index 547653d4..b6d01c3c 100644 --- a/frameworks/inner/src/bluetooth_avrcp_ct.cpp +++ b/frameworks/inner/src/bluetooth_avrcp_ct.cpp @@ -979,22 +979,20 @@ void AvrcpController::Init() * REGISTER / UNREGISTER OBSERVER * ******************************************************************/ -void AvrcpController::RegisterObserver(IObserver *observer) +void AvrcpController::RegisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - + HILOGD("enter"); std::lock_guard lock(pimpl->observerMutex_); - std::shared_ptr pointer(observer, [](IObserver *) {}); - pimpl->observers_.Register(pointer); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Register(observer); } -void AvrcpController::UnregisterObserver(IObserver *observer) +void AvrcpController::UnregisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - + HILOGD("enter"); std::lock_guard lock(pimpl->observerMutex_); - std::shared_ptr pointer(observer, [](IObserver *) {}); - pimpl->observers_.Deregister(pointer); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Deregister(observer); } /****************************************************************** diff --git a/frameworks/inner/src/bluetooth_avrcp_tg.cpp b/frameworks/inner/src/bluetooth_avrcp_tg.cpp index 64c3fdf0..adce346e 100644 --- a/frameworks/inner/src/bluetooth_avrcp_tg.cpp +++ b/frameworks/inner/src/bluetooth_avrcp_tg.cpp @@ -215,23 +215,20 @@ int32_t AvrcpTarget::GetDeviceAbsVolumeAbility(const BluetoothRemoteDevice &devi * REGISTER / UNREGISTER OBSERVER * ******************************************************************/ -void AvrcpTarget::RegisterObserver(AvrcpTarget::IObserver *observer) +void AvrcpTarget::RegisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - + HILOGD("enter"); std::lock_guard lock(pimpl->observerMutex_); - std::shared_ptr observerPtr(observer, [](IObserver *) {}); - pimpl->observers_.Register(observerPtr); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Register(observer); } -void AvrcpTarget::UnregisterObserver(AvrcpTarget::IObserver *observer) +void AvrcpTarget::UnregisterObserver(std::shared_ptr observer) { - HILOGI("enter"); - + HILOGD("enter"); std::lock_guard lock(pimpl->observerMutex_); - - std::shared_ptr observerPtr(observer, [](IObserver *) {}); - pimpl->observers_.Deregister(observerPtr); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Deregister(observer); } /****************************************************************** diff --git a/frameworks/inner/src/bluetooth_hfp_ag.cpp b/frameworks/inner/src/bluetooth_hfp_ag.cpp index f87f45c8..3dc6e823 100644 --- a/frameworks/inner/src/bluetooth_hfp_ag.cpp +++ b/frameworks/inner/src/bluetooth_hfp_ag.cpp @@ -682,23 +682,18 @@ int HandsFreeAudioGateway::GetConnectStrategy(const BluetoothRemoteDevice &devic return pimpl->GetConnectStrategy(device, strategy); } -void HandsFreeAudioGateway::RegisterObserver(HandsFreeAudioGatewayObserver *observer) +void HandsFreeAudioGateway::RegisterObserver(std::shared_ptr observer) { HILOGD("enter"); - std::shared_ptr observerPtr(observer, [](HandsFreeAudioGatewayObserver *) {}); - pimpl->RegisterObserver(observerPtr); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->RegisterObserver(observer); } -void HandsFreeAudioGateway::DeregisterObserver(HandsFreeAudioGatewayObserver *observer) +void HandsFreeAudioGateway::DeregisterObserver(std::shared_ptr observer) { HILOGD("enter"); - std::shared_ptr observerPtr(observer, [](HandsFreeAudioGatewayObserver *) {}); - if (pimpl == nullptr) { - HILOGI("pimpl is nullptr!"); - return; - } - pimpl->DeregisterObserver(observerPtr); - HILOGI("end"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->DeregisterObserver(observer); } } // namespace Bluetooth } // namespace OHOS \ No newline at end of file diff --git a/frameworks/inner/src/bluetooth_hfp_hf.cpp b/frameworks/inner/src/bluetooth_hfp_hf.cpp index 37cf1cc4..60b25112 100644 --- a/frameworks/inner/src/bluetooth_hfp_hf.cpp +++ b/frameworks/inner/src/bluetooth_hfp_hf.cpp @@ -831,16 +831,18 @@ std::optional HandsFreeUnit::StartDial( return pimpl->StartDial(device, number); } -void HandsFreeUnit::RegisterObserver(HandsFreeUnitObserver *observer) +void HandsFreeUnit::RegisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](HandsFreeUnitObserver *) {}); - return pimpl->RegisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->RegisterObserver(observer); } -void HandsFreeUnit::DeregisterObserver(HandsFreeUnitObserver *observer) +void HandsFreeUnit::DeregisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](HandsFreeUnitObserver *) {}); - return pimpl->DeregisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->DeregisterObserver(observer); } } // namespace Bluetooth } // namespace OHOS \ No newline at end of file diff --git a/frameworks/inner/src/bluetooth_hid_host.cpp b/frameworks/inner/src/bluetooth_hid_host.cpp index 70e7cd47..67da5608 100644 --- a/frameworks/inner/src/bluetooth_hid_host.cpp +++ b/frameworks/inner/src/bluetooth_hid_host.cpp @@ -384,16 +384,18 @@ int HidHost::GetConnectStrategy(const BluetoothRemoteDevice &device, int &strate return pimpl->GetConnectStrategy(device, strategy); } -void HidHost::RegisterObserver(HidHostObserver *observer) +void HidHost::RegisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](HidHostObserver *) {}); - return pimpl->RegisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->RegisterObserver(observer); } -void HidHost::DeregisterObserver(HidHostObserver *observer) +void HidHost::DeregisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](HidHostObserver *) {}); - return pimpl->DeregisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->DeregisterObserver(observer); } void HidHost::HidHostVCUnplug(std::string device, uint8_t id, uint16_t size, uint8_t type) diff --git a/frameworks/inner/src/bluetooth_host.cpp b/frameworks/inner/src/bluetooth_host.cpp index ff70bfaa..9aa27f43 100644 --- a/frameworks/inner/src/bluetooth_host.cpp +++ b/frameworks/inner/src/bluetooth_host.cpp @@ -468,26 +468,18 @@ BluetoothHost &BluetoothHost::GetDefaultHost() return hostAdapter; } -void BluetoothHost::RegisterObserver(BluetoothHostObserver &observer) +void BluetoothHost::RegisterObserver(std::shared_ptr observer) { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } - - std::shared_ptr pointer(&observer, [](BluetoothHostObserver *) {}); - pimpl->observers_.Register(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Register(observer); } -void BluetoothHost::DeregisterObserver(BluetoothHostObserver &observer) +void BluetoothHost::DeregisterObserver(std::shared_ptr observer) { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } - - std::shared_ptr pointer(&observer, [](BluetoothHostObserver *) {}); - pimpl->observers_.Deregister(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->observers_.Deregister(observer); } void BluetoothHost::Init() @@ -1037,21 +1029,16 @@ bool BluetoothHost::RemoveAllPairs() void BluetoothHost::RegisterRemoteDeviceObserver(std::shared_ptr observer) { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); pimpl->remoteObservers_.Register(observer); } -void BluetoothHost::DeregisterRemoteDeviceObserver(BluetoothRemoteDeviceObserver &observer) +void BluetoothHost::DeregisterRemoteDeviceObserver(std::shared_ptr observer) { - if (!pimpl) { - HILOGE("fails: no pimpl"); - return; - } - std::shared_ptr pointer(&observer, [](BluetoothRemoteDeviceObserver *) {}); - pimpl->remoteObservers_.Deregister(pointer); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->remoteObservers_.Deregister(observer); } int BluetoothHost::GetBleMaxAdvertisingDataLength() const diff --git a/frameworks/inner/src/bluetooth_opp.cpp b/frameworks/inner/src/bluetooth_opp.cpp index 7a83b597..f097beb6 100644 --- a/frameworks/inner/src/bluetooth_opp.cpp +++ b/frameworks/inner/src/bluetooth_opp.cpp @@ -515,16 +515,18 @@ bool Opp::CancelTransfer() return pimpl->CancelTransfer(); } -void Opp::RegisterObserver(OppObserver *observer) +void Opp::RegisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](OppObserver *) {}); - return pimpl->RegisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->RegisterObserver(observer); } -void Opp::DeregisterObserver(OppObserver *observer) +void Opp::DeregisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](OppObserver *) {}); - return pimpl->DeregisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->DeregisterObserver(observer); } } // namespace Bluetooth } // namespace OHOS \ No newline at end of file diff --git a/frameworks/inner/src/bluetooth_pan.cpp b/frameworks/inner/src/bluetooth_pan.cpp index 5487f0e6..6571282e 100644 --- a/frameworks/inner/src/bluetooth_pan.cpp +++ b/frameworks/inner/src/bluetooth_pan.cpp @@ -293,16 +293,18 @@ int32_t Pan::Disconnect(const BluetoothRemoteDevice &device) return pimpl->Disconnect(device); } -void Pan::RegisterObserver(PanObserver *observer) +void Pan::RegisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](PanObserver *) {}); - return pimpl->RegisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->RegisterObserver(observer); } -void Pan::DeregisterObserver(PanObserver *observer) +void Pan::DeregisterObserver(std::shared_ptr observer) { - std::shared_ptr observerPtr(observer, [](PanObserver *) {}); - return pimpl->DeregisterObserver(observerPtr); + HILOGD("enter"); + CHECK_AND_RETURN_LOG(pimpl != nullptr, "pimpl is null."); + pimpl->DeregisterObserver(observer); } int32_t Pan::SetTethering(bool value) diff --git a/frameworks/js/napi/include/napi_bluetooth_a2dp_snk.h b/frameworks/js/napi/include/napi_bluetooth_a2dp_snk.h index 72c8e0be..39ef613d 100644 --- a/frameworks/js/napi/include/napi_bluetooth_a2dp_snk.h +++ b/frameworks/js/napi/include/napi_bluetooth_a2dp_snk.h @@ -37,7 +37,7 @@ public: static napi_value Connect(napi_env env, napi_callback_info info); static napi_value Disconnect(napi_env env, napi_callback_info info); - static NapiA2dpSinkObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_a2dp_src.h b/frameworks/js/napi/include/napi_bluetooth_a2dp_src.h index 1fa68591..87500af4 100644 --- a/frameworks/js/napi/include/napi_bluetooth_a2dp_src.h +++ b/frameworks/js/napi/include/napi_bluetooth_a2dp_src.h @@ -86,7 +86,7 @@ public: static napi_value SetCurrentCodecInfo(napi_env env, napi_callback_info info); static napi_value GetCurrentCodecInfo(napi_env env, napi_callback_info info); #endif - static NapiA2dpSourceObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_avrcp_ct.h b/frameworks/js/napi/include/napi_bluetooth_avrcp_ct.h index 8a2dd5ce..e7392c1e 100644 --- a/frameworks/js/napi/include/napi_bluetooth_avrcp_ct.h +++ b/frameworks/js/napi/include/napi_bluetooth_avrcp_ct.h @@ -36,7 +36,7 @@ public: static napi_value Connect(napi_env env, napi_callback_info info); static napi_value Disconnect(napi_env env, napi_callback_info info); - static NapiAvrcpControllerObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_avrcp_tg.h b/frameworks/js/napi/include/napi_bluetooth_avrcp_tg.h index d471312c..10fbc6ea 100644 --- a/frameworks/js/napi/include/napi_bluetooth_avrcp_tg.h +++ b/frameworks/js/napi/include/napi_bluetooth_avrcp_tg.h @@ -36,7 +36,7 @@ public: static napi_value Connect(napi_env env, napi_callback_info info); static napi_value Disconnect(napi_env env, napi_callback_info info); - static NapiAvrcpTargetObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_hfp_ag.h b/frameworks/js/napi/include/napi_bluetooth_hfp_ag.h index 2f331ba3..cb4321fa 100644 --- a/frameworks/js/napi/include/napi_bluetooth_hfp_ag.h +++ b/frameworks/js/napi/include/napi_bluetooth_hfp_ag.h @@ -48,7 +48,7 @@ public: static napi_value CreateHfpAgProfile(napi_env env, napi_callback_info info); static napi_value DefineCreateProfile(napi_env env, napi_value exports); - static NapiHandsFreeAudioGatewayObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; static thread_local napi_ref consRef_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_hfp_hf.h b/frameworks/js/napi/include/napi_bluetooth_hfp_hf.h index dd82d7bf..d96df083 100644 --- a/frameworks/js/napi/include/napi_bluetooth_hfp_hf.h +++ b/frameworks/js/napi/include/napi_bluetooth_hfp_hf.h @@ -38,7 +38,7 @@ public: static napi_value DisconnectSco(napi_env env, napi_callback_info info); static napi_value SendDTMF(napi_env env, napi_callback_info info); - static NapiHandsFreeUnitObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; diff --git a/frameworks/js/napi/include/napi_bluetooth_hid_host.h b/frameworks/js/napi/include/napi_bluetooth_hid_host.h index 2d0efe42..2afdab87 100644 --- a/frameworks/js/napi/include/napi_bluetooth_hid_host.h +++ b/frameworks/js/napi/include/napi_bluetooth_hid_host.h @@ -41,7 +41,7 @@ public: static napi_value CreateHidHostProfile(napi_env env, napi_callback_info info); static napi_value DefineCreateProfile(napi_env env, napi_value exports); - static NapiBluetoothHidHostObserver observer_; + static std::shared_ptr observer_; static thread_local napi_ref consRef_; }; } // namespace Bluetooth diff --git a/frameworks/js/napi/include/napi_bluetooth_opp.h b/frameworks/js/napi/include/napi_bluetooth_opp.h index d86e48f8..4904714c 100644 --- a/frameworks/js/napi/include/napi_bluetooth_opp.h +++ b/frameworks/js/napi/include/napi_bluetooth_opp.h @@ -35,7 +35,7 @@ public: static napi_value GetConnectionDevices(napi_env env, napi_callback_info info); static napi_value GetDeviceState(napi_env env, napi_callback_info info); - static NapiBluetoothOppObserver observer_; + static std::shared_ptr observer_; static bool isRegistered_; }; } // namespace Bluetooth diff --git a/frameworks/js/napi/include/napi_bluetooth_pan.h b/frameworks/js/napi/include/napi_bluetooth_pan.h index 63afdc52..8453bee6 100644 --- a/frameworks/js/napi/include/napi_bluetooth_pan.h +++ b/frameworks/js/napi/include/napi_bluetooth_pan.h @@ -43,7 +43,7 @@ public: static napi_value DefineCreateProfile(napi_env env, napi_value exports); static thread_local napi_ref consRef_; - static NapiBluetoothPanObserver observer_; + static std::shared_ptr observer_; }; } // namespace Bluetooth } // namespace OHOS diff --git a/frameworks/js/napi/src/a2dp/napi_bluetooth_a2dp_src.cpp b/frameworks/js/napi/src/a2dp/napi_bluetooth_a2dp_src.cpp index 31b2be4f..6cdb20b2 100644 --- a/frameworks/js/napi/src/a2dp/napi_bluetooth_a2dp_src.cpp +++ b/frameworks/js/napi/src/a2dp/napi_bluetooth_a2dp_src.cpp @@ -28,7 +28,7 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiA2dpSourceObserver NapiA2dpSource::observer_; +std::shared_ptr NapiA2dpSource::observer_ = std::make_shared(); bool NapiA2dpSource::isRegistered_ = false; thread_local napi_ref g_napiProfile = nullptr; @@ -150,10 +150,10 @@ napi_value NapiA2dpSource::On(napi_env env, napi_callback_info info) std::unique_lock guard(NapiA2dpSourceObserver::g_a2dpSrcCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { A2dpSource *profile = A2dpSource::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } HILOGI("napi A2dpSource is registered"); @@ -166,7 +166,7 @@ napi_value NapiA2dpSource::Off(napi_env env, napi_callback_info info) std::unique_lock guard(NapiA2dpSourceObserver::g_a2dpSrcCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("Napi A2dpSource is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/access/napi_bluetooth_access.cpp b/frameworks/js/napi/src/access/napi_bluetooth_access.cpp index 58d4d36b..6d419f93 100644 --- a/frameworks/js/napi/src/access/napi_bluetooth_access.cpp +++ b/frameworks/js/napi/src/access/napi_bluetooth_access.cpp @@ -28,7 +28,8 @@ namespace OHOS { namespace Bluetooth { namespace { -NapiBluetoothAccessObserver g_bluetoothAccessObserver; +std::shared_ptr g_bluetoothAccessObserver = + std::make_shared(); } // namespace napi_value NapiAccess::DefineAccessJSFunction(napi_env env, napi_value exports) @@ -198,7 +199,7 @@ napi_value NapiAccess::RegisterAccessObserver(napi_env env, napi_callback_info i std::shared_ptr pCallbackInfo = std::make_shared(); auto status = CheckAccessObserverParams(env, argc, argv, type, pCallbackInfo); NAPI_BT_ASSERT_RETURN_UNDEF(env, status == napi_ok, BT_ERR_INVALID_PARAM); - g_bluetoothAccessObserver.stateChangeCallback = pCallbackInfo; + g_bluetoothAccessObserver->stateChangeCallback = pCallbackInfo; HILOGI("%{public}s is registered", type.c_str()); napi_value ret = nullptr; napi_get_undefined(env, &ret); @@ -214,7 +215,7 @@ static napi_status CheckAccessDeregisterObserver(napi_env env, napi_callback_inf if (argc == ARGS_SIZE_ONE) { std::string type; NAPI_BT_CALL_RETURN(NapiParseObserverType(env, argv[PARAM0], type)); - g_bluetoothAccessObserver.stateChangeCallback = nullptr; + g_bluetoothAccessObserver->stateChangeCallback = nullptr; } else { NAPI_BT_RETURN_IF(argc != ARGS_SIZE_TWO, "Requires 2 arguments.", napi_invalid_arg); std::string type; @@ -224,7 +225,7 @@ static napi_status CheckAccessDeregisterObserver(napi_env env, napi_callback_inf pCallbackInfo->env_ = env; NAPI_BT_CALL_RETURN(NapiIsFunction(env, argv[PARAM1])); NAPI_BT_CALL_RETURN(napi_create_reference(env, argv[PARAM1], 1, &pCallbackInfo->callback_)); - g_bluetoothAccessObserver.stateChangeCallback = nullptr; + g_bluetoothAccessObserver->stateChangeCallback = nullptr; } return napi_ok; } diff --git a/frameworks/js/napi/src/connection/napi_bluetooth_connection.cpp b/frameworks/js/napi/src/connection/napi_bluetooth_connection.cpp index e37d47eb..e4d78688 100644 --- a/frameworks/js/napi/src/connection/napi_bluetooth_connection.cpp +++ b/frameworks/js/napi/src/connection/napi_bluetooth_connection.cpp @@ -28,8 +28,10 @@ namespace OHOS { namespace Bluetooth { -NapiBluetoothConnectionObserver g_connectionObserver; -std::shared_ptr g_remoteDeviceObserver; +std::shared_ptr g_connectionObserver = + std::make_shared(); +std::shared_ptr g_remoteDeviceObserver = + std::make_shared(); std::mutex deviceMutex; std::vector> g_DiscoveryDevices; std::set g_supportRegisterFunc = { @@ -117,7 +119,7 @@ static bool IsValidObserverType(const std::string &callbackName) { if (callbackName == REGISTER_DEVICE_FIND_TYPE || callbackName == REGISTER_PIN_REQUEST_TYPE || callbackName == REGISTER_BOND_STATE_TYPE) { - return true; + return true; } else { HILOGE("not support %{public}s.", callbackName.c_str()); return false; @@ -149,7 +151,7 @@ napi_status CheckRegisterObserver(napi_env env, napi_callback_info info) if (callbackName == REGISTER_BOND_STATE_TYPE) { g_remoteDeviceObserver->RegisterCallback(callbackName, callbackInfo); } else { - g_connectionObserver.RegisterCallback(callbackName, callbackInfo); + g_connectionObserver->RegisterCallback(callbackName, callbackInfo); } return napi_ok; } @@ -177,7 +179,7 @@ napi_status CheckDeRegisterObserver(napi_env env, napi_callback_info info) if (callbackName == REGISTER_BOND_STATE_TYPE) { g_remoteDeviceObserver->DeRegisterCallback(callbackName); } else { - g_connectionObserver.DeRegisterCallback(callbackName); + g_connectionObserver->DeRegisterCallback(callbackName); } return napi_ok; } @@ -781,7 +783,6 @@ napi_value PinTypeInit(napi_env env) void RegisterObserverToHost() { HILOGD("enter"); - g_remoteDeviceObserver = std::make_shared(); BluetoothHost &host = BluetoothHost::GetDefaultHost(); host.RegisterObserver(g_connectionObserver); host.RegisterRemoteDeviceObserver(g_remoteDeviceObserver); diff --git a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp index 16e6eb7b..58d856e7 100644 --- a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp +++ b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_ag.cpp @@ -26,7 +26,8 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiHandsFreeAudioGatewayObserver NapiHandsFreeAudioGateway::observer_; +std::shared_ptr NapiHandsFreeAudioGateway::observer_ = + std::make_shared(); bool NapiHandsFreeAudioGateway::isRegistered_ = false; thread_local napi_ref NapiHandsFreeAudioGateway::consRef_ = nullptr; @@ -101,10 +102,10 @@ napi_value NapiHandsFreeAudioGateway::On(napi_env env, napi_callback_info info) std::unique_lock guard(NapiHandsFreeAudioGatewayObserver::g_handsFreeAudioGatewayCallbackMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { HandsFreeAudioGateway *profile = HandsFreeAudioGateway::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } @@ -118,7 +119,7 @@ napi_value NapiHandsFreeAudioGateway::Off(napi_env env, napi_callback_info info) std::unique_lock guard(NapiHandsFreeAudioGatewayObserver::g_handsFreeAudioGatewayCallbackMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("Hands Free Audio Gateway is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_hf.cpp b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_hf.cpp index 8d484503..46da1eb8 100644 --- a/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_hf.cpp +++ b/frameworks/js/napi/src/hfp/napi_bluetooth_hfp_hf.cpp @@ -21,7 +21,8 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiHandsFreeUnitObserver NapiHandsFreeUnit::observer_; +std::shared_ptr NapiHandsFreeUnit::observer_ = + std::make_shared(); bool NapiHandsFreeUnit::isRegistered_ = false; void NapiHandsFreeUnit::DefineHandsFreeUnitJSClass(napi_env env) @@ -63,10 +64,10 @@ napi_value NapiHandsFreeUnit::On(napi_env env, napi_callback_info info) std::unique_lock guard(NapiHandsFreeUnitObserver::g_handsFreeUnitCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { HandsFreeUnit *profile = HandsFreeUnit::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } @@ -80,7 +81,7 @@ napi_value NapiHandsFreeUnit::Off(napi_env env, napi_callback_info info) std::unique_lock guard(NapiHandsFreeUnitObserver::g_handsFreeUnitCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("Hands Free Unit is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp b/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp index b312c926..fdc2fd5c 100644 --- a/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp +++ b/frameworks/js/napi/src/hid/napi_bluetooth_hid_host.cpp @@ -28,7 +28,8 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiBluetoothHidHostObserver NapiBluetoothHidHost::observer_; +std::shared_ptr NapiBluetoothHidHost::observer_ = + std::make_shared(); thread_local napi_ref NapiBluetoothHidHost::consRef_ = nullptr; void NapiBluetoothHidHost::DefineHidHostJSClass(napi_env env, napi_value exports) @@ -62,7 +63,7 @@ void NapiBluetoothHidHost::DefineHidHostJSClass(napi_env env, napi_value exports napi_new_instance(env, constructor, 0, nullptr, &napiProfile); NapiProfile::SetProfile(env, ProfileId::PROFILE_HID_HOST, napiProfile); HidHost *profile = HidHost::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); #endif HILOGI("finished"); } @@ -86,7 +87,7 @@ napi_value NapiBluetoothHidHost::CreateHidHostProfile(napi_env env, napi_callbac NapiProfile::SetProfile(env, ProfileId::PROFILE_HID_HOST, napiProfile); HidHost *profile = HidHost::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); return napiProfile; } @@ -130,7 +131,7 @@ napi_value NapiBluetoothHidHost::On(napi_env env, napi_callback_info info) return ret; } napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); - observer_.callbackInfos_[type] = callbackInfo; + observer_->callbackInfos_[type] = callbackInfo; HILOGI("%{public}s is registered", type.c_str()); return ret; } @@ -157,11 +158,11 @@ napi_value NapiBluetoothHidHost::Off(napi_env env, napi_callback_info info) return ret; } - if (observer_.callbackInfos_[type] != nullptr) { - std::shared_ptr callbackInfo = observer_.callbackInfos_[type]; + if (observer_->callbackInfos_[type] != nullptr) { + std::shared_ptr callbackInfo = observer_->callbackInfos_[type]; napi_delete_reference(env, callbackInfo->callback_); } - observer_.callbackInfos_[type] = nullptr; + observer_->callbackInfos_[type] = nullptr; HILOGI("%{public}s is unregistered", type.c_str()); return ret; } diff --git a/frameworks/js/napi/src/napi_bluetooth_a2dp_snk.cpp b/frameworks/js/napi/src/napi_bluetooth_a2dp_snk.cpp index 4203912a..d012157f 100644 --- a/frameworks/js/napi/src/napi_bluetooth_a2dp_snk.cpp +++ b/frameworks/js/napi/src/napi_bluetooth_a2dp_snk.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiA2dpSinkObserver NapiA2dpSink::observer_; +std::shared_ptr NapiA2dpSink::observer_ = std::make_shared(); bool NapiA2dpSink::isRegistered_ = false; void NapiA2dpSink::DefineA2dpSinkJSClass(napi_env env) @@ -58,10 +58,10 @@ napi_value NapiA2dpSink::On(napi_env env, napi_callback_info info) std::unique_lock guard(NapiA2dpSinkObserver::g_a2dpSinkCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { A2dpSink *profile = A2dpSink::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } HILOGI("Napi A2dpSink is registered"); @@ -74,7 +74,7 @@ napi_value NapiA2dpSink::Off(napi_env env, napi_callback_info info) std::unique_lock guard(NapiA2dpSinkObserver::g_a2dpSinkCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("napi A2dpSink is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/napi_bluetooth_avrcp_ct.cpp b/frameworks/js/napi/src/napi_bluetooth_avrcp_ct.cpp index 000d49c2..e00bd305 100644 --- a/frameworks/js/napi/src/napi_bluetooth_avrcp_ct.cpp +++ b/frameworks/js/napi/src/napi_bluetooth_avrcp_ct.cpp @@ -21,8 +21,8 @@ namespace OHOS { namespace Bluetooth { using namespace std; - -NapiAvrcpControllerObserver NapiAvrcpController::observer_; +std::shared_ptr NapiAvrcpController::observer_ = + std::make_shared(); bool NapiAvrcpController::isRegistered_ = false; void NapiAvrcpController::DefineAvrcpControllerJSClass(napi_env env) @@ -54,14 +54,14 @@ napi_value NapiAvrcpController::AvrcpControllerConstructor(napi_env env, napi_ca napi_value NapiAvrcpController::On(napi_env env, napi_callback_info info) { - HILOGI("enter"); + HILOGD("enter"); std::unique_lock guard(NapiAvrcpControllerObserver::g_avrcpCtCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { AvrcpController *profile = AvrcpController::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } @@ -71,11 +71,11 @@ napi_value NapiAvrcpController::On(napi_env env, napi_callback_info info) napi_value NapiAvrcpController::Off(napi_env env, napi_callback_info info) { - HILOGI("enter"); + HILOGD("enter"); std::unique_lock guard(NapiAvrcpControllerObserver::g_avrcpCtCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("Napi Avrcp is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/napi_bluetooth_avrcp_tg.cpp b/frameworks/js/napi/src/napi_bluetooth_avrcp_tg.cpp index 5232d520..2cc00140 100644 --- a/frameworks/js/napi/src/napi_bluetooth_avrcp_tg.cpp +++ b/frameworks/js/napi/src/napi_bluetooth_avrcp_tg.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiAvrcpTargetObserver NapiAvrcpTarget::observer_; +std::shared_ptr NapiAvrcpTarget::observer_ = std::make_shared(); bool NapiAvrcpTarget::isRegistered_ = false; void NapiAvrcpTarget::DefineAvrcpTargetJSClass(napi_env env) @@ -57,10 +57,10 @@ napi_value NapiAvrcpTarget::On(napi_env env, napi_callback_info info) std::unique_lock guard(NapiAvrcpTargetObserver::g_avrcpTgCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OnEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OnEvent(env, info, observer_->callbackInfos_); if (!isRegistered_) { AvrcpTarget *profile = AvrcpTarget::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); isRegistered_ = true; } HILOGI("Napi Avrcp Target is registered"); @@ -73,7 +73,7 @@ napi_value NapiAvrcpTarget::Off(napi_env env, napi_callback_info info) std::unique_lock guard(NapiAvrcpTargetObserver::g_avrcpTgCallbackInfosMutex); napi_value ret = nullptr; - ret = NapiEvent::OffEvent(env, info, observer_.callbackInfos_); + ret = NapiEvent::OffEvent(env, info, observer_->callbackInfos_); HILOGI("Napi Avrcp Target is unregistered"); return ret; } diff --git a/frameworks/js/napi/src/napi_bluetooth_opp.cpp b/frameworks/js/napi/src/napi_bluetooth_opp.cpp index 53558ae1..8fc33791 100644 --- a/frameworks/js/napi/src/napi_bluetooth_opp.cpp +++ b/frameworks/js/napi/src/napi_bluetooth_opp.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiBluetoothOppObserver NapiBluetoothOpp::observer_; +std::shared_ptr NapiBluetoothOpp::observer_ = std::make_shared(); bool NapiBluetoothOpp::isRegistered_ = false; void NapiBluetoothOpp::DefineOppJSClass(napi_env env) @@ -48,7 +48,7 @@ void NapiBluetoothOpp::DefineOppJSClass(napi_env env) napi_new_instance(env, constructor, 0, nullptr, &napiProfile); NapiProfile::SetProfile(env, ProfileId::PROFILE_OPP, napiProfile); Opp *profile = Opp::GetProfile(); - profile->RegisterObserver(&observer_); + profile->RegisterObserver(observer_); HILOGI("DefineOppJSClass finished"); } @@ -90,7 +90,7 @@ napi_value NapiBluetoothOpp::On(napi_env env, napi_callback_info info) return ret; } napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); - observer_.callbackInfos_[type] = callbackInfo; + observer_->callbackInfos_[type] = callbackInfo; HILOGI("%{public}s is registered", type.c_str()); return ret; } @@ -117,11 +117,11 @@ napi_value NapiBluetoothOpp::Off(napi_env env, napi_callback_info info) return ret; } - if (observer_.callbackInfos_[type] != nullptr) { - std::shared_ptr callbackInfo = observer_.callbackInfos_[type]; + if (observer_->callbackInfos_[type] != nullptr) { + std::shared_ptr callbackInfo = observer_->callbackInfos_[type]; napi_delete_reference(env, callbackInfo->callback_); } - observer_.callbackInfos_[type] = nullptr; + observer_->callbackInfos_[type] = nullptr; HILOGI("%{public}s is unregistered", type.c_str()); return ret; } diff --git a/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp b/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp index ab1687a8..8b79cc28 100644 --- a/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp +++ b/frameworks/js/napi/src/pan/napi_bluetooth_pan.cpp @@ -26,7 +26,7 @@ namespace OHOS { namespace Bluetooth { using namespace std; -NapiBluetoothPanObserver NapiBluetoothPan::observer_; +std::shared_ptr NapiBluetoothPan::observer_ = std::make_shared(); thread_local napi_ref NapiBluetoothPan::consRef_ = nullptr; napi_value NapiBluetoothPan::CreatePanProfile(napi_env env, napi_callback_info info) @@ -38,7 +38,7 @@ napi_value NapiBluetoothPan::CreatePanProfile(napi_env env, napi_callback_info i napi_new_instance(env, constructor, 0, nullptr, &napiProfile); NapiProfile::SetProfile(env, ProfileId::PROFILE_PAN_NETWORK, napiProfile); Pan *profile = Pan::GetProfile(); - profile->RegisterObserver(&NapiBluetoothPan::observer_); + profile->RegisterObserver(NapiBluetoothPan::observer_); HILOGI("finished"); return napiProfile; @@ -77,7 +77,7 @@ void NapiBluetoothPan::DefinePanJSClass(napi_env env, napi_value exports) napi_new_instance(env, constructor, 0, nullptr, &napiProfile); NapiProfile::SetProfile(env, ProfileId::PROFILE_PAN_NETWORK, napiProfile); Pan *profile = Pan::GetProfile(); - profile->RegisterObserver(&NapiBluetoothPan::observer_); + profile->RegisterObserver(NapiBluetoothPan::observer_); #endif } @@ -142,7 +142,7 @@ napi_value NapiBluetoothPan::On(napi_env env, napi_callback_info info) return ret; } napi_create_reference(env, argv[PARAM1], 1, &callbackInfo->callback_); - observer_.callbackInfos_[type] = callbackInfo; + observer_->callbackInfos_[type] = callbackInfo; HILOGI("%{public}s is registered", type.c_str()); return ret; @@ -169,11 +169,11 @@ napi_value NapiBluetoothPan::Off(napi_env env, napi_callback_info info) HILOGE("string expected."); return ret; } - if (observer_.callbackInfos_[type] != nullptr) { - std::shared_ptr callbackInfo = observer_.callbackInfos_[type]; + if (observer_->callbackInfos_[type] != nullptr) { + std::shared_ptr callbackInfo = observer_->callbackInfos_[type]; napi_delete_reference(env, callbackInfo->callback_); } - observer_.callbackInfos_[type] = nullptr; + observer_->callbackInfos_[type] = nullptr; HILOGI("%{public}s is unregistered", type.c_str()); diff --git a/interfaces/inner_api/include/bluetooth_a2dp_snk.h b/interfaces/inner_api/include/bluetooth_a2dp_snk.h index 5398049f..7802814d 100644 --- a/interfaces/inner_api/include/bluetooth_a2dp_snk.h +++ b/interfaces/inner_api/include/bluetooth_a2dp_snk.h @@ -173,7 +173,7 @@ public: * @param observer Reference to the a2dp sink observer. * @since 6.0 */ - void RegisterObserver(A2dpSinkObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister callback function of framework. @@ -181,7 +181,7 @@ public: * @param observer Reference to the a2dp sink observer. * @since 6.0 */ - void DeregisterObserver(A2dpSinkObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief The external process calls the A2dpSink profile interface before the Bluetooth process starts. At this diff --git a/interfaces/inner_api/include/bluetooth_a2dp_src.h b/interfaces/inner_api/include/bluetooth_a2dp_src.h index e255fefb..3b6deb52 100644 --- a/interfaces/inner_api/include/bluetooth_a2dp_src.h +++ b/interfaces/inner_api/include/bluetooth_a2dp_src.h @@ -305,7 +305,7 @@ public: * @param observer Reference to the a2dp source observer. * @since 6.0 */ - void RegisterObserver(A2dpSourceObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister callback function of framework. @@ -313,7 +313,7 @@ public: * @param observer Reference to the a2dp source observer. * @since 6.0 */ - void DeregisterObserver(A2dpSourceObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Write the pcm data to a2dp source profile. diff --git a/interfaces/inner_api/include/bluetooth_avrcp_ct.h b/interfaces/inner_api/include/bluetooth_avrcp_ct.h index fb76083d..716d796f 100644 --- a/interfaces/inner_api/include/bluetooth_avrcp_ct.h +++ b/interfaces/inner_api/include/bluetooth_avrcp_ct.h @@ -474,7 +474,7 @@ public: * @param[in] observer The pointer to the AvrcpController::IObserver. * @since 6 */ - void RegisterObserver(AvrcpController::IObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Unregisters the observer. @@ -482,7 +482,7 @@ public: * @param[in] observer The pointer to the AvrcpController::IObserver. * @since 6 */ - void UnregisterObserver(AvrcpController::IObserver *observer); + void UnregisterObserver(std::shared_ptr observer); /****************************************************************** * CONNECTION * diff --git a/interfaces/inner_api/include/bluetooth_avrcp_tg.h b/interfaces/inner_api/include/bluetooth_avrcp_tg.h index c996fbdb..e1238c02 100644 --- a/interfaces/inner_api/include/bluetooth_avrcp_tg.h +++ b/interfaces/inner_api/include/bluetooth_avrcp_tg.h @@ -90,7 +90,7 @@ public: * @param[in] observer The pointer to the AvrcpTarget::IObserver. * @since 6 */ - void RegisterObserver(AvrcpTarget::IObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Unregisters the observer. @@ -98,7 +98,7 @@ public: * @param[in] observer The pointer to the AvrcpTarget::IObserver. * @since 6 */ - void UnregisterObserver(AvrcpTarget::IObserver *observer); + void UnregisterObserver(std::shared_ptr observer); /****************************************************************** * CONNECTION * diff --git a/interfaces/inner_api/include/bluetooth_ble_advertiser.h b/interfaces/inner_api/include/bluetooth_ble_advertiser.h index 13bd472b..d8df9863 100644 --- a/interfaces/inner_api/include/bluetooth_ble_advertiser.h +++ b/interfaces/inner_api/include/bluetooth_ble_advertiser.h @@ -430,7 +430,7 @@ public: * @since 6 */ int StartAdvertising(const BleAdvertiserSettings &settings, const BleAdvertiserData &advData, - const BleAdvertiserData &scanResponse, uint16_t duration, std::shared_ptr); + const BleAdvertiserData &scanResponse, uint16_t duration, std::shared_ptr callback); /** * @brief Start advertising. @@ -443,7 +443,7 @@ public: * @since 6 */ int StartAdvertising(const BleAdvertiserSettings &settings, const std::vector &advData, - const std::vector &scanResponse, uint16_t duration, std::shared_ptr); + const std::vector &scanResponse, uint16_t duration, std::shared_ptr callback); /** * @brief Enable advertising. @@ -453,7 +453,7 @@ public: * @param callback Advertise callback. * @since 11 */ - int EnableAdvertising(uint8_t advHandle, uint16_t duration, std::shared_ptr); + int EnableAdvertising(uint8_t advHandle, uint16_t duration, std::shared_ptr callback); /** * @brief Disable advertising. @@ -462,11 +462,11 @@ public: * @param callback Advertise callback. * @since 11 */ - int DisableAdvertising(uint8_t advHandle, std::shared_ptr); + int DisableAdvertising(uint8_t advHandle, std::shared_ptr callback); void SetAdvertisingData(const std::vector &advData, const std::vector &scanResponse, - std::shared_ptr); - int StopAdvertising(std::shared_ptr); + std::shared_ptr callback); + int StopAdvertising(std::shared_ptr callback); /** * @brief Cleans up advertisers. @@ -474,7 +474,7 @@ public: * @param callback Advertise callback. * @since 6 */ - void Close(std::shared_ptr); + void Close(std::shared_ptr callback); /** * @brief Get Advertise handle. @@ -482,7 +482,7 @@ public: * @param callback Advertise callback. * @since 6 */ - uint8_t GetAdvHandle(std::shared_ptr); + uint8_t GetAdvHandle(std::shared_ptr callback); private: BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BleAdvertiser); diff --git a/interfaces/inner_api/include/bluetooth_hfp_ag.h b/interfaces/inner_api/include/bluetooth_hfp_ag.h index 8b130660..739dcddb 100644 --- a/interfaces/inner_api/include/bluetooth_hfp_ag.h +++ b/interfaces/inner_api/include/bluetooth_hfp_ag.h @@ -287,7 +287,7 @@ public: * @param observer HandsFree AudioGateway observer instance. * @since 6 */ - void RegisterObserver(HandsFreeAudioGatewayObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister HandsFree AudioGateway observer instance. @@ -295,7 +295,7 @@ public: * @param observer HandsFree AudioGateway observer instance. * @since 6 */ - void DeregisterObserver(HandsFreeAudioGatewayObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Get remote HF device list which are in the connected state. diff --git a/interfaces/inner_api/include/bluetooth_hfp_hf.h b/interfaces/inner_api/include/bluetooth_hfp_hf.h index 339b613b..5c7a0f7a 100644 --- a/interfaces/inner_api/include/bluetooth_hfp_hf.h +++ b/interfaces/inner_api/include/bluetooth_hfp_hf.h @@ -374,7 +374,7 @@ public: * @param observer HandsFreeUnitObserver instance. * @since 6 */ - void RegisterObserver(HandsFreeUnitObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister HandsFree Unit observer instance. @@ -382,7 +382,7 @@ public: * @param observer HandsFreeUnitObserver instance. * @since 6 */ - void DeregisterObserver(HandsFreeUnitObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief The external process calls the HfpHf profile interface before the Bluetooth process starts. At this diff --git a/interfaces/inner_api/include/bluetooth_hid_host.h b/interfaces/inner_api/include/bluetooth_hid_host.h index 6e10dbe1..c30be6a8 100644 --- a/interfaces/inner_api/include/bluetooth_hid_host.h +++ b/interfaces/inner_api/include/bluetooth_hid_host.h @@ -143,14 +143,14 @@ public: * * @param observer Hid Host observer instance. */ - void RegisterObserver(HidHostObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister Hid Host observer instance. * * @param observer Hid Host observer instance. */ - void DeregisterObserver(HidHostObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Hid Host VCUnplug. diff --git a/interfaces/inner_api/include/bluetooth_host.h b/interfaces/inner_api/include/bluetooth_host.h index 248e6d3f..8c54d0bf 100644 --- a/interfaces/inner_api/include/bluetooth_host.h +++ b/interfaces/inner_api/include/bluetooth_host.h @@ -255,7 +255,7 @@ public: * @param observer Class BluetoothHostObserver pointer to register observer. * @since 6 */ - void RegisterObserver(BluetoothHostObserver &observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister observer. @@ -263,7 +263,7 @@ public: * @param observer Class BluetoothHostObserver pointer to deregister observer. * @since 6 */ - void DeregisterObserver(BluetoothHostObserver &observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Enable classic. @@ -611,7 +611,7 @@ public: * returns false if the operation fails. * @since 6 */ - void DeregisterRemoteDeviceObserver(BluetoothRemoteDeviceObserver &observer); + void DeregisterRemoteDeviceObserver(std::shared_ptr observer); /** * @brief Get max advertising data length. diff --git a/interfaces/inner_api/include/bluetooth_opp.h b/interfaces/inner_api/include/bluetooth_opp.h index 2c7d4d1f..8fe4ce85 100644 --- a/interfaces/inner_api/include/bluetooth_opp.h +++ b/interfaces/inner_api/include/bluetooth_opp.h @@ -343,14 +343,14 @@ public: * * @param observer Opp observer instance. */ - void RegisterObserver(OppObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister Opp observer instance. * * @param observer Opp observer instance. */ - void DeregisterObserver(OppObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Get remote Opp device list which are in the specified states. diff --git a/interfaces/inner_api/include/bluetooth_pan.h b/interfaces/inner_api/include/bluetooth_pan.h index 24fc7b88..0a5f2875 100644 --- a/interfaces/inner_api/include/bluetooth_pan.h +++ b/interfaces/inner_api/include/bluetooth_pan.h @@ -105,14 +105,14 @@ public: * * @param observer Pan observer instance. */ - void RegisterObserver(PanObserver *observer); + void RegisterObserver(std::shared_ptr observer); /** * @brief Deregister Pan observer instance. * * @param observer Pan observer instance. */ - void DeregisterObserver(PanObserver *observer); + void DeregisterObserver(std::shared_ptr observer); /** * @brief Set Tethering -- Gitee