(
event: BluetoothEvent,
session: BluetoothSession,
adapter_id: AdapterId,
)
| 142 | } |
| 143 | |
| 144 | async fn central_events( |
| 145 | event: BluetoothEvent, |
| 146 | session: BluetoothSession, |
| 147 | adapter_id: AdapterId, |
| 148 | ) -> Option<Vec<CentralEvent>> { |
| 149 | match event { |
| 150 | BluetoothEvent::Device { |
| 151 | id, |
| 152 | event: device_event, |
| 153 | } if id.adapter() == adapter_id => match device_event { |
| 154 | DeviceEvent::Discovered => { |
| 155 | let device = session.get_device_info(&id).await.ok()?; |
| 156 | let peripheral_id: PeripheralId = device.id.into(); |
| 157 | let mut events = vec![CentralEvent::DeviceDiscovered(peripheral_id.clone())]; |
| 158 | // BlueZ may already know the device's services (from cache or the |
| 159 | // advertisement). Emit a ServicesAdvertisement so listeners don't |
| 160 | // have to wait for a separate PropertiesChanged signal that may |
| 161 | // never arrive for cached devices. |
| 162 | if !device.services.is_empty() { |
| 163 | events.push(CentralEvent::ServicesAdvertisement { |
| 164 | id: peripheral_id, |
| 165 | services: device.services, |
| 166 | }); |
| 167 | } |
| 168 | Some(events) |
| 169 | } |
| 170 | DeviceEvent::Connected { connected } => { |
| 171 | if connected { |
| 172 | Some(vec![CentralEvent::DeviceConnected(id.into())]) |
| 173 | } else { |
| 174 | Some(vec![CentralEvent::DeviceDisconnected(id.into())]) |
| 175 | } |
| 176 | } |
| 177 | DeviceEvent::Rssi { rssi } => { |
| 178 | let device = session.get_device_info(&id).await.ok()?; |
| 179 | Some(vec![CentralEvent::RssiUpdate { |
| 180 | id: device.id.into(), |
| 181 | rssi, |
| 182 | }]) |
| 183 | } |
| 184 | DeviceEvent::ManufacturerData { manufacturer_data } => { |
| 185 | let device = session.get_device_info(&id).await.ok()?; |
| 186 | Some(vec![CentralEvent::ManufacturerDataAdvertisement { |
| 187 | id: device.id.into(), |
| 188 | manufacturer_data, |
| 189 | }]) |
| 190 | } |
| 191 | DeviceEvent::ServiceData { service_data } => { |
| 192 | let device = session.get_device_info(&id).await.ok()?; |
| 193 | Some(vec![CentralEvent::ServiceDataAdvertisement { |
| 194 | id: device.id.into(), |
| 195 | service_data, |
| 196 | }]) |
| 197 | } |
| 198 | DeviceEvent::Services { services } => { |
| 199 | let device = session.get_device_info(&id).await.ok()?; |
| 200 | Some(vec![CentralEvent::ServicesAdvertisement { |
| 201 | id: device.id.into(), |
no test coverage detected