/// Handles received notifications from the peer from the subscribed notifications streams and
/// dispatches the notifications back to the controller listeners
Handles received notifications from the peer from the subscribed notifications streams and
dispatches the notifications back to the controller listeners
Handles received notifications from the peer from the subscribed notifications streams and dispatches the notifications back to the controller listeners
fn handle_notification(
    notif: &NotificationEventId,
    peer: &Arc<RwLock<RemotePeer>>,
    data: &[u8],
) -> Result<bool, Error> {
    fx_vlog!(tag: "avrcp", 2, "received notification for {:?} {:?}", notif, data);
    let preamble = VendorDependentPreamble::decode(data).map_err(|e| Error::PacketError(e))?;
    let data = &data[preamble.encoded_len()..];
    if data.len() < preamble.parameter_length as usize {
        return Err(Error::UnexpectedResponse);
    }
    match notif {
        NotificationEventId::EventPlaybackStatusChanged => {
            let response = PlaybackStatusChangedNotificationResponse::decode(data)
                .map_err(|e| Error::PacketError(e))?;
            peer.write().handle_new_controller_notification_event(
                ControllerEvent::PlaybackStatusChanged(response.playback_status()),
            );
            Ok(false)
        }
        NotificationEventId::EventTrackChanged => {
            let response = TrackChangedNotificationResponse::decode(data)
                .map_err(|e| Error::PacketError(e))?;
            peer.write().handle_new_controller_notification_event(ControllerEvent::TrackIdChanged(
                response.identifier(),
            ));
            Ok(false)
        }
        NotificationEventId::EventPlaybackPosChanged => {
            let response = PlaybackPosChangedNotificationResponse::decode(data)
                .map_err(|e| Error::PacketError(e))?;
            peer.write().handle_new_controller_notification_event(
                ControllerEvent::PlaybackPosChanged(response.position()),
            );
            Ok(false)
        }
        NotificationEventId::EventVolumeChanged => {
            let response = VolumeChangedNotificationResponse::decode(data)
                .map_err(|e| Error::PacketError(e))?;
            peer.write().handle_new_controller_notification_event(ControllerEvent::VolumeChanged(
                response.volume(),
            ));
            Ok(false)
        }
        _ => Ok(true),
    }
}
fn handle_notification ( notif : & NotificationEventId , peer : & Arc < RwLock < RemotePeer > > , data : & [ u8 ] , ) -> Result < bool , Error > { fx_vlog ! ( tag " " 2 " " notif data ) ; let preamble = VendorDependentPreamble :: decode ( data ) . map_err ( | e | Error :: PacketError ( e ) ) ? ; let data = & data [ preamble . encoded_len ( ) .. ] ; if data . len ( ) < preamble . parameter_length as usize { return Err ( Error :: UnexpectedResponse ) ; } match notif { NotificationEventId :: EventPlaybackStatusChanged => { let response = PlaybackStatusChangedNotificationResponse :: decode ( data ) . map_err ( | e | Error :: PacketError ( e ) ) ? ; peer . write ( ) . handle_new_controller_notification_event ( ControllerEvent :: PlaybackStatusChanged ( response . playback_status ( ) ) , ) ; Ok ( false ) } NotificationEventId :: EventTrackChanged => { let response = TrackChangedNotificationResponse :: decode ( data ) . map_err ( | e | Error :: PacketError ( e ) ) ? ; peer . write ( ) . handle_new_controller_notification_event ( ControllerEvent :: TrackIdChanged ( response . identifier ( ) , ) ) ; Ok ( false ) } NotificationEventId :: EventPlaybackPosChanged => { let response = PlaybackPosChangedNotificationResponse :: decode ( data ) . map_err ( | e | Error :: PacketError ( e ) ) ? ; peer . write ( ) . handle_new_controller_notification_event ( ControllerEvent :: PlaybackPosChanged ( response . position ( ) ) , ) ; Ok ( false ) } NotificationEventId :: EventVolumeChanged => { let response = VolumeChangedNotificationResponse :: decode ( data ) . map_err ( | e | Error :: PacketError ( e ) ) ? ; peer . write ( ) . handle_new_controller_notification_event ( ControllerEvent :: VolumeChanged ( response . volume ( ) , ) ) ; Ok ( false ) } _ => Ok ( true ) , } }
Handles received notifications from the peer from the subscribed notifications streams and
dispatches the notifications back to the controller listeners
Handles received notifications from the peer from the subscribed notifications streams and dispatches the notifications back to the controller listeners
notif
&NotificationEventId
peer
&Arc<RwLock<RemotePeer>>
data
&[u8]