fn handle_profile_event(
    evt: ProfileEvent,
    profile_svc: ProfileProxy,
    peers: Arc<Mutex<ConnectedPeers>>,
    inspect: &fuchsia_inspect::Inspector,
    controller_pool: Arc<Mutex<AvdtpControllerPool>>,
) -> Result<(), Error> {
    match evt {
        ProfileEvent::OnServiceFound { peer_id, profile, attributes } => {
            fx_log_info!(
                "Audio Source on {} with profile {:?}: {:?}",
                peer_id,
                profile,
                attributes
            );
            let peer_id = peer_id.parse().expect("peer ids from profile should parse");
            peers.lock().found(peer_id, profile);

            if peers.lock().is_connected(&peer_id) {
                return Ok(());
            }

            fx_vlog!(
                tag: "a2dp-sink",
                1,
                "A2DP sink - waiting {:?} before assuming INT role for peer {}.",
                INITIATOR_DELAY,
                peer_id,
            );

            let timer_expired = fuchsia_async::Timer::new(INITIATOR_DELAY.after_now());
            let inspect = inspect.root().create_child(format!("peer {}", peer_id));
            fasync::spawn(initiate_after_timeout(
                peer_id,
                peers.clone(),
                profile_svc,
                inspect,
                timer_expired,
            ));
        }
        ProfileEvent::OnConnected { device_id, service_id: _, channel, protocol } => {
            fx_log_info!("Connection from {}: {:?} {:?}!", device_id, channel, protocol);
            let peer_id = device_id.parse().expect("peer ids from profile should parse");
            let socket = match channel.socket {
                Some(s) => s,
                None => {
                    fx_log_warn!("socket in OnConnected event missing");
                    return Ok(());
                }
            };
            let inspect = inspect.root().create_child(format!("peer {}", device_id));
            // The remote peer connected to us, `initiate_streaming` = false.
            peers.lock().connected(inspect, peer_id, socket, false);
            if let Some(peer) = peers.lock().get(&peer_id) {
                // Add the controller to the peers
                controller_pool.lock().peer_connected(peer_id, peer.read().avdtp_peer());
            }
        }
    }

    Ok(())
}
/// Handles incoming profile events.
///
/// If a remote device connects to us, store the transport channel and assume the ACP role.
/// If the remote device is found, but does not connect, wait `INITIATOR_DELAY` and attempt
/// to assume the INT role.
Handles incoming profile events.
If a remote device connects to us, store the transport channel and assume the ACP role.
If the remote device is found, but does not connect, wait `INITIATOR_DELAY` and attempt
to assume the INT role.
Handles incoming profile events . If a remote device connects to us store the transport channel and assume the ACP role . If the remote device is found but does not connect wait ` INITIATOR_DELAY ` and attempt to assume the INT role .
fn handle_profile_event(
    evt: ProfileEvent,
    profile_svc: ProfileProxy,
    peers: Arc<Mutex<ConnectedPeers>>,
    inspect: &fuchsia_inspect::Inspector,
    controller_pool: Arc<Mutex<AvdtpControllerPool>>,
) -> Result<(), Error> {
    match evt {
        ProfileEvent::OnServiceFound { peer_id, profile, attributes } => {
            fx_log_info!(
                "Audio Source on {} with profile {:?}: {:?}",
                peer_id,
                profile,
                attributes
            );
            let peer_id = peer_id.parse().expect("peer ids from profile should parse");
            peers.lock().found(peer_id, profile);
            if peers.lock().is_connected(&peer_id) {
                return Ok(());
            }
            fx_vlog!(
                tag: "a2dp-sink",
                1,
                "A2DP sink - waiting {:?} before assuming INT role for peer {}.",
                INITIATOR_DELAY,
                peer_id,
            );
            let timer_expired = fuchsia_async::Timer::new(INITIATOR_DELAY.after_now());
            let inspect = inspect.root().create_child(format!("peer {}", peer_id));
            fasync::spawn(initiate_after_timeout(
                peer_id,
                peers.clone(),
                profile_svc,
                inspect,
                timer_expired,
            ));
        }
        ProfileEvent::OnConnected { device_id, service_id: _, channel, protocol } => {
            fx_log_info!("Connection from {}: {:?} {:?}!", device_id, channel, protocol);
            let peer_id = device_id.parse().expect("peer ids from profile should parse");
            let socket = match channel.socket {
                Some(s) => s,
                None => {
                    fx_log_warn!("socket in OnConnected event missing");
                    return Ok(());
                }
            };
            let inspect = inspect.root().create_child(format!("peer {}", device_id));
            // The remote peer connected to us, `initiate_streaming` = false.
            peers.lock().connected(inspect, peer_id, socket, false);
            if let Some(peer) = peers.lock().get(&peer_id) {
                // Add the controller to the peers
                controller_pool.lock().peer_connected(peer_id, peer.read().avdtp_peer());
            }
        }
    }
    Ok(())
}
fn handle_profile_event ( evt : ProfileEvent , profile_svc : ProfileProxy , peers : Arc < Mutex < ConnectedPeers > > , inspect : & fuchsia_inspect :: Inspector , controller_pool : Arc < Mutex < AvdtpControllerPool > > , ) -> Result < ( ) , Error > { match evt { ProfileEvent :: OnServiceFound { peer_id , profile , attributes } => { fx_log_info ! ( " " peer_id profile attributes ) ; let peer_id = peer_id . parse ( ) . expect ( " " ) ; peers . lock ( ) . found ( peer_id , profile ) ; if peers . lock ( ) . is_connected ( & peer_id ) { return Ok ( ( ) ) ; } fx_vlog ! ( tag " " 1 " " INITIATOR_DELAY peer_id ) ; let timer_expired = fuchsia_async :: Timer :: new ( INITIATOR_DELAY . after_now ( ) ) ; let inspect = inspect . root ( ) . create_child ( format ! ( " " peer_id ) ) ; fasync :: spawn ( initiate_after_timeout ( peer_id , peers . clone ( ) , profile_svc , inspect , timer_expired , ) ) ; } ProfileEvent :: OnConnected { device_id , service_id : _ , channel , protocol } => { fx_log_info ! ( " " device_id channel protocol ) ; let peer_id = device_id . parse ( ) . expect ( " " ) ; let socket = match channel . socket { Some ( s ) => s , None => { fx_log_warn ! ( " " ) ; return Ok ( ( ) ) ; } } ; let inspect = inspect . root ( ) . create_child ( format ! ( " " device_id ) ) ; // The remote peer connected to us, `initiate_streaming` = false. peers . lock ( ) . connected ( inspect , peer_id , socket , false ) ; if let Some ( peer ) = peers . lock ( ) . get ( & peer_id ) { // Add the controller to the peers controller_pool . lock ( ) . peer_connected ( peer_id , peer . read ( ) . avdtp_peer ( ) ) ; } } } Ok ( ( ) ) }
Handles incoming profile events.
Handles incoming profile events .
evt
ProfileEvent
profile_svc
ProfileProxy
peers
Arc<Mutex<ConnectedPeers>>
inspect
&fuchsia_inspect::Inspector
controller_pool
Arc<Mutex<AvdtpControllerPool>>
evt
ProfileEvent
profile_svc
ProfileProxy
peers
Arc<Mutex<ConnectedPeers>>
inspect
&fuchsia_inspect::Inspector
controller_pool
Arc<Mutex<AvdtpControllerPool>>