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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#![doc = include_str!("../README.md")]
#![cfg_attr(test, allow(unused_crate_dependencies))]

pub use profile::*;

#[path = "att/att.rs"]
pub mod att;
#[path = "gap/gap.rs"]
pub mod gap;
#[path = "gatt/gatt.rs"]
pub mod gatt;
#[path = "hci/hci.rs"]
pub mod hci;
#[path = "host/host.rs"]
pub mod host;
#[path = "l2cap/l2cap.rs"]
pub mod l2cap;
pub mod le;
#[path = "smp/smp.rs"]
pub mod smp;

/// Service Discovery Protocol constants ([Vol 3] Part B).
pub mod sdp {
    pub use burble_const::ServiceClass;
}

/// Independent Bluetooth profile and service implementations.
mod profile {
    pub mod bas;
    pub mod dis;
    #[path = "hid/hid.rs"]
    pub mod hid;
    pub mod hogp;
}

type SyncMutex<T> = parking_lot::Mutex<T>;
type SyncMutexGuard<'a, T> = parking_lot::MutexGuard<'a, T>;
type AsyncMutex<T> = tokio::sync::Mutex<T>;
type AsyncRwLock<T> = tokio::sync::RwLock<T>;

/// Interface to persistent peer data storage.
pub trait PeerStore: std::fmt::Debug + Send + Sync {
    /// Type of stored data.
    type Value;

    /// Saves peer data and returns `true` if the operation was successful.
    fn save(&self, peer: le::Addr, v: &Self::Value) -> bool;

    /// Loads peer data.
    #[must_use]
    fn load(&self, peer: le::Addr) -> Option<Self::Value>;

    /// Removes peer data.
    fn remove(&self, peer: le::Addr);

    /// Removes all peer data.
    fn clear(&self);
}

/// Forwards [`core::fmt::Display`] implementation to [`core::fmt::Debug`].
macro_rules! impl_display_via_debug {
    ($($t:ty),*$(,)?) => {$(
        impl ::core::fmt::Display for $t {
            #[inline(always)]
            fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
                ::core::fmt::Debug::fmt(self, f)
            }
        }
    )*};
}
pub(crate) use impl_display_via_debug;

/// Returns a string representation of the specified type.
macro_rules! name_of {
    ($t:ty) => {{
        // TODO: Switch to `core::any::type_name` when stabilized
        type _T = $t; // Allows $t to be recognized as a type for refactoring
        stringify!($t)
    }};
}
pub(crate) use name_of;