Loading system/gd/hci/hci_layer.cc +56 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ using os::Alarm; using os::Handler; using std::unique_ptr; static std::recursive_mutex life_cycle_guard; static bool life_cycle_stopped = true; static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); Loading Loading @@ -542,6 +545,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { explicit hal_callbacks(HciLayer& module) : module_(module) {} void hciEventReceived(hal::HciPacket event_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(event_bytes)); EventView event = EventView::Create(packet); Loading @@ -549,6 +556,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void aclDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto acl = std::make_unique<AclView>(AclView::Create(packet)); Loading @@ -556,6 +567,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void scoDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto sco = std::make_unique<ScoView>(ScoView::Create(packet)); Loading @@ -563,6 +578,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void isoDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto iso = std::make_unique<IsoView>(IsoView::Create(packet)); Loading Loading @@ -590,39 +609,71 @@ common::BidiQueueEnd<IsoBuilder, IsoView>* HciLayer::GetIsoQueueEnd() { void HciLayer::EnqueueCommand(unique_ptr<CommandBuilder> command, ContextualOnceCallback<void(CommandCompleteView)> on_complete) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::enqueue_command<CommandCompleteView>, std::move(command), std::move(on_complete)); } void HciLayer::EnqueueCommand(unique_ptr<CommandBuilder> command, ContextualOnceCallback<void(CommandStatusView)> on_status) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::enqueue_command<CommandStatusView>, std::move(command), std::move(on_status)); } void HciLayer::RegisterEventHandler(EventCode event, ContextualCallback<void(EventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_event, event, handler); } void HciLayer::UnregisterEventHandler(EventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_event, event); } void HciLayer::RegisterLeEventHandler(SubeventCode event, ContextualCallback<void(LeMetaEventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_le_event, event, handler); } void HciLayer::UnregisterLeEventHandler(SubeventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_le_event, event); } void HciLayer::RegisterVendorSpecificEventHandler( VseSubeventCode event, ContextualCallback<void(VendorSpecificEventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_vs_event, event, handler); } void HciLayer::UnregisterVendorSpecificEventHandler(VseSubeventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_vs_event, event); } Loading Loading @@ -830,9 +881,11 @@ void HciLayer::ListDependencies(ModuleList* list) const { } void HciLayer::Start() { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); auto hal = GetDependency<hal::HciHal>(); impl_ = new impl(hal, *this); hal_callbacks_ = new hal_callbacks(*this); life_cycle_stopped = false; Handler* handler = GetHandler(); impl_->acl_queue_.GetDownEnd()->RegisterDequeue(handler, Loading Loading @@ -860,6 +913,7 @@ void HciLayer::StartWithNoHalDependencies(Handler* handler) { } void HciLayer::Stop() { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); auto hal = GetDependency<hal::HciHal>(); hal->unregisterIncomingPacketCallback(); delete hal_callbacks_; Loading @@ -868,6 +922,8 @@ void HciLayer::Stop() { impl_->sco_queue_.GetDownEnd()->UnregisterDequeue(); impl_->iso_queue_.GetDownEnd()->UnregisterDequeue(); delete impl_; life_cycle_stopped = true; } } // namespace hci Loading Loading
system/gd/hci/hci_layer.cc +56 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ using os::Alarm; using os::Handler; using std::unique_ptr; static std::recursive_mutex life_cycle_guard; static bool life_cycle_stopped = true; static std::chrono::milliseconds getHciTimeoutMs() { static auto sHciTimeoutMs = std::chrono::milliseconds(bluetooth::os::GetSystemPropertyUint32Base( "bluetooth.hci.timeout_milliseconds", HciLayer::kHciTimeoutMs.count())); Loading Loading @@ -542,6 +545,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { explicit hal_callbacks(HciLayer& module) : module_(module) {} void hciEventReceived(hal::HciPacket event_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(event_bytes)); EventView event = EventView::Create(packet); Loading @@ -549,6 +556,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void aclDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto acl = std::make_unique<AclView>(AclView::Create(packet)); Loading @@ -556,6 +567,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void scoDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto sco = std::make_unique<ScoView>(ScoView::Create(packet)); Loading @@ -563,6 +578,10 @@ struct HciLayer::hal_callbacks : public hal::HciHalCallbacks { } void isoDataReceived(hal::HciPacket data_bytes) override { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } auto packet = packet::PacketView<packet::kLittleEndian>( std::make_shared<std::vector<uint8_t>>(std::move(data_bytes))); auto iso = std::make_unique<IsoView>(IsoView::Create(packet)); Loading Loading @@ -590,39 +609,71 @@ common::BidiQueueEnd<IsoBuilder, IsoView>* HciLayer::GetIsoQueueEnd() { void HciLayer::EnqueueCommand(unique_ptr<CommandBuilder> command, ContextualOnceCallback<void(CommandCompleteView)> on_complete) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::enqueue_command<CommandCompleteView>, std::move(command), std::move(on_complete)); } void HciLayer::EnqueueCommand(unique_ptr<CommandBuilder> command, ContextualOnceCallback<void(CommandStatusView)> on_status) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::enqueue_command<CommandStatusView>, std::move(command), std::move(on_status)); } void HciLayer::RegisterEventHandler(EventCode event, ContextualCallback<void(EventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_event, event, handler); } void HciLayer::UnregisterEventHandler(EventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_event, event); } void HciLayer::RegisterLeEventHandler(SubeventCode event, ContextualCallback<void(LeMetaEventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_le_event, event, handler); } void HciLayer::UnregisterLeEventHandler(SubeventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_le_event, event); } void HciLayer::RegisterVendorSpecificEventHandler( VseSubeventCode event, ContextualCallback<void(VendorSpecificEventView)> handler) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::register_vs_event, event, handler); } void HciLayer::UnregisterVendorSpecificEventHandler(VseSubeventCode event) { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); if (life_cycle_stopped) { return; } CallOn(impl_, &impl::unregister_vs_event, event); } Loading Loading @@ -830,9 +881,11 @@ void HciLayer::ListDependencies(ModuleList* list) const { } void HciLayer::Start() { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); auto hal = GetDependency<hal::HciHal>(); impl_ = new impl(hal, *this); hal_callbacks_ = new hal_callbacks(*this); life_cycle_stopped = false; Handler* handler = GetHandler(); impl_->acl_queue_.GetDownEnd()->RegisterDequeue(handler, Loading Loading @@ -860,6 +913,7 @@ void HciLayer::StartWithNoHalDependencies(Handler* handler) { } void HciLayer::Stop() { std::unique_lock<std::recursive_mutex> lock(life_cycle_guard); auto hal = GetDependency<hal::HciHal>(); hal->unregisterIncomingPacketCallback(); delete hal_callbacks_; Loading @@ -868,6 +922,8 @@ void HciLayer::Stop() { impl_->sco_queue_.GetDownEnd()->UnregisterDequeue(); impl_->iso_queue_.GetDownEnd()->UnregisterDequeue(); delete impl_; life_cycle_stopped = true; } } // namespace hci Loading