/// Handles the specific browse channel command specified by `pdu_id`.
///
/// Returns an encoded response buffer to be sent.
/// Upon error, returns a StatusCode indicating point of failure to send over the
/// general reject.
Handles the specific browse channel command specified by `pdu_id`.
Returns an encoded response buffer to be sent.
Upon error, returns a StatusCode indicating point of failure to send over the
general reject.
Handles the specific browse channel command specified by ` pdu_id ` . Returns an encoded response buffer to be sent . Upon error returns a StatusCode indicating point of failure to send over the general reject .
async fn handle_browse_command(
        pdu_id: PduId,
        parameters: Vec<u8>,
        target_delegate: Arc<TargetDelegate>,
    ) -> Result<Vec<u8>, StatusCode> {
        match pdu_id {
            PduId::GetFolderItems => {
                let get_folder_items_cmd = GetFolderItemsCommand::decode(&parameters)
                    .map_err(|_| StatusCode::InvalidParameter)?;
                trace!("Received GetFolderItems Command {:?}", get_folder_items_cmd);
                // Currently, for GetFolderItems, we only support MediaPlayerList scope.
                if get_folder_items_cmd.scope() != Scope::MediaPlayerList {
                    return Err(StatusCode::InvalidParameter);
                }
                // Get the media player items from the TargetDelegate.
                let folder_items = target_delegate
                    .send_get_media_player_items_command()
                    .await
                    .map_err(|e| StatusCode::from(e))?;
                // Use an arbitrary uid_counter for creating the response. Don't support
                // multiple players, so this value is irrelevant.
                let uid_counter: u16 = 0x1234;
                let media_player_items = folder_items.into_iter().map(|i| i.into()).collect();
                let resp = GetFolderItemsResponse::new(
                    StatusCode::Success,
                    uid_counter,
                    media_player_items,
                );
                // Encode the result into the output buffer.
                let mut buf = vec![0; resp.encoded_len()];
                resp.encode(&mut buf[..]).map_err(|_| StatusCode::ParameterContentError)?;
                Ok(buf)
            }
            PduId::GetTotalNumberOfItems => {
                let get_total_items_cmd = GetTotalNumberOfItemsCommand::decode(&parameters)
                    .map_err(|_| StatusCode::InvalidParameter)?;
                trace!("Received GetTotalNumberOfItems Command {:?}", get_total_items_cmd);
                // Currently, for GetTotalNumberOfItems, we only support MediaPlayerList scope.
                if get_total_items_cmd.scope() != Scope::MediaPlayerList {
                    return Err(StatusCode::InvalidParameter);
                }
                // Use an arbitrary uid_counter for creating the response. Don't support
                // multiple players, so this value is irrelevant.
                let uid_counter: u16 = 0x1234;
                let resp = GetTotalNumberOfItemsResponse::new(StatusCode::Success, uid_counter, 1);
                // Encode the result into the output buffer.
                let mut buf = vec![0; resp.encoded_len()];
                resp.encode(&mut buf[..]).map_err(|_| StatusCode::ParameterContentError)?;
                Ok(buf)
            }
            _ => {
                info!("[Browse Channel] Command unimplemented: {:?}", pdu_id);
                // Per AVRCP 1.6, Section 6.15.3, the TG will send `InvalidParameter` for a PDU ID
                // that it did not understand.
                return Err(StatusCode::InvalidParameter);
            }
        }
    }
async fn handle_browse_command ( pdu_id : PduId , parameters : Vec < u8 > , target_delegate : Arc < TargetDelegate > , ) -> Result < Vec < u8 > , StatusCode > { match pdu_id { PduId :: GetFolderItems => { let get_folder_items_cmd = GetFolderItemsCommand :: decode ( & parameters ) . map_err ( | _ | StatusCode :: InvalidParameter ) ? ; trace ! ( " " get_folder_items_cmd ) ; // Currently, for GetFolderItems, we only support MediaPlayerList scope. if get_folder_items_cmd . scope ( ) != Scope :: MediaPlayerList { return Err ( StatusCode :: InvalidParameter ) ; } // Get the media player items from the TargetDelegate. let folder_items = target_delegate . send_get_media_player_items_command ( ) . await . map_err ( | e | StatusCode :: from ( e ) ) ? ; // Use an arbitrary uid_counter for creating the response. Don't support // multiple players, so this value is irrelevant. let uid_counter : u16 = 0x1234 ; let media_player_items = folder_items . into_iter ( ) . map ( | i | i . into ( ) ) . collect ( ) ; let resp = GetFolderItemsResponse :: new ( StatusCode :: Success , uid_counter , media_player_items , ) ; // Encode the result into the output buffer. let mut buf = vec ! [ 0 resp encoded_len ( ) ] ; resp . encode ( & mut buf [ .. ] ) . map_err ( | _ | StatusCode :: ParameterContentError ) ? ; Ok ( buf ) } PduId :: GetTotalNumberOfItems => { let get_total_items_cmd = GetTotalNumberOfItemsCommand :: decode ( & parameters ) . map_err ( | _ | StatusCode :: InvalidParameter ) ? ; trace ! ( " " get_total_items_cmd ) ; // Currently, for GetTotalNumberOfItems, we only support MediaPlayerList scope. if get_total_items_cmd . scope ( ) != Scope :: MediaPlayerList { return Err ( StatusCode :: InvalidParameter ) ; } // Use an arbitrary uid_counter for creating the response. Don't support // multiple players, so this value is irrelevant. let uid_counter : u16 = 0x1234 ; let resp = GetTotalNumberOfItemsResponse :: new ( StatusCode :: Success , uid_counter , 1 ) ; // Encode the result into the output buffer. let mut buf = vec ! [ 0 resp encoded_len ( ) ] ; resp . encode ( & mut buf [ .. ] ) . map_err ( | _ | StatusCode :: ParameterContentError ) ? ; Ok ( buf ) } _ => { info ! ( " " pdu_id ) ; // Per AVRCP 1.6, Section 6.15.3, the TG will send `InvalidParameter` for a PDU ID // that it did not understand. return Err ( StatusCode :: InvalidParameter ) ; } } }
Handles the specific browse channel command specified by `pdu_id`.
Handles the specific browse channel command specified by ` pdu_id ` .
pdu_id
PduId
parameters
Vec<u8>
target_delegate
Arc<TargetDelegate>