• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Anything related to the Qualification API (IBluetoothQA).
2 
3 use crate::Message;
4 use bt_topshim::btif::BtDiscMode;
5 use tokio::sync::mpsc::Sender;
6 
7 /// Defines the Qualification API
8 pub trait IBluetoothQA {
add_media_player(&self, name: String, browsing_supported: bool)9     fn add_media_player(&self, name: String, browsing_supported: bool);
rfcomm_send_msc(&self, dlci: u8, addr: String)10     fn rfcomm_send_msc(&self, dlci: u8, addr: String);
11 
12     /// Returns adapter's discoverable mode.
get_discoverable_mode(&self) -> BtDiscMode13     fn get_discoverable_mode(&self) -> BtDiscMode;
14 }
15 
16 pub struct BluetoothQA {
17     tx: Sender<Message>,
18     disc_mode: BtDiscMode,
19 }
20 
21 impl BluetoothQA {
new(tx: Sender<Message>) -> BluetoothQA22     pub fn new(tx: Sender<Message>) -> BluetoothQA {
23         BluetoothQA { tx, disc_mode: BtDiscMode::NonDiscoverable }
24     }
25 
handle_discoverable_mode_changed(&mut self, mode: BtDiscMode)26     pub fn handle_discoverable_mode_changed(&mut self, mode: BtDiscMode) {
27         self.disc_mode = mode;
28     }
29 }
30 
31 impl IBluetoothQA for BluetoothQA {
add_media_player(&self, name: String, browsing_supported: bool)32     fn add_media_player(&self, name: String, browsing_supported: bool) {
33         let txl = self.tx.clone();
34         tokio::spawn(async move {
35             let _ = txl.send(Message::QaAddMediaPlayer(name, browsing_supported)).await;
36         });
37     }
rfcomm_send_msc(&self, dlci: u8, addr: String)38     fn rfcomm_send_msc(&self, dlci: u8, addr: String) {
39         let txl = self.tx.clone();
40         tokio::spawn(async move {
41             let _ = txl.send(Message::QaRfcommSendMsc(dlci, addr)).await;
42         });
43     }
get_discoverable_mode(&self) -> BtDiscMode44     fn get_discoverable_mode(&self) -> BtDiscMode {
45         self.disc_mode.clone()
46     }
47 }
48