Loading system/build/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,18 @@ fluoride_defaults { // libstatslog -> libbinder doesn't build on mac enabled: false, }, android: { shared_libs: [ "android.hardware.bluetooth@1.0", "libhidlbase", "libutils", "libcutils", ], static_libs: [ "libbt_common_sys_prop_cxx", "libbt_hidl_hal_cxx", ], }, }, } Loading system/gd/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,10 @@ cc_defaults { "libutils", "libcutils", ], static_libs: [ "libbt_common_sys_prop_cxx", "libbt_hidl_hal_cxx", ], }, }, srcs: [ Loading system/gd/rust/main/src/lib.rs +25 −8 Original line number Diff line number Diff line //! Main BT lifecycle support use gddi::{module, Registry, RegistryBuilder, Stoppable}; use bt_common::GrpcFacade; use bt_hal::rootcanal_hal::RootcanalConfig; use bt_hal::snoop::{SnoopConfig, SnoopMode}; use gddi::{module, Registry, RegistryBuilder, Stoppable}; use std::sync::Arc; use tokio::runtime::Runtime; use bt_common::GrpcFacade; module! { stack_module, Loading @@ -18,24 +18,28 @@ module! { /// Central state manager pub struct Stack { registry: Arc<Registry>, rt: Arc<Runtime>, } impl Stack { /// Construct a new Stack pub async fn new(rt: Arc<Runtime>) -> Self { let registry = Arc::new(RegistryBuilder::new().register_module(stack_module).build()); registry.inject(rt).await; registry.inject(rt.clone()).await; Self { registry } Self { registry, rt } } /// Helper to set the rootcanal port pub async fn set_rootcanal_port(&self, port: Option<u16>) { if let Some(port) = port { self.registry .inject(RootcanalConfig::new("127.0.0.1", port)) .await; self.registry.inject(RootcanalConfig::new("127.0.0.1", port)).await; } } /// Configures snoop with defaults pub async fn use_default_snoop(&self) { self.configure_snoop(None).await; } /// Configures snoop. If the path is provided, full logging is turned on Loading @@ -53,8 +57,15 @@ impl Stack { self.registry.get::<T>().await } /// Get, but blocks the current thread. pub fn get_blocking<T: 'static + Clone + Send + Sync + Stoppable>(&self) -> T { self.rt.block_on(self.get::<T>()) } /// Helper to get a grpc service pub async fn get_grpc<T: 'static + Clone + Send + Sync + GrpcFacade + Stoppable>(&self) -> grpcio::Service { pub async fn get_grpc<T: 'static + Clone + Send + Sync + GrpcFacade + Stoppable>( &self, ) -> grpcio::Service { self.get::<T>().await.into_grpc() } Loading @@ -62,4 +73,10 @@ impl Stack { pub async fn stop(&mut self) { self.registry.stop_all().await; } /// Stop, but blocks the current thread. pub fn stop_blocking(&mut self) { let rt = self.rt.clone(); rt.block_on(self.stop()); } } system/gd/rust/shim/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ rust_ffi_static { "libbt_hci", "libbt_common", "libcxx", "libtokio", "libbt_main", ], static_libs: [ "libbt_callbacks_cxx", Loading system/gd/rust/shim/src/stack.rs +33 −4 Original line number Diff line number Diff line //! Stack management use bt_common::init_flags; use bt_main::Stack; use std::sync::Arc; use tokio::runtime::Runtime; #[cxx::bridge(namespace = bluetooth::rust::stack)] mod ffi { extern "Rust" { fn start(); fn stop(); type Stack; fn create() -> Box<Stack>; fn start(stack: &mut Stack); fn stop(stack: &mut Stack); } } pub fn start() { pub fn create() -> Box<Stack> { assert!(init_flags::gd_rust_is_enabled()); let rt = Arc::new(Runtime::new().unwrap()); let local_rt = rt.clone(); rt.block_on(async move { let stack = Stack::new(local_rt).await; stack.use_default_snoop().await; Box::new(stack) }) } pub fn stop() { pub fn start(stack: &mut Stack) { assert!(init_flags::gd_rust_is_enabled()); if init_flags::gd_hci_is_enabled() { stack.get_blocking::<bt_hci::HciExports>(); } } pub fn stop(stack: &mut Stack) { assert!(init_flags::gd_rust_is_enabled()); stack.stop_blocking(); } Loading
system/build/Android.bp +12 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,18 @@ fluoride_defaults { // libstatslog -> libbinder doesn't build on mac enabled: false, }, android: { shared_libs: [ "android.hardware.bluetooth@1.0", "libhidlbase", "libutils", "libcutils", ], static_libs: [ "libbt_common_sys_prop_cxx", "libbt_hidl_hal_cxx", ], }, }, } Loading
system/gd/Android.bp +4 −0 Original line number Diff line number Diff line Loading @@ -130,6 +130,10 @@ cc_defaults { "libutils", "libcutils", ], static_libs: [ "libbt_common_sys_prop_cxx", "libbt_hidl_hal_cxx", ], }, }, srcs: [ Loading
system/gd/rust/main/src/lib.rs +25 −8 Original line number Diff line number Diff line //! Main BT lifecycle support use gddi::{module, Registry, RegistryBuilder, Stoppable}; use bt_common::GrpcFacade; use bt_hal::rootcanal_hal::RootcanalConfig; use bt_hal::snoop::{SnoopConfig, SnoopMode}; use gddi::{module, Registry, RegistryBuilder, Stoppable}; use std::sync::Arc; use tokio::runtime::Runtime; use bt_common::GrpcFacade; module! { stack_module, Loading @@ -18,24 +18,28 @@ module! { /// Central state manager pub struct Stack { registry: Arc<Registry>, rt: Arc<Runtime>, } impl Stack { /// Construct a new Stack pub async fn new(rt: Arc<Runtime>) -> Self { let registry = Arc::new(RegistryBuilder::new().register_module(stack_module).build()); registry.inject(rt).await; registry.inject(rt.clone()).await; Self { registry } Self { registry, rt } } /// Helper to set the rootcanal port pub async fn set_rootcanal_port(&self, port: Option<u16>) { if let Some(port) = port { self.registry .inject(RootcanalConfig::new("127.0.0.1", port)) .await; self.registry.inject(RootcanalConfig::new("127.0.0.1", port)).await; } } /// Configures snoop with defaults pub async fn use_default_snoop(&self) { self.configure_snoop(None).await; } /// Configures snoop. If the path is provided, full logging is turned on Loading @@ -53,8 +57,15 @@ impl Stack { self.registry.get::<T>().await } /// Get, but blocks the current thread. pub fn get_blocking<T: 'static + Clone + Send + Sync + Stoppable>(&self) -> T { self.rt.block_on(self.get::<T>()) } /// Helper to get a grpc service pub async fn get_grpc<T: 'static + Clone + Send + Sync + GrpcFacade + Stoppable>(&self) -> grpcio::Service { pub async fn get_grpc<T: 'static + Clone + Send + Sync + GrpcFacade + Stoppable>( &self, ) -> grpcio::Service { self.get::<T>().await.into_grpc() } Loading @@ -62,4 +73,10 @@ impl Stack { pub async fn stop(&mut self) { self.registry.stop_all().await; } /// Stop, but blocks the current thread. pub fn stop_blocking(&mut self) { let rt = self.rt.clone(); rt.block_on(self.stop()); } }
system/gd/rust/shim/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ rust_ffi_static { "libbt_hci", "libbt_common", "libcxx", "libtokio", "libbt_main", ], static_libs: [ "libbt_callbacks_cxx", Loading
system/gd/rust/shim/src/stack.rs +33 −4 Original line number Diff line number Diff line //! Stack management use bt_common::init_flags; use bt_main::Stack; use std::sync::Arc; use tokio::runtime::Runtime; #[cxx::bridge(namespace = bluetooth::rust::stack)] mod ffi { extern "Rust" { fn start(); fn stop(); type Stack; fn create() -> Box<Stack>; fn start(stack: &mut Stack); fn stop(stack: &mut Stack); } } pub fn start() { pub fn create() -> Box<Stack> { assert!(init_flags::gd_rust_is_enabled()); let rt = Arc::new(Runtime::new().unwrap()); let local_rt = rt.clone(); rt.block_on(async move { let stack = Stack::new(local_rt).await; stack.use_default_snoop().await; Box::new(stack) }) } pub fn stop() { pub fn start(stack: &mut Stack) { assert!(init_flags::gd_rust_is_enabled()); if init_flags::gd_hci_is_enabled() { stack.get_blocking::<bt_hci::HciExports>(); } } pub fn stop(stack: &mut Stack) { assert!(init_flags::gd_rust_is_enabled()); stack.stop_blocking(); }