1 //! Anything related to the GATT API (IBluetoothGatt).
2 
3 use bt_topshim::btif::BluetoothInterface;
4 
5 use std::sync::{Arc, Mutex};
6 
7 /// Defines the GATT API.
8 pub trait IBluetoothGatt {
register_scanner(&self, callback: Box<dyn IScannerCallback + Send>)9     fn register_scanner(&self, callback: Box<dyn IScannerCallback + Send>);
10 
unregister_scanner(&self, scanner_id: i32)11     fn unregister_scanner(&self, scanner_id: i32);
12 
start_scan(&self, scanner_id: i32, settings: ScanSettings, filters: Vec<ScanFilter>)13     fn start_scan(&self, scanner_id: i32, settings: ScanSettings, filters: Vec<ScanFilter>);
stop_scan(&self, scanner_id: i32)14     fn stop_scan(&self, scanner_id: i32);
15 }
16 
17 /// Interface for scanner callbacks to clients, passed to `IBluetoothGatt::register_scanner`.
18 pub trait IScannerCallback {
19     /// When the `register_scanner` request is done.
on_scanner_registered(&self, status: i32, scanner_id: i32)20     fn on_scanner_registered(&self, status: i32, scanner_id: i32);
21 }
22 
23 #[derive(Debug, FromPrimitive, ToPrimitive)]
24 #[repr(i32)]
25 /// Scan type configuration.
26 pub enum ScanType {
27     Active = 0,
28     Passive = 1,
29 }
30 
31 impl Default for ScanType {
default() -> Self32     fn default() -> Self {
33         ScanType::Active
34     }
35 }
36 
37 /// Represents RSSI configurations for hardware offloaded scanning.
38 // TODO: This is still a placeholder struct, not yet complete.
39 #[derive(Debug, Default)]
40 pub struct RSSISettings {
41     pub low_threshold: i32,
42     pub high_threshold: i32,
43 }
44 
45 /// Represents scanning configurations to be passed to `IBluetoothGatt::start_scan`.
46 #[derive(Debug, Default)]
47 pub struct ScanSettings {
48     pub interval: i32,
49     pub window: i32,
50     pub scan_type: ScanType,
51     pub rssi_settings: RSSISettings,
52 }
53 
54 /// Represents a scan filter to be passed to `IBluetoothGatt::start_scan`.
55 #[derive(Debug, Default)]
56 pub struct ScanFilter {}
57 
58 /// Implementation of the GATT API (IBluetoothGatt).
59 pub struct BluetoothGatt {
60     _intf: Arc<Mutex<BluetoothInterface>>,
61 }
62 
63 impl BluetoothGatt {
64     /// Constructs a new IBluetoothGatt implementation.
new(intf: Arc<Mutex<BluetoothInterface>>) -> BluetoothGatt65     pub fn new(intf: Arc<Mutex<BluetoothInterface>>) -> BluetoothGatt {
66         BluetoothGatt { _intf: intf }
67     }
68 }
69 
70 impl IBluetoothGatt for BluetoothGatt {
register_scanner(&self, _callback: Box<dyn IScannerCallback + Send>)71     fn register_scanner(&self, _callback: Box<dyn IScannerCallback + Send>) {
72         // TODO: implement
73     }
74 
unregister_scanner(&self, _scanner_id: i32)75     fn unregister_scanner(&self, _scanner_id: i32) {
76         // TODO: implement
77     }
78 
start_scan(&self, _scanner_id: i32, _settings: ScanSettings, _filters: Vec<ScanFilter>)79     fn start_scan(&self, _scanner_id: i32, _settings: ScanSettings, _filters: Vec<ScanFilter>) {
80         // TODO: implement
81     }
82 
stop_scan(&self, _scanner_id: i32)83     fn stop_scan(&self, _scanner_id: i32) {
84         // TODO: implement
85     }
86 }
87