• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Mocked implementation of AttTransport for use in test
2 
3 use crate::{
4     gatt::{channel::AttTransport, ids::TransportIndex},
5     packets::{AttBuilder, Serializable, SerializeError},
6 };
7 use tokio::sync::mpsc::{self, unbounded_channel, UnboundedReceiver};
8 
9 /// Routes calls to AttTransport into a channel containing AttBuilders
10 pub struct MockAttTransport(mpsc::UnboundedSender<(TransportIndex, AttBuilder)>);
11 
12 impl MockAttTransport {
13     /// Constructor. Returns Self and the RX side of a channel containing
14     /// AttBuilders sent on TransportIndices
new() -> (Self, UnboundedReceiver<(TransportIndex, AttBuilder)>)15     pub fn new() -> (Self, UnboundedReceiver<(TransportIndex, AttBuilder)>) {
16         let (tx, rx) = unbounded_channel();
17         (Self(tx), rx)
18     }
19 }
20 
21 impl AttTransport for MockAttTransport {
send_packet( &self, tcb_idx: TransportIndex, packet: AttBuilder, ) -> Result<(), SerializeError>22     fn send_packet(
23         &self,
24         tcb_idx: TransportIndex,
25         packet: AttBuilder,
26     ) -> Result<(), SerializeError> {
27         packet.to_vec()?; // trigger SerializeError if needed
28         self.0.send((tcb_idx, packet)).unwrap();
29         Ok(())
30     }
31 }
32