From 0063e84eb0636c2b2cce0ff09e6fb804a3bb6276 Mon Sep 17 00:00:00 2001 From: Zach Johnson Date: Thu, 19 Nov 2020 11:26:43 -0800 Subject: [PATCH] rusty-gd: some tidying up of imports & formatting Bug: 171749953 Tag: #gd-refactor Test: gd/cert/run --rhost SimpleHalTest Change-Id: Id98b6ad953908de110ad34c6443d6812588332c5 --- gd/rust/common/src/lib.rs | 1 - gd/rust/facade/src/lib.rs | 18 ++++++------------ gd/rust/facade/src/main.rs | 21 +++++---------------- gd/rust/gddi/src/lib.rs | 5 +---- gd/rust/hal/src/facade.rs | 16 +++++----------- gd/rust/hal/src/lib.rs | 11 ++++------- gd/rust/hci/src/facade.rs | 10 +++------- gd/rust/hci/src/lib.rs | 25 +++++++++---------------- 8 files changed, 33 insertions(+), 74 deletions(-) diff --git a/gd/rust/common/src/lib.rs b/gd/rust/common/src/lib.rs index 6e873120d..5f83d1333 100644 --- a/gd/rust/common/src/lib.rs +++ b/gd/rust/common/src/lib.rs @@ -6,7 +6,6 @@ pub mod time; #[macro_use] mod ready; - #[cfg(test)] #[macro_use] mod asserts; diff --git a/gd/rust/facade/src/lib.rs b/gd/rust/facade/src/lib.rs index 724b4bcbd..ff0718062 100644 --- a/gd/rust/facade/src/lib.rs +++ b/gd/rust/facade/src/lib.rs @@ -10,26 +10,20 @@ pub mod empty { use bt_facade_common_proto::common; use bt_facade_rootservice_proto::rootservice; -use rootservice::*; -use rootservice_grpc::{create_root_facade, RootFacade}; - use bt_hal::facade::HciHalFacadeService; use bt_hal::hal_module; use bt_hal::rootcanal_hal::RootcanalConfig; use bt_hci::facade::HciLayerFacadeService; use bt_hci::hci_module; - -use tokio::runtime::Runtime; -use tokio::sync::mpsc::{channel, Sender}; -use tokio::sync::oneshot; - +use futures::executor::block_on; use gddi::{module, Registry, RegistryBuilder}; - use grpcio::*; - +use rootservice::*; +use rootservice_grpc::{create_root_facade, RootFacade}; use std::sync::Arc; - -use futures::executor::block_on; +use tokio::runtime::Runtime; +use tokio::sync::mpsc::{channel, Sender}; +use tokio::sync::oneshot; module! { stack_module, diff --git a/gd/rust/facade/src/main.rs b/gd/rust/facade/src/main.rs index b8100ad8c..c6b726440 100644 --- a/gd/rust/facade/src/main.rs +++ b/gd/rust/facade/src/main.rs @@ -7,24 +7,17 @@ use clap::{App, Arg}; #[macro_use] extern crate lazy_static; -use grpcio::*; - +use bluetooth_with_facades::RootFacadeService; use futures::channel::mpsc; use futures::executor::block_on; use futures::stream::StreamExt; - -use bluetooth_with_facades::RootFacadeService; - +use grpcio::*; +use nix::sys::signal; use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr}; -use std::sync::Arc; -use std::sync::Mutex; - +use std::sync::{Arc, Mutex}; use tokio::net::TcpStream; - use tokio::runtime::Runtime; -use nix::sys::signal; - fn main() { let sigint = install_sigint(); let rt = Arc::new(Runtime::new().unwrap()); @@ -57,11 +50,7 @@ async fn async_main(rt: Arc, mut sigint: mpsc::UnboundedReceiver<()>) { .long("rootcanal-port") .takes_value(true), ) - .arg( - Arg::with_name("btsnoop") - .long("btsnoop") - .takes_value(true), - ) + .arg(Arg::with_name("btsnoop").long("btsnoop").takes_value(true)) .arg( Arg::with_name("btconfig") .long("btconfig") diff --git a/gd/rust/gddi/src/lib.rs b/gd/rust/gddi/src/lib.rs index 1017f53ac..7ae5c592b 100644 --- a/gd/rust/gddi/src/lib.rs +++ b/gd/rust/gddi/src/lib.rs @@ -1,13 +1,10 @@ //! Core dependency injection objects +use std::any::{Any, TypeId}; use std::collections::HashMap; - -use std::any::Any; -use std::any::TypeId; use std::future::Future; use std::pin::Pin; use std::sync::Arc; - use tokio::sync::Mutex; pub use gddi_macros::{module, provides}; diff --git a/gd/rust/hal/src/facade.rs b/gd/rust/hal/src/facade.rs index 86b9f5094..75ca0fc8f 100644 --- a/gd/rust/hal/src/facade.rs +++ b/gd/rust/hal/src/facade.rs @@ -1,22 +1,16 @@ //! BT HCI HAL facade +use crate::HalExports; use bt_hal_proto::empty::Empty; use bt_hal_proto::facade::*; use bt_hal_proto::facade_grpc::{create_hci_hal_facade, HciHalFacade}; - -use gddi::{module, provides}; -use tokio::runtime::Runtime; -use tokio::sync::mpsc; -use tokio::sync::Mutex; - +use bt_packet::{HciCommand, HciEvent, RawPacket}; use futures::sink::SinkExt; +use gddi::{module, provides}; use grpcio::*; - use std::sync::Arc; - -use crate::HalExports; - -use bt_packet::{HciCommand, HciEvent, RawPacket}; +use tokio::runtime::Runtime; +use tokio::sync::{mpsc, Mutex}; module! { hal_facade_module, diff --git a/gd/rust/hal/src/lib.rs b/gd/rust/hal/src/lib.rs index 25f68ac61..249662e2c 100644 --- a/gd/rust/hal/src/lib.rs +++ b/gd/rust/hal/src/lib.rs @@ -15,15 +15,12 @@ mod hidl_hal; #[cfg(target_os = "android")] use hidl_hal::hidl_hal_module; -use std::sync::Arc; -use thiserror::Error; -use tokio::sync::mpsc; -use tokio::sync::Mutex; -use gddi::module; - use bt_packet::{HciCommand, HciEvent, RawPacket}; - use facade::hal_facade_module; +use gddi::module; +use std::sync::Arc; +use thiserror::Error; +use tokio::sync::{mpsc, Mutex}; #[cfg(target_os = "android")] module! { diff --git a/gd/rust/hci/src/facade.rs b/gd/rust/hci/src/facade.rs index 72b5981fb..cdc32e8fe 100644 --- a/gd/rust/hci/src/facade.rs +++ b/gd/rust/hci/src/facade.rs @@ -1,19 +1,15 @@ //! HCI layer facade +use crate::HciExports; use bt_hci_proto::empty::Empty; use bt_hci_proto::facade::*; use bt_hci_proto::facade_grpc::{create_hci_layer_facade, HciLayerFacade}; - +use futures::prelude::*; use futures::sink::SinkExt; use gddi::{module, provides}; -use tokio::runtime::Runtime; - -use crate::HciExports; - -use futures::prelude::*; use grpcio::*; - use std::sync::Arc; +use tokio::runtime::Runtime; module! { facade_module, diff --git a/gd/rust/hci/src/lib.rs b/gd/rust/hci/src/lib.rs index d5f005028..dc4ae5616 100644 --- a/gd/rust/hci/src/lib.rs +++ b/gd/rust/hci/src/lib.rs @@ -6,23 +6,16 @@ pub mod error; /// HCI layer facade service pub mod facade; +use bt_hal::HalExports; +use bt_packet::{HciCommand, HciEvent}; +use error::Result; +use facade::facade_module; use gddi::{module, provides}; -use tokio::sync::mpsc; -use tokio::sync::mpsc::{channel, Receiver, Sender}; -use tokio::sync::oneshot; - use std::collections::HashSet; use std::sync::Arc; use tokio::runtime::Runtime; -use tokio::sync::Mutex; - -use bt_hal::HalExports; -use bt_packet as packet; -use packet::{HciCommand, HciEvent}; - -use error::Result; - -use facade::facade_module; +use tokio::sync::mpsc::{channel, Receiver, Sender}; +use tokio::sync::{mpsc, oneshot, Mutex}; module! { hci_module, @@ -97,7 +90,7 @@ impl HciExports { /// Send the HCI event async fn dispatch_event(&mut self, event: HciEvent) -> Result<()> { - let evt_code = packet::get_evt_code(&event); + let evt_code = bt_packet::get_evt_code(&event); if let Some(evt_code) = evt_code { let registered_events = self.registered_events.lock().await; if registered_events.contains(&evt_code) { @@ -136,7 +129,7 @@ async fn on_event( evt_rx: Arc>>, ) { while let Some(evt) = evt_rx.lock().await.recv().await { - let opcode = packet::get_evt_opcode(&evt).unwrap(); + let opcode = bt_packet::get_evt_opcode(&evt).unwrap(); let mut pending_cmds = pending_cmds.lock().await; if let Some(pending_cmd) = remove_first(&mut pending_cmds, |entry| entry.opcode == opcode) { pending_cmd.fut.send(evt).unwrap(); @@ -154,7 +147,7 @@ async fn on_command( while let Some(cmd) = cmd_rx.recv().await { let mut pending_cmds = pending_cmds.lock().await; pending_cmds.push(HciCommandEntryInner { - opcode: packet::get_cmd_opcode(&cmd.cmd).unwrap(), + opcode: bt_packet::get_cmd_opcode(&cmd.cmd).unwrap(), fut: cmd.fut, }); cmd_tx.send(cmd.cmd).unwrap(); -- 2.11.0