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

Method notifications

src/droidplug/peripheral.rs:407–440  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

405 }
406
407 async fn notifications(&self) -> Result<Pin<Box<dyn Stream<Item = ValueNotification> + Send>>> {
408 use futures::stream::StreamExt;
409 let shared = self.shared.clone();
410 let stream = self.with_obj(|_env, obj| JSendStream::try_from(obj.get_notifications()?))?;
411 let stream = stream
412 .map(move |item| match item {
413 Ok(item) => {
414 let env = global_jvm().get_env()?;
415 let item = item.as_obj();
416 let characteristic = JBluetoothGattCharacteristic::from_env(&env, item)?;
417 let uuid = characteristic.get_uuid()?;
418 let value = characteristic.get_value()?;
419 let service_uuid = shared
420 .lock()
421 .ok()
422 .and_then(|guard| {
423 guard
424 .services
425 .iter()
426 .find(|s| s.characteristics.iter().any(|c| c.uuid == uuid))
427 .map(|s| s.uuid)
428 })
429 .unwrap_or_default();
430 Ok(ValueNotification {
431 uuid,
432 service_uuid,
433 value,
434 })
435 }
436 Err(err) => Err(err),
437 })
438 .filter_map(|item| async { item.ok() });
439 Ok(Box::pin(stream))
440 }
441
442 async fn read_rssi(&self) -> Result<i16> {
443 let future = self.with_obj(|env, obj| {

Callers

nothing calls this directly

Calls 6

global_jvmFunction · 0.85
with_objMethod · 0.80
get_notificationsMethod · 0.80
get_uuidMethod · 0.80
get_valueMethod · 0.80
iterMethod · 0.80

Tested by

no test coverage detected