From d1172739798639c75e08be41803eaa2dcb2d1e56 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Sat, 12 Dec 2020 21:38:53 -0800 Subject: [PATCH] rusty-gd: simplify hci a little bit Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --rhost SimpleHalTest Change-Id: I0356c2102cf760c091a92ae0ab8ee7917eea03b6 --- gd/rust/hci/src/lib.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/gd/rust/hci/src/lib.rs b/gd/rust/hci/src/lib.rs index 07c1474e2..186589662 100644 --- a/gd/rust/hci/src/lib.rs +++ b/gd/rust/hci/src/lib.rs @@ -7,8 +7,8 @@ pub mod error; pub mod facade; use bt_hal::HalExports; -use bt_packets::hci; -use bt_packets::hci::EventChild::{CommandStatus,CommandComplete}; +use bt_packets::hci::EventChild::{CommandComplete, CommandStatus}; +use bt_packets::hci::{AclPacket, CommandPacket, EventCode, EventPacket, OpCode}; use error::Result; use gddi::{module, provides, Stoppable}; use std::collections::HashMap; @@ -53,30 +53,30 @@ async fn provide_hci(hal_exports: HalExports, rt: Arc) -> HciExports { /// to the command is received #[derive(Debug)] struct Command { - cmd: hci::CommandPacket, - fut: oneshot::Sender, + cmd: CommandPacket, + fut: oneshot::Sender, } #[derive(Debug)] struct PendingCommand { - opcode: hci::OpCode, - fut: oneshot::Sender, + opcode: OpCode, + fut: oneshot::Sender, } /// HCI interface #[derive(Clone, Stoppable)] pub struct HciExports { cmd_tx: Sender, - evt_handlers: Arc>>>, + evt_handlers: Arc>>>, /// Transmit end of a channel used to send ACL data - pub acl_tx: Sender, + pub acl_tx: Sender, /// Receive end of a channel used to receive ACL data - pub acl_rx: Arc>>, + pub acl_rx: Arc>>, } impl HciExports { - async fn send(&mut self, cmd: hci::CommandPacket) -> Result { - let (tx, rx) = oneshot::channel::(); + async fn send(&mut self, cmd: CommandPacket) -> Result { + let (tx, rx) = oneshot::channel::(); self.cmd_tx.send(Command { cmd, fut: tx }).await?; let event = rx.await?; Ok(event) @@ -84,26 +84,30 @@ impl HciExports { /// Enqueue an HCI command expecting a command complete /// response from the controller - pub async fn enqueue_command_with_complete(&mut self, cmd: hci::CommandPacket) -> hci::EventPacket { + pub async fn enqueue_command_with_complete(&mut self, cmd: CommandPacket) -> EventPacket { self.send(cmd).await.unwrap() } /// Enqueue an HCI command expecting a status response /// from the controller - pub async fn enqueue_command_with_status(&mut self, cmd: hci::CommandPacket) -> hci::EventPacket { + pub async fn enqueue_command_with_status(&mut self, cmd: CommandPacket) -> EventPacket { self.send(cmd).await.unwrap() } /// Indicate interest in specific HCI events - pub async fn register_event_handler(&mut self, evt_code: hci::EventCode, sender: Sender) { + pub async fn register_event_handler( + &mut self, + evt_code: EventCode, + sender: Sender, + ) { self.evt_handlers.lock().await.insert(evt_code, sender); } } async fn dispatch( - evt_handlers: Arc>>>, - evt_rx: Arc>>, - cmd_tx: Sender, + evt_handlers: Arc>>>, + evt_rx: Arc>>, + cmd_tx: Sender, mut cmd_rx: Receiver, ) { let mut pending_cmds: Vec = Vec::new(); @@ -142,7 +146,7 @@ async fn dispatch( } } -async fn consume(evt_rx: &Arc>>) -> Option { +async fn consume(evt_rx: &Arc>>) -> Option { evt_rx.lock().await.recv().await } -- 2.11.0