pub async fn avrcp_client_stream_handler<F>(
    mut stream: PeerManagerRequestStream,
    mut sender: mpsc::Sender<ServiceRequest>,
    spawn_fn: F,
) -> Result<(), anyhow::Error>
where
    F: Fn(Controller, ControllerRequestStream),
{
    while let Some(req) = stream.try_next().await? {
        match req {
            PeerManagerRequest::GetControllerForTarget { peer_id, client, responder } => {
                let client: fidl::endpoints::ServerEnd<ControllerMarker> = client;

                fx_log_info!("New connection request for {}", peer_id);

                match client.into_stream() {
                    Err(err) => {
                        fx_log_warn!("Err unable to create server end point from stream {:?}", err);
                        responder.send(&mut Err(zx::Status::UNAVAILABLE.into_raw()))?;
                    }
                    Ok(client_stream) => {
                        let (response, pcr) = ServiceRequest::new_controller_request(peer_id);
                        sender.try_send(pcr)?;
                        let controller = response.into_future().await?;
                        spawn_fn(controller, client_stream);
                        responder.send(&mut Ok(()))?;
                    }
                }
            }
            PeerManagerRequest::SetAbsoluteVolumeHandler { handler, responder, peer_id: _ } => {
                match handler.into_proxy() {
                    Ok(absolute_volume_handler) => {
                        let (response, register_absolute_volume_handler_request) =
                            ServiceRequest::new_register_absolute_volume_handler_request(
                                absolute_volume_handler,
                            );
                        sender.try_send(register_absolute_volume_handler_request)?;
                        match response.into_future().await? {
                            Ok(_) => responder.send(&mut Ok(()))?,
                            Err(_) => {
                                responder.send(&mut Err(zx::Status::ALREADY_BOUND.into_raw()))?
                            }
                        }
                    }
                    Err(_) => responder.send(&mut Err(zx::Status::INVALID_ARGS.into_raw()))?,
                };
            }
            PeerManagerRequest::RegisterTargetHandler { handler, responder } => {
                match handler.into_proxy() {
                    Ok(target_handler) => {
                        let (response, register_target_handler_request) =
                            ServiceRequest::new_register_target_handler_request(target_handler);
                        sender.try_send(register_target_handler_request)?;
                        match response.into_future().await? {
                            Ok(_) => responder.send(&mut Ok(()))?,
                            Err(_) => {
                                responder.send(&mut Err(zx::Status::ALREADY_BOUND.into_raw()))?
                            }
                        }
                    }
                    Err(_) => responder.send(&mut Err(zx::Status::INVALID_ARGS.into_raw()))?,
                };
            }
        }
    }
    Ok(())
}
/// Polls the stream for the PeerManager FIDL interface to set target handlers and respond with
/// new controller clients.
Polls the stream for the PeerManager FIDL interface to set target handlers and respond with
new controller clients.
Polls the stream for the PeerManager FIDL interface to set target handlers and respond with new controller clients .
pub async fn avrcp_client_stream_handler<F>(
    mut stream: PeerManagerRequestStream,
    mut sender: mpsc::Sender<ServiceRequest>,
    spawn_fn: F,
) -> Result<(), anyhow::Error>
where
    F: Fn(Controller, ControllerRequestStream),
{
    while let Some(req) = stream.try_next().await? {
        match req {
            PeerManagerRequest::GetControllerForTarget { peer_id, client, responder } => {
                let client: fidl::endpoints::ServerEnd<ControllerMarker> = client;
                fx_log_info!("New connection request for {}", peer_id);
                match client.into_stream() {
                    Err(err) => {
                        fx_log_warn!("Err unable to create server end point from stream {:?}", err);
                        responder.send(&mut Err(zx::Status::UNAVAILABLE.into_raw()))?;
                    }
                    Ok(client_stream) => {
                        let (response, pcr) = ServiceRequest::new_controller_request(peer_id);
                        sender.try_send(pcr)?;
                        let controller = response.into_future().await?;
                        spawn_fn(controller, client_stream);
                        responder.send(&mut Ok(()))?;
                    }
                }
            }
            PeerManagerRequest::SetAbsoluteVolumeHandler { handler, responder, peer_id: _ } => {
                match handler.into_proxy() {
                    Ok(absolute_volume_handler) => {
                        let (response, register_absolute_volume_handler_request) =
                            ServiceRequest::new_register_absolute_volume_handler_request(
                                absolute_volume_handler,
                            );
                        sender.try_send(register_absolute_volume_handler_request)?;
                        match response.into_future().await? {
                            Ok(_) => responder.send(&mut Ok(()))?,
                            Err(_) => {
                                responder.send(&mut Err(zx::Status::ALREADY_BOUND.into_raw()))?
                            }
                        }
                    }
                    Err(_) => responder.send(&mut Err(zx::Status::INVALID_ARGS.into_raw()))?,
                };
            }
            PeerManagerRequest::RegisterTargetHandler { handler, responder } => {
                match handler.into_proxy() {
                    Ok(target_handler) => {
                        let (response, register_target_handler_request) =
                            ServiceRequest::new_register_target_handler_request(target_handler);
                        sender.try_send(register_target_handler_request)?;
                        match response.into_future().await? {
                            Ok(_) => responder.send(&mut Ok(()))?,
                            Err(_) => {
                                responder.send(&mut Err(zx::Status::ALREADY_BOUND.into_raw()))?
                            }
                        }
                    }
                    Err(_) => responder.send(&mut Err(zx::Status::INVALID_ARGS.into_raw()))?,
                };
            }
        }
    }
    Ok(())
}
pub async fn avrcp_client_stream_handler < F > ( mut stream : PeerManagerRequestStream , mut sender : mpsc :: Sender < ServiceRequest > , spawn_fn : F , ) -> Result < ( ) , anyhow :: Error > where F : Fn ( Controller , ControllerRequestStream ) , { while let Some ( req ) = stream . try_next ( ) . await ? { match req { PeerManagerRequest :: GetControllerForTarget { peer_id , client , responder } => { let client : fidl :: endpoints :: ServerEnd < ControllerMarker > = client ; fx_log_info ! ( " " peer_id ) ; match client . into_stream ( ) { Err ( err ) => { fx_log_warn ! ( " " err ) ; responder . send ( & mut Err ( zx :: Status :: UNAVAILABLE . into_raw ( ) ) ) ? ; } Ok ( client_stream ) => { let ( response , pcr ) = ServiceRequest :: new_controller_request ( peer_id ) ; sender . try_send ( pcr ) ? ; let controller = response . into_future ( ) . await ? ; spawn_fn ( controller , client_stream ) ; responder . send ( & mut Ok ( ( ) ) ) ? ; } } } PeerManagerRequest :: SetAbsoluteVolumeHandler { handler , responder , peer_id : _ } => { match handler . into_proxy ( ) { Ok ( absolute_volume_handler ) => { let ( response , register_absolute_volume_handler_request ) = ServiceRequest :: new_register_absolute_volume_handler_request ( absolute_volume_handler , ) ; sender . try_send ( register_absolute_volume_handler_request ) ? ; match response . into_future ( ) . await ? { Ok ( _ ) => responder . send ( & mut Ok ( ( ) ) ) ? , Err ( _ ) => { responder . send ( & mut Err ( zx :: Status :: ALREADY_BOUND . into_raw ( ) ) ) ? } } } Err ( _ ) => responder . send ( & mut Err ( zx :: Status :: INVALID_ARGS . into_raw ( ) ) ) ? , } ; } PeerManagerRequest :: RegisterTargetHandler { handler , responder } => { match handler . into_proxy ( ) { Ok ( target_handler ) => { let ( response , register_target_handler_request ) = ServiceRequest :: new_register_target_handler_request ( target_handler ) ; sender . try_send ( register_target_handler_request ) ? ; match response . into_future ( ) . await ? { Ok ( _ ) => responder . send ( & mut Ok ( ( ) ) ) ? , Err ( _ ) => { responder . send ( & mut Err ( zx :: Status :: ALREADY_BOUND . into_raw ( ) ) ) ? } } } Err ( _ ) => responder . send ( & mut Err ( zx :: Status :: INVALID_ARGS . into_raw ( ) ) ) ? , } ; } } } Ok ( ( ) ) }
Polls the stream for the PeerManager FIDL interface to set target handlers and respond with
new controller clients.
Polls the stream for the PeerManager FIDL interface to set target handlers and respond with new controller clients .
stream
PeerManagerRequestStream
sender
mpsc::Sender<ServiceRequest>
spawn_fn
F
stream
PeerManagerRequestStream
sender
mpsc::Sender<ServiceRequest>
spawn_fn
F