(&self)
| 305 | } |
| 306 | |
| 307 | async fn discover_services(&self) -> Result<()> { |
| 308 | let future = self.with_obj(|env, obj| JSendFuture::try_from(obj.discover_services()?))?; |
| 309 | let result_ref = future.await?; |
| 310 | self.with_obj(|env, _obj| { |
| 311 | use std::iter::FromIterator; |
| 312 | |
| 313 | let result = JPollResult::from_env(env, result_ref.as_obj())?; |
| 314 | let obj = get_poll_result(env, result)?; |
| 315 | let list = JList::from_env(env, obj)?; |
| 316 | let mut peripheral_services = Vec::new(); |
| 317 | let mut peripheral_characteristics = Vec::new(); |
| 318 | |
| 319 | for service in list.iter()? { |
| 320 | let service = JBluetoothGattService::from_env(env, service)?; |
| 321 | let mut characteristics = BTreeSet::<Characteristic>::new(); |
| 322 | for characteristic in service.get_characteristics()? { |
| 323 | let mut descriptors = BTreeSet::new(); |
| 324 | for descriptor in characteristic.get_descriptors()? { |
| 325 | descriptors.insert(Descriptor { |
| 326 | uuid: descriptor.get_uuid()?, |
| 327 | service_uuid: service.get_uuid()?, |
| 328 | characteristic_uuid: characteristic.get_uuid()?, |
| 329 | }); |
| 330 | } |
| 331 | let char = Characteristic { |
| 332 | service_uuid: service.get_uuid()?, |
| 333 | uuid: characteristic.get_uuid()?, |
| 334 | properties: characteristic.get_properties()?, |
| 335 | descriptors: descriptors.clone(), |
| 336 | }; |
| 337 | // Only consider the first characteristic of each UUID |
| 338 | // This "should" be unique, but of course it's not enforced |
| 339 | if characteristics |
| 340 | .iter() |
| 341 | .filter(|c| c.service_uuid == char.service_uuid && c.uuid == char.uuid) |
| 342 | .count() |
| 343 | == 0 |
| 344 | { |
| 345 | characteristics.insert(char.clone()); |
| 346 | peripheral_characteristics.push(char.clone()); |
| 347 | } |
| 348 | } |
| 349 | peripheral_services.push(Service { |
| 350 | uuid: service.get_uuid()?, |
| 351 | primary: service.is_primary()?, |
| 352 | characteristics, |
| 353 | }) |
| 354 | } |
| 355 | let mut guard = self.shared.lock().map_err(Into::<Error>::into)?; |
| 356 | guard.services = BTreeSet::from_iter(peripheral_services.clone()); |
| 357 | guard.characteristics = BTreeSet::from_iter(peripheral_characteristics.clone()); |
| 358 | Ok(()) |
| 359 | }) |
| 360 | } |
| 361 | |
| 362 | async fn write( |
| 363 | &self, |
nothing calls this directly
no test coverage detected