pub struct Peripheral { /* private fields */ }Expand description
A local GATT server.
Implementations§
Source§impl Peripheral
impl Peripheral
Sourcepub fn new() -> (Self, Requests)
pub fn new() -> (Self, Requests)
Open the peripheral role, returning the handle and its request stream.
Sourcepub fn with_restoration(_restoration: Restoration) -> (Self, Requests)
pub fn with_restoration(_restoration: Restoration) -> (Self, Requests)
Android has no state preservation, so the identifier is accepted and ignored — nothing here relaunches a process for Bluetooth.
Sourcepub async fn availability(&self) -> Result<(), Availability>
pub async fn availability(&self) -> Result<(), Availability>
Why the peripheral role is not usable, if it is not.
Sourcepub async fn publish(&self, service: Service) -> Result<PublishedService>
pub async fn publish(&self, service: Service) -> Result<PublishedService>
Publish a service into the local GATT database.
A characteristic that can notify gets a Client Characteristic Configuration descriptor added automatically — Android does not, and without one no central can subscribe.
Sourcepub fn unpublish_all(&self)
pub fn unpublish_all(&self)
Remove every published service.
Sourcepub async fn start_advertising(&self, advertising: Advertising) -> Result<()>
pub async fn start_advertising(&self, advertising: Advertising) -> Result<()>
Start advertising.
Android will not put an arbitrary name in the payload — AdvertiseData
only offers “include the device name”, and the device name is the
adapter’s, shared by every app. So
Advertising::local_name turns that
flag on rather than setting a name.
Sourcepub fn stop_advertising(&self)
pub fn stop_advertising(&self)
Stop advertising.
Sourcepub fn is_advertising(&self) -> bool
pub fn is_advertising(&self) -> bool
Whether the radio is currently advertising.
Sourcepub async fn publish_l2cap_channel(
&self,
encryption_required: bool,
) -> Result<Psm>
pub async fn publish_l2cap_channel( &self, encryption_required: bool, ) -> Result<Psm>
Publish an L2CAP channel and return the PSM the system assigned.
Needs API 29. A thread accepts connections and reports each as
Request::ChannelOpened, because accept() blocks.
Sourcepub async fn unpublish_l2cap_channel(&self, psm: Psm) -> Result<()>
pub async fn unpublish_l2cap_channel(&self, psm: Psm) -> Result<()>
Withdraw a previously published PSM.
Sourcepub async fn restored_state(&self) -> Option<RestoredPeripheral>
pub async fn restored_state(&self) -> Option<RestoredPeripheral>
Always None: Android preserves nothing across a relaunch.