背景 在前面章节中介绍在stack.cc的StartEverything接口中主要是通过handle_start_up这个接口初始化Stack::impl,然后调用hci_backend_aidl.cc的initialize接口,调用到vendor下IBluetoothHci.aild的接口。蓝牙协议栈接收HOST主机和Controller 控制器的消息的地方就在Stack::impl的BidiQueue 双向队列实现的:round_robin_scheduler_(handler, controller_, hci_layer_.GetAclQueueEnd()),这是一个轮询调度的。GetAclQueueEnd就是拿到impl_-acl_queue_.GetUpEnd()去发送acl数据包。Control主要是通过hci_layer.cc类调用aclDataReceived通知上层底层会回调的消息。下面就来介绍下BidiQueue 的用法。说明源码:路径是:/android/packages/modules/Bluetooth/system/gd/common/bidi_queue.h#pragma once #include "common/callback.h" #include "os/queue.h" namespace bluetooth { namespace common { // // Interface for one context to send and receive data over // a pair of queues (|BidiQueue|). // template typename TENQUEUE, typename TDEQUEUE class BidiQueueEnd : public ::bluetooth::os::IQueueEnqueueTENQUEUE, public ::bluetooth::os::IQueueDequeueTDEQUEUE { public: using EnqueueCallback = Callbackstd::unique_ptrTENQUEUE(); using DequeueCallback = Callbackvoid(); BidiQueueEnd(::bluetooth::os::IQueueEnqueueTENQUEUE* tx, ::bluetooth::os::IQueueDequeueTDEQUEUE* rx) : tx_(tx), rx_(rx) {} void RegisterEnqueue(::bluetooth::os::Handler* handler, EnqueueCallback callback) override { tx_-RegisterEnqueue(handler, callback); } void UnregisterEnqueue() override { tx_-UnregisterEnqueue(); } void RegisterDequeue(::bluetooth::os::Handler* handler, DequeueCallback callback) override { rx_-RegisterDequeue(handler, callback); } void UnregisterDequeue() override { rx_-UnregisterDequeue(); } std::unique_ptrTDEQUEUE TryDequeue() override { return rx_-TryDequeue(); } private: ::bluetooth::os::IQueueEnqueueTENQUEUE* tx_; ::bluetooth::os::IQueueDequeueTDEQUEUE* rx_; }; // // Interface managing a pair of queues shared between two contexts // (typically layers of the stack). // // The up queue can be used for data to indicate up to bluetooth host and // the down queue can be used for data to sent to bluetooth controller. // Each context uses its |BidiQueueEnd| to manage their data operations: // // The up end: // - Receives data indicated from the down end. // - Sends data to the down end. // // The down e