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 /// Returns Floss API verion.The MSB 16-bit is the major version and 52 /// LSB 16-bit is the minor version get_floss_api_version(&mut self) -> u3253 fn get_floss_api_version(&mut self) -> u32; 54 55 /// Set the tablet mode of the device. The device that is in tablet mode does not allow 56 /// wakeup by the HID devices. set_tablet_mode(&mut self, tablet_mode: bool)57 fn set_tablet_mode(&mut self, tablet_mode: bool); 58 } 59 60 /// Interface of Bluetooth Manager callbacks. 61 pub trait IBluetoothManagerCallback: RPCProxy { 62 /// HCI device presence has changed. on_hci_device_changed(&mut self, hci_interface: i32, present: bool)63 fn on_hci_device_changed(&mut self, hci_interface: i32, present: bool); 64 65 /// HCI device is enabled or disabled. on_hci_enabled_changed(&mut self, hci_interface: i32, enabled: bool)66 fn on_hci_enabled_changed(&mut self, hci_interface: i32, enabled: bool); 67 68 /// The default adapter has changed. At start-up, if the default adapter is 69 /// already available, this won't be sent out. This will only be sent in two 70 /// cases: 71 /// * Default adapter is no longer available and we need to use a backup. 72 /// * Desired default adapter re-appears and we should switch back. on_default_adapter_changed(&mut self, hci_interface: i32)73 fn on_default_adapter_changed(&mut self, hci_interface: i32); 74 } 75