MCPcopy Create free account
hub / github.com/deviceplug/btleplug / Central

Interface Central

src/api/mod.rs:437–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435/// A Central can be obtained from [`Manager::adapters()`].
436#[async_trait]
437pub trait Central: Send + Sync + Clone {
438 type Peripheral: Peripheral;
439
440 /// Retrieve a stream of `CentralEvent`s. This stream will receive notifications when events
441 /// occur for this Central module. See [`CentralEvent`] for the full set of possible events.
442 async fn events(&self) -> Result<Pin<Box<dyn Stream<Item = CentralEvent> + Send>>>;
443
444 /// Starts a scan for BLE devices. This scan will generally continue until explicitly stopped,
445 /// although this may depend on your Bluetooth adapter. Discovered devices will be announced
446 /// to subscribers of `events` and will be available via `peripherals()`.
447 /// The filter can be used to scan only for specific devices. While some implementations might
448 /// ignore (parts of) the filter and make additional devices available, other implementations
449 /// might require at least one filter for security reasons. Cross-platform code should provide
450 /// a filter, but must be able to handle devices, which do not fit into the filter.
451 async fn start_scan(&self, filter: ScanFilter) -> Result<()>;
452
453 /// Stops scanning for BLE devices.
454 async fn stop_scan(&self) -> Result<()>;
455
456 /// Returns the list of [`Peripheral`]s that have been discovered so far. Note that this list
457 /// may contain peripherals that are no longer available.
458 async fn peripherals(&self) -> Result<Vec<Self::Peripheral>>;
459
460 /// Returns a particular [`Peripheral`] by its address if it has been discovered.
461 async fn peripheral(&self, id: &PeripheralId) -> Result<Self::Peripheral>;
462
463 /// Add a [`Peripheral`] from a MAC address without a scan result. Not supported on all Bluetooth systems.
464 async fn add_peripheral(&self, address: &PeripheralId) -> Result<Self::Peripheral>;
465
466 /// Clears the list of [`Peripheral`]s that have been discovered so far. Connected peripherals
467 /// should be disconnected before calling this method. On platforms that do not cache peripherals
468 /// locally (e.g. BlueZ on Linux), this is a no-op.
469 async fn clear_peripherals(&self) -> Result<()>;
470
471 /// Get information about the Bluetooth adapter being used, such as the model or type.
472 ///
473 /// The details of this are platform-specific andyou should not attempt to parse it, but it may
474 /// be useful for debug logs.
475 async fn adapter_info(&self) -> Result<String>;
476
477 /// Get information about the Bluetooth adapter state.
478 async fn adapter_state(&self) -> Result<CentralState>;
479}
480
481/// The Manager is the entry point to the library, providing access to all the Bluetooth adapters on
482/// the system. You can obtain an instance from [`platform::Manager::new()`](crate::platform::Manager::new).

Callers

nothing calls this directly

Implementers 4

adapter.rssrc/winrtble/adapter.rs
adapter.rssrc/corebluetooth/adapter.rs
adapter.rssrc/bluez/adapter.rs
adapter.rssrc/droidplug/adapter.rs

Calls

no outgoing calls

Tested by

no test coverage detected