1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::provisioning::pb_adv;
use crate::provisioning::pb_adv::{LinkID, TransactionNumber};
use alloc::collections::BTreeSet;
use core::sync::atomic::Ordering;
#[derive(Debug)]
pub struct AtomicTransactionNumber(core::sync::atomic::AtomicU8);
impl AtomicTransactionNumber {
    pub fn new(num: TransactionNumber) -> Self {
        Self(core::sync::atomic::AtomicU8::new(num.0))
    }
    pub fn get(&self) -> TransactionNumber {
        TransactionNumber(self.0.load(Ordering::SeqCst))
    }
    pub fn set(&self, new_number: TransactionNumber) {
        self.0.store(new_number.0, Ordering::SeqCst);
    }
}
impl Clone for AtomicTransactionNumber {
    fn clone(&self) -> Self {
        Self::new(self.get())
    }
}
impl PartialEq for AtomicTransactionNumber {
    fn eq(&self, other: &Self) -> bool {
        self.get() == other.get()
    }
}
impl Eq for AtomicTransactionNumber {}
impl PartialOrd for AtomicTransactionNumber {
    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
        self.get().partial_cmp(&other.get())
    }
}
impl Ord for AtomicTransactionNumber {
    fn cmp(&self, other: &Self) -> core::cmp::Ordering {
        self.get().cmp(&other.get())
    }
}
pub struct Links {
    links: BTreeSet<Link>,
}
impl Links {
    pub fn handle_pb_adv_pdu(&mut self, _pdu: &pb_adv::PDU) {
        unimplemented!()
    }
}
pub enum LinkError {
    Closed,
}
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
pub struct Link {
    link_id: LinkID,
    my_transaction_number: AtomicTransactionNumber,
    other_transaction_number: Option<AtomicTransactionNumber>,
}
impl Link {
    pub fn handle_pb_adv_pdu(&self, pdu: &pb_adv::PDU) {
        if pdu.link_id != self.link_id {
            return;
        }
    }
}