pub async fn new() -> Result<Self> {
        let (resource, connection) = spawn_blocking(connection::new_system_sync).await??;
        let dbus_task = tokio::spawn(resource);
        log::trace!("Connected to D-Bus with unique name {}", &connection.unique_name());

        let mut crossroads = Crossroads::new();
        crossroads.set_async_support(Some((
            connection.clone(),
            Box::new(|x| {
                tokio::spawn(x);
            }),
        )));

        let le_advertisment_token = Advertisement::register_interface(&mut crossroads);
        let gatt_service_token = gatt::local::RegisteredService::register_interface(&mut crossroads);
        let gatt_reg_characteristic_token =
            gatt::local::RegisteredCharacteristic::register_interface(&mut crossroads);
        let gatt_reg_characteristic_descriptor_token =
            gatt::local::RegisteredDescriptor::register_interface(&mut crossroads);
        let gatt_profile_token = gatt::local::Profile::register_interface(&mut crossroads);
        let agent_token = RegisteredAgent::register_interface(&mut crossroads);
        let profile_token = RegisteredProfile::register_interface(&mut crossroads);

        let (event_sub_tx, event_sub_rx) = mpsc::channel(1);
        Event::handle_connection(connection.clone(), event_sub_rx).await?;

        let inner = Arc::new(SessionInner {
            connection: connection.clone(),
            crossroads: Mutex::new(crossroads),
            le_advertisment_token,
            gatt_reg_service_token: gatt_service_token,
            gatt_reg_characteristic_token,
            gatt_reg_characteristic_descriptor_token,
            gatt_profile_token,
            agent_token,
            profile_token,
            single_sessions: Mutex::new(HashMap::new()),
            event_sub_tx,
            dbus_task,
        });

        let mc_callback = connection.add_match(MatchRule::new_method_call()).await?;
        let mc_inner = Arc::downgrade(&inner);
        tokio::spawn(async move {
            let (_mc_callback, mut mc_stream) = mc_callback.msg_stream();
            while let Some(msg) = mc_stream.next().await {
                let mc_inner = match mc_inner.upgrade() {
                    Some(inner) => inner,
                    None => return,
                };
                let mut crossroads = mc_inner.crossroads.lock().await;
                let _ = crossroads.handle_message(msg, &*mc_inner.connection);
            }
        });

        Ok(Self { inner })
    }
/// Create a new Bluetooth session.
///
/// This establishes a connection to the system Bluetooth daemon over D-Bus.
Create a new Bluetooth session.
This establishes a connection to the system Bluetooth daemon over D-Bus.
Create a new Bluetooth session . This establishes a connection to the system Bluetooth daemon over D - Bus .
pub async fn new() -> Result<Self> {
        let (resource, connection) = spawn_blocking(connection::new_system_sync).await??;
        let dbus_task = tokio::spawn(resource);
        log::trace!("Connected to D-Bus with unique name {}", &connection.unique_name());
        let mut crossroads = Crossroads::new();
        crossroads.set_async_support(Some((
            connection.clone(),
            Box::new(|x| {
                tokio::spawn(x);
            }),
        )));
        let le_advertisment_token = Advertisement::register_interface(&mut crossroads);
        let gatt_service_token = gatt::local::RegisteredService::register_interface(&mut crossroads);
        let gatt_reg_characteristic_token =
            gatt::local::RegisteredCharacteristic::register_interface(&mut crossroads);
        let gatt_reg_characteristic_descriptor_token =
            gatt::local::RegisteredDescriptor::register_interface(&mut crossroads);
        let gatt_profile_token = gatt::local::Profile::register_interface(&mut crossroads);
        let agent_token = RegisteredAgent::register_interface(&mut crossroads);
        let profile_token = RegisteredProfile::register_interface(&mut crossroads);
        let (event_sub_tx, event_sub_rx) = mpsc::channel(1);
        Event::handle_connection(connection.clone(), event_sub_rx).await?;
        let inner = Arc::new(SessionInner {
            connection: connection.clone(),
            crossroads: Mutex::new(crossroads),
            le_advertisment_token,
            gatt_reg_service_token: gatt_service_token,
            gatt_reg_characteristic_token,
            gatt_reg_characteristic_descriptor_token,
            gatt_profile_token,
            agent_token,
            profile_token,
            single_sessions: Mutex::new(HashMap::new()),
            event_sub_tx,
            dbus_task,
        });
        let mc_callback = connection.add_match(MatchRule::new_method_call()).await?;
        let mc_inner = Arc::downgrade(&inner);
        tokio::spawn(async move {
            let (_mc_callback, mut mc_stream) = mc_callback.msg_stream();
            while let Some(msg) = mc_stream.next().await {
                let mc_inner = match mc_inner.upgrade() {
                    Some(inner) => inner,
                    None => return,
                };
                let mut crossroads = mc_inner.crossroads.lock().await;
                let _ = crossroads.handle_message(msg, &*mc_inner.connection);
            }
        });
        Ok(Self { inner })
    }
pub async fn new ( ) -> Result < Self > { let ( resource , connection ) = spawn_blocking ( connection :: new_system_sync ) . await ? ? ; let dbus_task = tokio :: spawn ( resource ) ; log :: trace ! ( " " connection unique_name ( ) ) ; let mut crossroads = Crossroads :: new ( ) ; crossroads . set_async_support ( Some ( ( connection . clone ( ) , Box :: new ( | x | { tokio :: spawn ( x ) ; } ) , ) ) ) ; let le_advertisment_token = Advertisement :: register_interface ( & mut crossroads ) ; let gatt_service_token = gatt :: local :: RegisteredService :: register_interface ( & mut crossroads ) ; let gatt_reg_characteristic_token = gatt :: local :: RegisteredCharacteristic :: register_interface ( & mut crossroads ) ; let gatt_reg_characteristic_descriptor_token = gatt :: local :: RegisteredDescriptor :: register_interface ( & mut crossroads ) ; let gatt_profile_token = gatt :: local :: Profile :: register_interface ( & mut crossroads ) ; let agent_token = RegisteredAgent :: register_interface ( & mut crossroads ) ; let profile_token = RegisteredProfile :: register_interface ( & mut crossroads ) ; let ( event_sub_tx , event_sub_rx ) = mpsc :: channel ( 1 ) ; Event :: handle_connection ( connection . clone ( ) , event_sub_rx ) . await ? ; let inner = Arc :: new ( SessionInner { connection : connection . clone ( ) , crossroads : Mutex :: new ( crossroads ) , le_advertisment_token , gatt_reg_service_token : gatt_service_token , gatt_reg_characteristic_token , gatt_reg_characteristic_descriptor_token , gatt_profile_token , agent_token , profile_token , single_sessions : Mutex :: new ( HashMap :: new ( ) ) , event_sub_tx , dbus_task , } ) ; let mc_callback = connection . add_match ( MatchRule :: new_method_call ( ) ) . await ? ; let mc_inner = Arc :: downgrade ( & inner ) ; tokio :: spawn ( async move { let ( _mc_callback , mut mc_stream ) = mc_callback . msg_stream ( ) ; while let Some ( msg ) = mc_stream . next ( ) . await { let mc_inner = match mc_inner . upgrade ( ) { Some ( inner ) => inner , None => return , } ; let mut crossroads = mc_inner . crossroads . lock ( ) . await ; let _ = crossroads . handle_message ( msg , & * mc_inner . connection ) ; } } ) ; Ok ( Self { inner } ) }
Create a new Bluetooth session.
Create a new Bluetooth session .