1 use btstack::RPCProxy; 2 3 use std::sync::{Arc, Mutex}; 4 5 use crate::bluetooth_manager::BluetoothManager; 6 7 #[derive(Debug, Default)] 8 pub struct AdapterWithEnabled { 9 pub hci_interface: i32, 10 pub enabled: bool, 11 } 12 13 /// A mixin of the several interfaces. The naming of the fields in the mixin must match 14 /// what is listed in the `generate_dbus_exporter` invocation. 15 pub struct BluetoothManagerMixin { 16 pub manager: Arc<Mutex<Box<BluetoothManager>>>, 17 pub experimental: Arc<Mutex<Box<BluetoothManager>>>, 18 } 19 20 /// Bluetooth stack management API. 21 pub trait IBluetoothManager { 22 /// Starts the Bluetooth stack. start(&mut self, hci_interface: i32)23 fn start(&mut self, hci_interface: i32); 24 25 /// Stops the Bluetooth stack. stop(&mut self, hci_interface: i32)26 fn stop(&mut self, hci_interface: i32); 27 28 /// Returns whether an adapter is enabled. get_adapter_enabled(&mut self, hci_interface: i32) -> bool29 fn get_adapter_enabled(&mut self, hci_interface: i32) -> bool; 30 31 /// Registers a callback to the Bluetooth manager state. register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>)32 fn register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>); 33 34 /// Returns whether Floss is enabled. get_floss_enabled(&mut self) -> bool35 fn get_floss_enabled(&mut self) -> bool; 36 37 /// Enables/disables Floss. set_floss_enabled(&mut self, enabled: bool)38 fn set_floss_enabled(&mut self, enabled: bool); 39 40 /// Returns a list of available HCI devices and if they are enabled. get_available_adapters(&mut self) -> Vec<AdapterWithEnabled>41 fn get_available_adapters(&mut self) -> Vec<AdapterWithEnabled>; 42 43 /// Get the default adapter to use for activity. The default adapter should 44 /// be used for all device management and will be the |desired_adapter|, if 45 /// present/enabled on the system, or the lowest numbered hci interface otherwise. get_default_adapter(&mut self) -> i3246 fn get_default_adapter(&mut self) -> i32; 47 48 /// Set the preferred default adapter. set_desired_default_adapter(&mut self, hci_interface: i32)49 fn set_desired_default_adapter(&mut self, hci_interface: i32); 50 } 51 52 /// Interface of Bluetooth Manager callbacks. 53 pub trait IBluetoothManagerCallback: RPCProxy { 54 /// HCI device presence has changed. on_hci_device_changed(&mut self, hci_interface: i32, present: bool)55 fn on_hci_device_changed(&mut self, hci_interface: i32, present: bool); 56 57 /// HCI device is enabled or disabled. on_hci_enabled_changed(&mut self, hci_interface: i32, enabled: bool)58 fn on_hci_enabled_changed(&mut self, hci_interface: i32, enabled: bool); 59 60 /// The default adapter has changed. At start-up, if the default adapter is 61 /// already available, this won't be sent out. This will only be sent in two 62 /// cases: 63 /// * Default adapter is no longer available and we need to use a backup. 64 /// * Desired default adapter re-appears and we should switch back. on_default_adapter_changed(&mut self, hci_interface: i32)65 fn on_default_adapter_changed(&mut self, hci_interface: i32); 66 } 67