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

Function run_corebluetooth_thread

src/corebluetooth/internal.rs:1500–1524  ·  view source on GitHub ↗
(
    event_sender: Sender<CoreBluetoothEvent>,
)

Source from the content-addressed store, hash-verified

1498}
1499
1500pub fn run_corebluetooth_thread(
1501 event_sender: Sender<CoreBluetoothEvent>,
1502) -> Result<Sender<CoreBluetoothMessage>, Error> {
1503 let authorization = unsafe { CBManager::authorization_class() };
1504 if authorization != CBManagerAuthorization::AllowedAlways
1505 && authorization != CBManagerAuthorization::NotDetermined
1506 {
1507 warn!("Authorization status {:?}", authorization);
1508 return Err(Error::PermissionDenied);
1509 } else {
1510 trace!("Authorization status {:?}", authorization);
1511 }
1512 let (sender, receiver) = mpsc::channel::<CoreBluetoothMessage>(256);
1513 // CoreBluetoothInternal is !Send, so we need to keep it on a single thread.
1514 thread::spawn(move || {
1515 let runtime = runtime::Builder::new_current_thread().build().unwrap();
1516 runtime.block_on(async move {
1517 let mut cbi = CoreBluetoothInternal::new(receiver, event_sender);
1518 loop {
1519 cbi.wait_for_message().await;
1520 }
1521 })
1522 });
1523 Ok(sender)
1524}

Callers 1

newMethod · 0.85

Calls 1

wait_for_messageMethod · 0.80

Tested by

no test coverage detected