/// Handle a single request event from the avdtp peer.
Handle a single request event from the avdtp peer.
Handle a single request event from the avdtp peer .
async fn handle_request(&mut self, r: avdtp::Request) -> avdtp::Result<()> {
        fx_vlog!(1, "Handling {:?} from peer..", r);
        match r {
            avdtp::Request::Discover { responder } => responder.send(&self.local.information()),
            avdtp::Request::GetCapabilities { responder, stream_id }
            | avdtp::Request::GetAllCapabilities { responder, stream_id } => {
                match self.local.get_endpoint(&stream_id) {
                    None => responder.reject(avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => responder.send(stream.capabilities()),
                }
            }
            avdtp::Request::Open { responder, stream_id } => {
                match self.local.get_endpoint(&stream_id) {
                    None => responder.reject(avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => match stream.establish() {
                        Ok(()) => {
                            self.opening = Some(stream_id);
                            responder.send()
                        }
                        Err(_) => responder.reject(avdtp::ErrorCode::BadState),
                    },
                }
            }
            avdtp::Request::Close { responder, stream_id } => {
                match self.local.get_endpoint(&stream_id) {
                    None => responder.reject(avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => stream.release(responder, &self.peer).await,
                }
            }
            avdtp::Request::SetConfiguration {
                responder,
                local_stream_id,
                remote_stream_id,
                capabilities,
            } => {
                let stream = match self.local.get_endpoint(&local_stream_id) {
                    None => return responder.reject(None, avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => stream,
                };
                // TODO(BT-695): Confirm the MediaCodec parameters are OK
                match stream.configure(&remote_stream_id, capabilities.clone()) {
                    Ok(_) => responder.send(),
                    Err(e) => {
                        // Only happens when this is already configured.
                        responder.reject(None, avdtp::ErrorCode::SepInUse)?;
                        Err(e)
                    }
                }
            }
            avdtp::Request::GetConfiguration { stream_id, responder } => {
                let stream = match self.local.get_endpoint(&stream_id) {
                    None => return responder.reject(avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => stream,
                };
                match stream.get_configuration() {
                    Ok(c) => responder.send(&c),
                    Err(e) => {
                        // Only happens when the stream is in the wrong state
                        responder.reject(avdtp::ErrorCode::BadState)?;
                        Err(e)
                    }
                }
            }
            avdtp::Request::Reconfigure { responder, local_stream_id, capabilities } => {
                let stream = match self.local.get_endpoint(&local_stream_id) {
                    None => return responder.reject(None, avdtp::ErrorCode::BadAcpSeid),
                    Some(stream) => stream,
                };
                // TODO(40768): Actually tweak the codec parameters.
                match stream.reconfigure(capabilities) {
                    Ok(_) => responder.send(),
                    Err(e) => {
                        responder.reject(None, avdtp::ErrorCode::BadState)?;
                        Err(e)
                    }
                }
            }
            avdtp::Request::Start { responder, stream_ids } => {
                for seid in stream_ids {
                    let res = self.start_endpoint(&seid);
                    if let Err(code) = res {
                        return responder.reject(&seid, code);
                    }
                }
                responder.send()
            }
            avdtp::Request::Suspend { responder, stream_ids } => {
                for seid in stream_ids {
                    let res = self
                        .local
                        .get_mut(&seid)
                        .and_then(|x| x.stop().or(Err(avdtp::ErrorCode::BadState)));
                    if let Err(code) = res {
                        return responder.reject(&seid, code);
                    }
                }
                responder.send()
            }
            avdtp::Request::Abort { responder, stream_id } => {
                let stream = match self.local.get_endpoint(&stream_id) {
                    // No response shall be sent if the SEID is not valid. AVDTP 8.16.2
                    None => return Ok(()),
                    Some(stream) => stream,
                };
                stream.abort(None).await?;
                self.opening = self.opening.take().filter(|id| id != &stream_id);
                let _ = self
                    .local
                    .get_mut(&stream_id)
                    .and_then(|x| x.stop().or(Err(avdtp::ErrorCode::BadState)));
                responder.send()
            }
        }
    }
async fn handle_request ( & mut self , r : avdtp :: Request ) -> avdtp :: Result < ( ) > { fx_vlog ! ( 1 " " r ) ; match r { avdtp :: Request :: Discover { responder } => responder . send ( & self . local . information ( ) ) , avdtp :: Request :: GetCapabilities { responder , stream_id } | avdtp :: Request :: GetAllCapabilities { responder , stream_id } => { match self . local . get_endpoint ( & stream_id ) { None => responder . reject ( avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => responder . send ( stream . capabilities ( ) ) , } } avdtp :: Request :: Open { responder , stream_id } => { match self . local . get_endpoint ( & stream_id ) { None => responder . reject ( avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => match stream . establish ( ) { Ok ( ( ) ) => { self . opening = Some ( stream_id ) ; responder . send ( ) } Err ( _ ) => responder . reject ( avdtp :: ErrorCode :: BadState ) , } , } } avdtp :: Request :: Close { responder , stream_id } => { match self . local . get_endpoint ( & stream_id ) { None => responder . reject ( avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => stream . release ( responder , & self . peer ) . await , } } avdtp :: Request :: SetConfiguration { responder , local_stream_id , remote_stream_id , capabilities , } => { let stream = match self . local . get_endpoint ( & local_stream_id ) { None => return responder . reject ( None , avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => stream , } ; // TODO(BT-695): Confirm the MediaCodec parameters are OK match stream . configure ( & remote_stream_id , capabilities . clone ( ) ) { Ok ( _ ) => responder . send ( ) , Err ( e ) => { // Only happens when this is already configured. responder . reject ( None , avdtp :: ErrorCode :: SepInUse ) ? ; Err ( e ) } } } avdtp :: Request :: GetConfiguration { stream_id , responder } => { let stream = match self . local . get_endpoint ( & stream_id ) { None => return responder . reject ( avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => stream , } ; match stream . get_configuration ( ) { Ok ( c ) => responder . send ( & c ) , Err ( e ) => { // Only happens when the stream is in the wrong state responder . reject ( avdtp :: ErrorCode :: BadState ) ? ; Err ( e ) } } } avdtp :: Request :: Reconfigure { responder , local_stream_id , capabilities } => { let stream = match self . local . get_endpoint ( & local_stream_id ) { None => return responder . reject ( None , avdtp :: ErrorCode :: BadAcpSeid ) , Some ( stream ) => stream , } ; // TODO(40768): Actually tweak the codec parameters. match stream . reconfigure ( capabilities ) { Ok ( _ ) => responder . send ( ) , Err ( e ) => { responder . reject ( None , avdtp :: ErrorCode :: BadState ) ? ; Err ( e ) } } } avdtp :: Request :: Start { responder , stream_ids } => { for seid in stream_ids { let res = self . start_endpoint ( & seid ) ; if let Err ( code ) = res { return responder . reject ( & seid , code ) ; } } responder . send ( ) } avdtp :: Request :: Suspend { responder , stream_ids } => { for seid in stream_ids { let res = self . local . get_mut ( & seid ) . and_then ( | x | x . stop ( ) . or ( Err ( avdtp :: ErrorCode :: BadState ) ) ) ; if let Err ( code ) = res { return responder . reject ( & seid , code ) ; } } responder . send ( ) } avdtp :: Request :: Abort { responder , stream_id } => { let stream = match self . local . get_endpoint ( & stream_id ) { // No response shall be sent if the SEID is not valid. AVDTP 8.16.2 None => return Ok ( ( ) ) , Some ( stream ) => stream , } ; stream . abort ( None ) . await ? ; self . opening = self . opening . take ( ) . filter ( | id | id != & stream_id ) ; let _ = self . local . get_mut ( & stream_id ) . and_then ( | x | x . stop ( ) . or ( Err ( avdtp :: ErrorCode :: BadState ) ) ) ; responder . send ( ) } } }
Handle a single request event from the avdtp peer.
Handle a single request event from the avdtp peer .
&mut self
r
avdtp::Request