diff --git a/frameworks/inner/c_adapter/ohos_bt_gap.cpp b/frameworks/inner/c_adapter/ohos_bt_gap.cpp index 2f5575810b08116c7ba8228635e6d47a83d72c6d..412f3b175652014bb1039bf305cb9b5db8dfdaf6 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 9cf8ad9f884b35774777395fd7687393f19d96ce..553dc6ead9fbc01d314c774672d8a315b568e571 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 593d5ab26842b04936f94763c723206680ffb64e..2a328c28a71223b1948d761ced09a1d7e5ea4170 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 547653d42820c37b85c7bdda3ccc5b4120cdd02b..b6d01c3cce4d38b6ea7772ef5b4741e67f75c318 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 64c3fdf06819b615019e95066fcdc9f752d05f54..adce346e70f2ee0374c677699fd44e91483b8f04 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 f87f45c83812f10a303dadbd86e21a4bb225cf4a..3dc6e8230d43c4eebd0b188247d02c4db6ac0fa9 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 37cf1cc42a2c0940c0e25e1d2bc696f70e935106..60b25112f3e643e6554cd45b3d8d0d4462e6890f 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 70e7cd47f52b949190beff013e5ab52c89211c8e..67da5608f2a1130cfcd1c0fd8a1ef4fdce0549f1 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 ff70bfaaba9be31c8e8597af896c93e3096155f5..9aa27f438d592d5dde3e7c9ddeaba7b3658591db 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 7a83b597ecdc4cd0caf2789a620396553f308984..f097beb6d82c078faf3088273f83d360758fa2c8 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 5487f0e6200a0fa40aa8f713ed9222330de4d461..6571282e8485b5e1b3a99c6abb219417f24bb209 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 72c8e0be785afed0c5849fffd2baeffc8b78711b..39ef613d0295426a18426d3dee17a35c8a2b545c 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 1fa68591a73c9413fd245b852a33b69ab3c35130..87500af4c673f2e3b75f0babed006fadd8770aef 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 8a2dd5ced1ca6ca06475e7ea6ef5fa1602b41788..e7392c1e26cbe7e4186186af1e128097762a4844 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 d471312cf27299ddca3c3a2ed31c1adc3b35414c..10fbc6ea2c1335f0dfa4aba80528a9a4992919e8 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 2f331ba3871f2e7342ee077c29424922fc28e160..cb4321fa431bd801ea9ad54c88fd9528e3760a96 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 dd82d7bf3d2b207ff24350bbcf815a28b2f9adcb..d96df083a25accea2e9a2718ae63bf394c2d5625 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 2d0efe42ac5d1678b1664dad6bfd635ee3e7c867..2afdab8720e78053d606bf5c3799f01d6d5ebe5d 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 d86e48f83d40af1f11f353e7056982b863a37656..4904714cd3236c75950e3e9888fac0b98fdf74c3 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 63afdc52f2a1f061ac0958ef5e9ed442bd86dea3..8453bee6908ae8db6f21584ecf3cc1685005cac4 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 31b2be4f10febdaef68fcafe2937ca0135bdfe41..6cdb20b2c628804eae7deac9899834187a16791f 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 58d4d36bc295c1482debea76bf3076852e73431c..6d419f93e7dae11e691f3d80fff71a67587bd8c0 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 e37d47eb71cab417f770e4d5594418eefbab707b..e4d78688ff847f0224d3aebb6942adc3b73c7bf4 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 16e6eb7b77882e1fc9d535cb4b1216524e3d95b3..58d856e7e9fc9174439ad86e6218c27c99823df2 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 8d484503968ffe0114a52af4530f9071d4db23c9..46da1eb8d3d8d52cd56d646f49a1059ef01f1550 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 b312c926fd0a3db2acb3bd33940185f8137e687c..fdc2fd5c79b55843239e92faec93d93bba11764f 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 4203912abc69479c59fb3a74ef8e16efe3ec3234..d012157fa43ea92d95ac8d35b01d3eb36710c8cc 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 000d49c28e0c2628ca89ded9d7844da53c9c47b0..e00bd305ad366d10305cc79c564665ff768eb8c5 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 5232d520f510e9f0c6739c4d17c43f5f9d86b2b7..2cc0014043596d365d7176e2e729e4284d65612b 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 53558ae104936cb6274be62376669a370ace682c..8fc337913354db5730963c596611ec3a1355a5e8 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 ab1687a85469aa58e3a59dcbe2f9e79e68fc5216..8b79cc28fd5382aeb3b0f001d65cc7a0fe35069f 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 5398049fdf943bd1016f84ee1068b7fbe9aa9bd1..7802814dde9d78413b44d23b4ff6baf9586e89ba 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 e255fefbfa45396db0ce19d472b49d13a5bb2ca6..3b6deb528d24351561caf29ec2bfcea4b76875ae 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 fb76083d1e19786f40828d95d3a778e85ccc4afb..716d796f8483df8db77bff9c8aa6b72cd907a4cf 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 c996fbdbff2b0c474ca7040a7f4af3d62145c344..e1238c0283c3b8292efb38eccad6813cfb27c5c3 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 13bd472be75073de186e03940bd144cb62d9beda..d8df9863763754060bded047bcd58251745d560b 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 8b1306607ab2e046fe04a5fb4ec4806eef33638d..739dcddb2c16e5bdd3803466d47569c02009752e 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 339b613bd4d7080177beac4b438700dbf49022d3..5c7a0f7a9d2853fb6dd84c272e19023a4f196a8c 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 6e10dbe1c86c7e18a17e3ed1c908ed1e579fc0ff..c30be6a804010bd5ef1349a2521aab76c03f49c6 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 248e6d3f77ee75bd125461943429f37469c9c966..8c54d0bf0d1e8629082ae5b32509d2e4827cbd86 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 2c7d4d1fe4b873d692fad98d590efb9c3f42cd6c..8fe4ce8522e247d2e327c72f8f34110f745dd9d7 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 24fc7b880e30af104e287a31095c4e51ec449fbb..0a5f2875a4ca18f30ff705e8b69c8b53d54fe73d 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