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
use crate::{sys, Characteristic, Result, Uuid};
/// A Bluetooth GATT service
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Service(pub(crate) sys::service::ServiceImpl);
impl Service {
/// The [`Uuid`] identifying the type of this GATT service
///
/// # Panics
///
/// On Linux, this method will panic if there is a current Tokio runtime and it is single-threaded, if there is no
/// current Tokio runtime and creating one fails, or if the underlying [`Service::uuid_async()`] method
/// fails.
#[inline]
pub fn uuid(&self) -> Uuid {
self.0.uuid()
}
/// The [`Uuid`] identifying the type of this GATT service
#[inline]
pub async fn uuid_async(&self) -> Result<Uuid> {
self.0.uuid_async().await
}
/// Whether this is a primary service of the device.
///
/// # Platform specific
///
/// Returns [`NotSupported`][crate::error::ErrorKind::NotSupported] on Windows.
#[inline]
pub async fn is_primary(&self) -> Result<bool> {
self.0.is_primary().await
}
/// Discover all characteristics associated with this service.
#[inline]
pub async fn discover_characteristics(&self) -> Result<Vec<Characteristic>> {
self.0.discover_characteristics().await
}
/// Discover the characteristic(s) with the given [`Uuid`].
#[inline]
pub async fn discover_characteristics_with_uuid(&self, uuid: Uuid) -> Result<Vec<Characteristic>> {
self.0.discover_characteristics_with_uuid(uuid).await
}
/// Get previously discovered characteristics.
///
/// If no characteristics have been discovered yet, this method will perform characteristic discovery.
#[inline]
pub async fn characteristics(&self) -> Result<Vec<Characteristic>> {
self.0.characteristics().await
}
/// Discover the included services of this service.
#[inline]
pub async fn discover_included_services(&self) -> Result<Vec<Service>> {
self.0.discover_included_services().await
}
/// Discover the included service(s) with the given [`Uuid`].
#[inline]
pub async fn discover_included_services_with_uuid(&self, uuid: Uuid) -> Result<Vec<Service>> {
self.0.discover_included_services_with_uuid(uuid).await
}
/// Get previously discovered included services.
///
/// If no included services have been discovered yet, this method will perform included service discovery.
#[inline]
pub async fn included_services(&self) -> Result<Vec<Service>> {
self.0.included_services().await
}
}