ble_peripheral_rust/peripheral/
mod.rs

1#[cfg(any(target_os = "macos", target_os = "ios"))]
2mod corebluetooth;
3#[cfg(any(target_os = "macos", target_os = "ios"))]
4pub use self::corebluetooth::Peripheral;
5
6#[cfg(any(target_os = "linux", target_os = "android"))]
7mod bluez;
8#[cfg(any(target_os = "linux", target_os = "android"))]
9pub use self::bluez::Peripheral;
10
11#[cfg(target_os = "windows")]
12mod winrt;
13#[cfg(target_os = "windows")]
14pub use self::winrt::Peripheral;
15
16use crate::{
17    error::Error,
18    gatt::{peripheral_event::PeripheralEvent, service::Service},
19};
20use async_trait::async_trait;
21use tokio::sync::mpsc::Sender;
22use uuid::Uuid;
23
24#[async_trait]
25pub trait PeripheralImpl: Send + Sync {
26    type Peripheral: PeripheralImpl + Send + Sync;
27
28    async fn new(sender_tx: Sender<PeripheralEvent>) -> Result<Peripheral, Error>;
29
30    async fn is_powered(&mut self) -> Result<bool, Error>;
31
32    async fn is_advertising(&mut self) -> Result<bool, Error>;
33
34    async fn start_advertising(&mut self, name: &str, uuids: &[Uuid]) -> Result<(), Error>;
35
36    async fn stop_advertising(&mut self) -> Result<(), Error>;
37
38    async fn add_service(&mut self, service: &Service) -> Result<(), Error>;
39
40    async fn update_characteristic(
41        &mut self,
42        characteristic: Uuid,
43        value: Vec<u8>,
44    ) -> Result<(), Error>;
45}