/// Controller that handles commands for SettingType::Audio.
/// TODO(go/fxb/35988): Hook up the presentation service to listen for the mic mute state.
Controller that handles commands for SettingType::Audio.
TODO(go/fxb/35988): Hook up the presentation service to listen for the mic mute state.
Controller that handles commands for SettingType :: Audio . TODO ( go / fxb / 35988 ) : Hook up the presentation service to listen for the mic mute state .
pub fn spawn_audio_controller<T: DeviceStorageFactory + Send + Sync + 'static>(
    context: Context<T>,
) -> BoxFuture<'static, SettingHandler> {
    let service_context_handle = context.environment.service_context_handle.clone();
    let storage_factory_handle = context.environment.storage_factory_handle.clone();
    let (audio_handler_tx, mut audio_handler_rx) = futures::channel::mpsc::unbounded::<Command>();
    let notifier_lock = Arc::<Mutex<Option<Notifier>>>::new(Mutex::new(None));
    // New additions
    let input_monitor_handle =
        InputMonitor::create(service_context_handle.clone(), notifier_lock.clone());
    let volume_controller_handle = VolumeController::create(
        service_context_handle.clone(),
        storage_factory_handle.clone(),
        notifier_lock.clone(),
        input_monitor_handle.clone(),
    );
    let volume_controller_handle_clone = volume_controller_handle.clone();
    fasync::spawn(async move {
        while let Some(command) = audio_handler_rx.next().await {
            match command {
                Command::ChangeState(state) => match state {
                    State::Listen(notifier) => {
                        *notifier_lock.lock().await = Some(notifier);
                    }
                    State::EndListen => {
                        *notifier_lock.lock().await = None;
                    }
                },
                Command::HandleRequest(request, responder) =>
                {
                    #[allow(unreachable_patterns)]
                    match request {
                        SettingRequest::Restore => {
                            volume_controller_handle_clone.lock().await.restore().await;
                        }
                        SettingRequest::SetVolume(volume) => {
                            responder
                                .send(
                                    volume_controller_handle_clone
                                        .lock()
                                        .await
                                        .set_volume(volume)
                                        .await,
                                )
                                .ok();
                        }
                        SettingRequest::Get => {
                            let response = match volume_controller_handle_clone
                                .lock()
                                .await
                                .get_info()
                                .await
                            {
                                Ok(info) => Ok(Some(SettingResponse::Audio(info))),
                                Err(e) => Err(e),
                            };
                            responder.send(response).ok();
                        }
                        _ => {
                            responder
                                .send(Err(SwitchboardError::UnimplementedRequest {
                                    setting_type: SettingType::Audio,
                                    request: request,
                                }))
                                .ok();
                        }
                    }
                }
            }
        }
        fx_log_err!("[audio_controller] exited service event loop");
    });
    Box::pin(async move { audio_handler_tx })
}
pub fn spawn_audio_controller < T : DeviceStorageFactory + Send + Sync + ' static > ( context : Context < T > , ) -> BoxFuture < ' static , SettingHandler > { let service_context_handle = context . environment . service_context_handle . clone ( ) ; let storage_factory_handle = context . environment . storage_factory_handle . clone ( ) ; let ( audio_handler_tx , mut audio_handler_rx ) = futures :: channel :: mpsc :: unbounded :: < Command > ( ) ; let notifier_lock = Arc :: < Mutex < Option < Notifier > > > :: new ( Mutex :: new ( None ) ) ; // New additions let input_monitor_handle = InputMonitor :: create ( service_context_handle . clone ( ) , notifier_lock . clone ( ) ) ; let volume_controller_handle = VolumeController :: create ( service_context_handle . clone ( ) , storage_factory_handle . clone ( ) , notifier_lock . clone ( ) , input_monitor_handle . clone ( ) , ) ; let volume_controller_handle_clone = volume_controller_handle . clone ( ) ; fasync :: spawn ( async move { while let Some ( command ) = audio_handler_rx . next ( ) . await { match command { Command :: ChangeState ( state ) => match state { State :: Listen ( notifier ) => { * notifier_lock . lock ( ) . await = Some ( notifier ) ; } State :: EndListen => { * notifier_lock . lock ( ) . await = None ; } } , Command :: HandleRequest ( request , responder ) => { # [ allow ( unreachable_patterns ) ] match request { SettingRequest :: Restore => { volume_controller_handle_clone . lock ( ) . await . restore ( ) . await ; } SettingRequest :: SetVolume ( volume ) => { responder . send ( volume_controller_handle_clone . lock ( ) . await . set_volume ( volume ) . await , ) . ok ( ) ; } SettingRequest :: Get => { let response = match volume_controller_handle_clone . lock ( ) . await . get_info ( ) . await { Ok ( info ) => Ok ( Some ( SettingResponse :: Audio ( info ) ) ) , Err ( e ) => Err ( e ) , } ; responder . send ( response ) . ok ( ) ; } _ => { responder . send ( Err ( SwitchboardError :: UnimplementedRequest { setting_type : SettingType :: Audio , request : request , } ) ) . ok ( ) ; } } } } } fx_log_err ! ( " " ) ; } ) ; Box :: pin ( async move { audio_handler_tx } ) }
Controller that handles commands for SettingType::Audio.
Controller that handles commands for SettingType :: Audio .
context
Context<T>