Struct bluez_async::BluetoothSession
source · pub struct BluetoothSession { /* private fields */ }
Expand description
A connection to the Bluetooth daemon. This can be cheaply cloned and passed around to be used from different places. It is the main entry point to the library.
Implementations§
source§impl BluetoothSession
impl BluetoothSession
sourcepub async fn new(
) -> Result<(impl Future<Output = Result<(), SpawnError>>, Self), BluetoothError>
pub async fn new( ) -> Result<(impl Future<Output = Result<(), SpawnError>>, Self), BluetoothError>
Establish a new D-Bus connection to communicate with BlueZ.
Returns a tuple of (join handle, Self). If the join handle ever completes then you’re in trouble and should probably restart the process.
sourcepub async fn start_discovery(&self) -> Result<(), BluetoothError>
pub async fn start_discovery(&self) -> Result<(), BluetoothError>
Power on all Bluetooth adapters, remove any discovery filter, and then start scanning for devices.
This is equivalent to calling start_discovery_with_filter(&DiscoveryFilter::default())
.
sourcepub async fn start_discovery_on_adapter(
&self,
adapter: &AdapterId
) -> Result<(), BluetoothError>
pub async fn start_discovery_on_adapter( &self, adapter: &AdapterId ) -> Result<(), BluetoothError>
Power on the given Bluetooth adapter, remove any discovery filter, and then start scanning for devices.
This is equivalent to calling
start_discovery_on_adapter_with_filter(adapter, &DiscoveryFilter::default())
.
sourcepub async fn start_discovery_with_filter(
&self,
discovery_filter: &DiscoveryFilter
) -> Result<(), BluetoothError>
pub async fn start_discovery_with_filter( &self, discovery_filter: &DiscoveryFilter ) -> Result<(), BluetoothError>
Power on all Bluetooth adapters, set the given discovery filter, and then start scanning for devices.
Note that BlueZ combines discovery filters from all clients and sends events matching any filter to all clients, so you may receive unexpected discovery events if there are other clients on the system using Bluetooth as well.
In most common cases, DiscoveryFilter::default()
is fine.
sourcepub async fn start_discovery_on_adapter_with_filter(
&self,
adapter_id: &AdapterId,
discovery_filter: &DiscoveryFilter
) -> Result<(), BluetoothError>
pub async fn start_discovery_on_adapter_with_filter( &self, adapter_id: &AdapterId, discovery_filter: &DiscoveryFilter ) -> Result<(), BluetoothError>
Power on the given Bluetooth adapter, set the given discovery filter, and then start scanning for devices.
Note that BlueZ combines discovery filters from all clients and sends events matching any filter to all clients, so you may receive unexpected discovery events if there are other clients on the system using Bluetooth as well.
In most common cases, DiscoveryFilter::default()
is fine.
sourcepub async fn stop_discovery(&self) -> Result<(), BluetoothError>
pub async fn stop_discovery(&self) -> Result<(), BluetoothError>
Stop scanning for devices on all Bluetooth adapters.
sourcepub async fn stop_discovery_on_adapter(
&self,
adapter_id: &AdapterId
) -> Result<(), BluetoothError>
pub async fn stop_discovery_on_adapter( &self, adapter_id: &AdapterId ) -> Result<(), BluetoothError>
Stop scanning for devices on the given Bluetooth adapters.
sourcepub async fn get_adapters(&self) -> Result<Vec<AdapterInfo>, BluetoothError>
pub async fn get_adapters(&self) -> Result<Vec<AdapterInfo>, BluetoothError>
Get a list of all Bluetooth adapters on the system.
sourcepub async fn get_devices(&self) -> Result<Vec<DeviceInfo>, BluetoothError>
pub async fn get_devices(&self) -> Result<Vec<DeviceInfo>, BluetoothError>
Get a list of all Bluetooth devices which have been discovered so far.
sourcepub async fn get_devices_on_adapter(
&self,
adapter: &AdapterId
) -> Result<Vec<DeviceInfo>, BluetoothError>
pub async fn get_devices_on_adapter( &self, adapter: &AdapterId ) -> Result<Vec<DeviceInfo>, BluetoothError>
Get a list of all Bluetooth devices which have been discovered so far on a given adapter.
sourcepub async fn get_services(
&self,
device: &DeviceId
) -> Result<Vec<ServiceInfo>, BluetoothError>
pub async fn get_services( &self, device: &DeviceId ) -> Result<Vec<ServiceInfo>, BluetoothError>
Get a list of all GATT services which the given Bluetooth device offers.
Note that this won’t be filled in until the device is connected.
sourcepub async fn get_characteristics(
&self,
service: &ServiceId
) -> Result<Vec<CharacteristicInfo>, BluetoothError>
pub async fn get_characteristics( &self, service: &ServiceId ) -> Result<Vec<CharacteristicInfo>, BluetoothError>
Get a list of all characteristics on the given GATT service.
sourcepub async fn get_descriptors(
&self,
characteristic: &CharacteristicId
) -> Result<Vec<DescriptorInfo>, BluetoothError>
pub async fn get_descriptors( &self, characteristic: &CharacteristicId ) -> Result<Vec<DescriptorInfo>, BluetoothError>
Get a list of all descriptors on the given GATT characteristic.
sourcepub async fn get_service_by_uuid(
&self,
device: &DeviceId,
uuid: Uuid
) -> Result<ServiceInfo, BluetoothError>
pub async fn get_service_by_uuid( &self, device: &DeviceId, uuid: Uuid ) -> Result<ServiceInfo, BluetoothError>
Find a GATT service with the given UUID advertised by the given device, if any.
Note that this generally won’t work until the device is connected.
sourcepub async fn get_characteristic_by_uuid(
&self,
service: &ServiceId,
uuid: Uuid
) -> Result<CharacteristicInfo, BluetoothError>
pub async fn get_characteristic_by_uuid( &self, service: &ServiceId, uuid: Uuid ) -> Result<CharacteristicInfo, BluetoothError>
Find a characteristic with the given UUID as part of the given GATT service advertised by a device, if there is any.
sourcepub async fn get_service_characteristic_by_uuid(
&self,
device: &DeviceId,
service_uuid: Uuid,
characteristic_uuid: Uuid
) -> Result<CharacteristicInfo, BluetoothError>
pub async fn get_service_characteristic_by_uuid( &self, device: &DeviceId, service_uuid: Uuid, characteristic_uuid: Uuid ) -> Result<CharacteristicInfo, BluetoothError>
Convenience method to get a GATT charactacteristic with the given UUID advertised by a device as part of the given service.
This is equivalent to calling get_service_by_uuid
and then get_characteristic_by_uuid
.
sourcepub async fn get_device_info(
&self,
id: &DeviceId
) -> Result<DeviceInfo, BluetoothError>
pub async fn get_device_info( &self, id: &DeviceId ) -> Result<DeviceInfo, BluetoothError>
Get information about the given Bluetooth device.
sourcepub async fn get_adapter_info(
&self,
id: &AdapterId
) -> Result<AdapterInfo, BluetoothError>
pub async fn get_adapter_info( &self, id: &AdapterId ) -> Result<AdapterInfo, BluetoothError>
Get information about the given Bluetooth adapter.
sourcepub async fn get_service_info(
&self,
id: &ServiceId
) -> Result<ServiceInfo, BluetoothError>
pub async fn get_service_info( &self, id: &ServiceId ) -> Result<ServiceInfo, BluetoothError>
Get information about the given GATT service.
sourcepub async fn get_characteristic_info(
&self,
id: &CharacteristicId
) -> Result<CharacteristicInfo, BluetoothError>
pub async fn get_characteristic_info( &self, id: &CharacteristicId ) -> Result<CharacteristicInfo, BluetoothError>
Get information about the given GATT characteristic.
sourcepub async fn get_descriptor_info(
&self,
id: &DescriptorId
) -> Result<DescriptorInfo, BluetoothError>
pub async fn get_descriptor_info( &self, id: &DescriptorId ) -> Result<DescriptorInfo, BluetoothError>
Get information about the given GATT descriptor.
sourcepub async fn connect(&self, id: &DeviceId) -> Result<(), BluetoothError>
pub async fn connect(&self, id: &DeviceId) -> Result<(), BluetoothError>
Connect to the given Bluetooth device.
sourcepub async fn connect_with_timeout(
&self,
id: &DeviceId,
timeout: Duration
) -> Result<(), BluetoothError>
pub async fn connect_with_timeout( &self, id: &DeviceId, timeout: Duration ) -> Result<(), BluetoothError>
Connect to the given Bluetooth device with specified timeout.
sourcepub async fn disconnect(&self, id: &DeviceId) -> Result<(), BluetoothError>
pub async fn disconnect(&self, id: &DeviceId) -> Result<(), BluetoothError>
Disconnect from the given Bluetooth device.
sourcepub async fn read_characteristic_value(
&self,
id: &CharacteristicId
) -> Result<Vec<u8>, BluetoothError>
pub async fn read_characteristic_value( &self, id: &CharacteristicId ) -> Result<Vec<u8>, BluetoothError>
Read the value of the given GATT characteristic.
This is equivalent to calling read_characteristic_value_with_offset(0)
.
sourcepub async fn read_characteristic_value_with_offset(
&self,
id: &CharacteristicId,
offset: usize
) -> Result<Vec<u8>, BluetoothError>
pub async fn read_characteristic_value_with_offset( &self, id: &CharacteristicId, offset: usize ) -> Result<Vec<u8>, BluetoothError>
Read the value of the given GATT characteristic, starting from the given offset.
sourcepub async fn write_characteristic_value(
&self,
id: &CharacteristicId,
value: impl Into<Vec<u8>>
) -> Result<(), BluetoothError>
pub async fn write_characteristic_value( &self, id: &CharacteristicId, value: impl Into<Vec<u8>> ) -> Result<(), BluetoothError>
Write the given value to the given GATT characteristic, with default options.
This is equivalent to calling write_characteristic_value_with_options(WriteOptions::default())
.
sourcepub async fn write_characteristic_value_with_options(
&self,
id: &CharacteristicId,
value: impl Into<Vec<u8>>,
options: WriteOptions
) -> Result<(), BluetoothError>
pub async fn write_characteristic_value_with_options( &self, id: &CharacteristicId, value: impl Into<Vec<u8>>, options: WriteOptions ) -> Result<(), BluetoothError>
Write the given value to the given GATT characteristic, with the given options.
sourcepub async fn read_descriptor_value(
&self,
id: &DescriptorId
) -> Result<Vec<u8>, BluetoothError>
pub async fn read_descriptor_value( &self, id: &DescriptorId ) -> Result<Vec<u8>, BluetoothError>
Read the value of the given GATT descriptor.
This is equivalent to calling read_descriptor_value_with_offset(0)
.
sourcepub async fn read_descriptor_value_with_offset(
&self,
id: &DescriptorId,
offset: usize
) -> Result<Vec<u8>, BluetoothError>
pub async fn read_descriptor_value_with_offset( &self, id: &DescriptorId, offset: usize ) -> Result<Vec<u8>, BluetoothError>
Read the value of the given GATT descriptor, starting from the given offset.
sourcepub async fn write_descriptor_value(
&self,
id: &DescriptorId,
value: impl Into<Vec<u8>>
) -> Result<(), BluetoothError>
pub async fn write_descriptor_value( &self, id: &DescriptorId, value: impl Into<Vec<u8>> ) -> Result<(), BluetoothError>
Write the given value to the given GATT descriptor.
This is equivalent to calling write_descriptor_value_with_offset(0)
.
sourcepub async fn write_descriptor_value_with_offset(
&self,
id: &DescriptorId,
value: impl Into<Vec<u8>>,
offset: usize
) -> Result<(), BluetoothError>
pub async fn write_descriptor_value_with_offset( &self, id: &DescriptorId, value: impl Into<Vec<u8>>, offset: usize ) -> Result<(), BluetoothError>
Write the given value to the given GATT descriptor, starting from the given offset.
sourcepub async fn start_notify(
&self,
id: &CharacteristicId
) -> Result<(), BluetoothError>
pub async fn start_notify( &self, id: &CharacteristicId ) -> Result<(), BluetoothError>
Start notifications on the given GATT characteristic.
sourcepub async fn stop_notify(
&self,
id: &CharacteristicId
) -> Result<(), BluetoothError>
pub async fn stop_notify( &self, id: &CharacteristicId ) -> Result<(), BluetoothError>
Stop notifications on the given GATT characteristic.
sourcepub async fn event_stream(
&self
) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
pub async fn event_stream( &self ) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
Get a stream of events for all devices.
sourcepub async fn adapter_event_stream(
&self,
adapter: &AdapterId
) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
pub async fn adapter_event_stream( &self, adapter: &AdapterId ) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
Get a stream of events for a particular adapter. This includes events for all devices it discovers or connects to.
sourcepub async fn device_event_stream(
&self,
device: &DeviceId
) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
pub async fn device_event_stream( &self, device: &DeviceId ) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
Get a stream of events for a particular device. This includes events for all its characteristics.
Note that this will not include the device discovered event for that device, as it is considered an event for the adapter rather than the device itself.
sourcepub async fn characteristic_event_stream(
&self,
characteristic: &CharacteristicId
) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
pub async fn characteristic_event_stream( &self, characteristic: &CharacteristicId ) -> Result<impl Stream<Item = BluetoothEvent>, BluetoothError>
Get a stream of events for a particular characteristic of a device.
Trait Implementations§
source§impl Clone for BluetoothSession
impl Clone for BluetoothSession
source§fn clone(&self) -> BluetoothSession
fn clone(&self) -> BluetoothSession
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more