fn create_environment<'a, T: DeviceStorageFactory + Send + Sync + 'static>(
    mut service_dir: ServiceFsDir<'_, ServiceObj<'a, ()>>,
    components: HashSet<switchboard::base::SettingType>,
    agents: Vec<AgentHandle>,
    service_context_handle: ServiceContextHandle,
    handler_factory: Arc<Mutex<SettingHandlerFactoryImpl<T>>>,
) -> Receiver<Result<(), Error>> {
    let conduit_handle = ConduitImpl::create();

    // Creates switchboard, handed to interface implementations to send messages
    // to handlers.
    let switchboard_handle = SwitchboardImpl::create(conduit_handle.clone());

    let mut agent_authority = AuthorityImpl::new();

    // Creates registry, used to register handlers for setting types.
    let _registry_handle = RegistryImpl::create(handler_factory.clone(), conduit_handle.clone());

    if components.contains(&SettingType::Accessibility) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: AccessibilityRequestStream| {
            spawn_accessibility_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::Audio) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: AudioRequestStream| {
            spawn_audio_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::Device) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DeviceRequestStream| {
            spawn_device_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::Display) || components.contains(&SettingType::LightSensor)
    {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DisplayRequestStream| {
            spawn_display_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::DoNotDisturb) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DoNotDisturbRequestStream| {
            spawn_do_not_disturb_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::Intl) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: IntlRequestStream| {
            spawn_intl_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::NightMode) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: NightModeRequestStream| {
            spawn_night_mode_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::Privacy) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: PrivacyRequestStream| {
            spawn_privacy_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    if components.contains(&SettingType::System) {
        {
            let switchboard_handle_clone = switchboard_handle.clone();
            service_dir.add_fidl_service(move |stream: SystemRequestStream| {
                spawn_system_fidl_handler(switchboard_handle_clone.clone(), stream);
            });
        }
        {
            let switchboard_handle_clone = switchboard_handle.clone();
            service_dir.add_fidl_service(move |stream: SetUiServiceRequestStream| {
                spawn_setui_fidl_handler(switchboard_handle_clone.clone(), stream);
            });
        }
    }

    if components.contains(&SettingType::Setup) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: SetupRequestStream| {
            spawn_setup_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }

    let (response_tx, response_rx) = futures::channel::oneshot::channel::<Result<(), Error>>();
    let switchboard_handle_clone = switchboard_handle.clone();
    fasync::spawn(async move {
        // Register agents
        for agent in agents {
            if agent_authority.register(agent.clone()).is_err() {
                fx_log_err!("failed to register agent: {:?}", agent.clone().lock().await);
            }
        }

        // Execute initialization agents sequentially
        if let Ok(Ok(())) = agent_authority
            .execute_lifespan(
                Lifespan::Initialization,
                components.clone(),
                switchboard_handle_clone.clone(),
                service_context_handle.clone(),
                true,
            )
            .await
        {
            response_tx.send(Ok(())).ok();
        } else {
            response_tx.send(Err(format_err!("Agent initialization failed"))).ok();
        }

        // Execute service agents concurrently
        agent_authority
            .execute_lifespan(
                Lifespan::Service,
                components.clone(),
                switchboard_handle_clone.clone(),
                service_context_handle.clone(),
                false,
            )
            .await
            .ok();
    });

    return response_rx;
}
/// Brings up the settings service environment.
///
/// This method generates the necessary infrastructure to support the settings
/// service (switchboard, registry, etc.) and brings up the components necessary
/// to support the components specified in the components HashSet.
Brings up the settings service environment.
This method generates the necessary infrastructure to support the settings
service (switchboard, registry, etc.) and brings up the components necessary
to support the components specified in the components HashSet.
Brings up the settings service environment . This method generates the necessary infrastructure to support the settings service ( switchboard registry etc . ) and brings up the components necessary to support the components specified in the components HashSet .
fn create_environment<'a, T: DeviceStorageFactory + Send + Sync + 'static>(
    mut service_dir: ServiceFsDir<'_, ServiceObj<'a, ()>>,
    components: HashSet<switchboard::base::SettingType>,
    agents: Vec<AgentHandle>,
    service_context_handle: ServiceContextHandle,
    handler_factory: Arc<Mutex<SettingHandlerFactoryImpl<T>>>,
) -> Receiver<Result<(), Error>> {
    let conduit_handle = ConduitImpl::create();
    // Creates switchboard, handed to interface implementations to send messages
    // to handlers.
    let switchboard_handle = SwitchboardImpl::create(conduit_handle.clone());
    let mut agent_authority = AuthorityImpl::new();
    // Creates registry, used to register handlers for setting types.
    let _registry_handle = RegistryImpl::create(handler_factory.clone(), conduit_handle.clone());
    if components.contains(&SettingType::Accessibility) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: AccessibilityRequestStream| {
            spawn_accessibility_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::Audio) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: AudioRequestStream| {
            spawn_audio_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::Device) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DeviceRequestStream| {
            spawn_device_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::Display) || components.contains(&SettingType::LightSensor)
    {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DisplayRequestStream| {
            spawn_display_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::DoNotDisturb) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: DoNotDisturbRequestStream| {
            spawn_do_not_disturb_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::Intl) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: IntlRequestStream| {
            spawn_intl_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::NightMode) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: NightModeRequestStream| {
            spawn_night_mode_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::Privacy) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: PrivacyRequestStream| {
            spawn_privacy_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    if components.contains(&SettingType::System) {
        {
            let switchboard_handle_clone = switchboard_handle.clone();
            service_dir.add_fidl_service(move |stream: SystemRequestStream| {
                spawn_system_fidl_handler(switchboard_handle_clone.clone(), stream);
            });
        }
        {
            let switchboard_handle_clone = switchboard_handle.clone();
            service_dir.add_fidl_service(move |stream: SetUiServiceRequestStream| {
                spawn_setui_fidl_handler(switchboard_handle_clone.clone(), stream);
            });
        }
    }
    if components.contains(&SettingType::Setup) {
        let switchboard_handle_clone = switchboard_handle.clone();
        service_dir.add_fidl_service(move |stream: SetupRequestStream| {
            spawn_setup_fidl_handler(switchboard_handle_clone.clone(), stream);
        });
    }
    let (response_tx, response_rx) = futures::channel::oneshot::channel::<Result<(), Error>>();
    let switchboard_handle_clone = switchboard_handle.clone();
    fasync::spawn(async move {
        // Register agents
        for agent in agents {
            if agent_authority.register(agent.clone()).is_err() {
                fx_log_err!("failed to register agent: {:?}", agent.clone().lock().await);
            }
        }
        // Execute initialization agents sequentially
        if let Ok(Ok(())) = agent_authority
            .execute_lifespan(
                Lifespan::Initialization,
                components.clone(),
                switchboard_handle_clone.clone(),
                service_context_handle.clone(),
                true,
            )
            .await
        {
            response_tx.send(Ok(())).ok();
        } else {
            response_tx.send(Err(format_err!("Agent initialization failed"))).ok();
        }
        // Execute service agents concurrently
        agent_authority
            .execute_lifespan(
                Lifespan::Service,
                components.clone(),
                switchboard_handle_clone.clone(),
                service_context_handle.clone(),
                false,
            )
            .await
            .ok();
    });
    return response_rx;
}
fn create_environment < ' a , T : DeviceStorageFactory + Send + Sync + ' static > ( mut service_dir : ServiceFsDir < ' _ , ServiceObj < ' a , ( ) > > , components : HashSet < switchboard :: base :: SettingType > , agents : Vec < AgentHandle > , service_context_handle : ServiceContextHandle , handler_factory : Arc < Mutex < SettingHandlerFactoryImpl < T > > > , ) -> Receiver < Result < ( ) , Error > > { let conduit_handle = ConduitImpl :: create ( ) ; // Creates switchboard, handed to interface implementations to send messages // to handlers. let switchboard_handle = SwitchboardImpl :: create ( conduit_handle . clone ( ) ) ; let mut agent_authority = AuthorityImpl :: new ( ) ; // Creates registry, used to register handlers for setting types. let _registry_handle = RegistryImpl :: create ( handler_factory . clone ( ) , conduit_handle . clone ( ) ) ; if components . contains ( & SettingType :: Accessibility ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : AccessibilityRequestStream | { spawn_accessibility_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: Audio ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : AudioRequestStream | { spawn_audio_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: Device ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : DeviceRequestStream | { spawn_device_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: Display ) || components . contains ( & SettingType :: LightSensor ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : DisplayRequestStream | { spawn_display_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: DoNotDisturb ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : DoNotDisturbRequestStream | { spawn_do_not_disturb_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: Intl ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : IntlRequestStream | { spawn_intl_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: NightMode ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : NightModeRequestStream | { spawn_night_mode_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: Privacy ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : PrivacyRequestStream | { spawn_privacy_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } if components . contains ( & SettingType :: System ) { { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : SystemRequestStream | { spawn_system_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : SetUiServiceRequestStream | { spawn_setui_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } } if components . contains ( & SettingType :: Setup ) { let switchboard_handle_clone = switchboard_handle . clone ( ) ; service_dir . add_fidl_service ( move | stream : SetupRequestStream | { spawn_setup_fidl_handler ( switchboard_handle_clone . clone ( ) , stream ) ; } ) ; } let ( response_tx , response_rx ) = futures :: channel :: oneshot :: channel :: < Result < ( ) , Error > > ( ) ; let switchboard_handle_clone = switchboard_handle . clone ( ) ; fasync :: spawn ( async move { // Register agents for agent in agents { if agent_authority . register ( agent . clone ( ) ) . is_err ( ) { fx_log_err ! ( " " agent clone ( ) lock ( ) await ) ; } } // Execute initialization agents sequentially if let Ok ( Ok ( ( ) ) ) = agent_authority . execute_lifespan ( Lifespan :: Initialization , components . clone ( ) , switchboard_handle_clone . clone ( ) , service_context_handle . clone ( ) , true , ) . await { response_tx . send ( Ok ( ( ) ) ) . ok ( ) ; } else { response_tx . send ( Err ( format_err ! ( " " ) ) ) . ok ( ) ; } // Execute service agents concurrently agent_authority . execute_lifespan ( Lifespan :: Service , components . clone ( ) , switchboard_handle_clone . clone ( ) , service_context_handle . clone ( ) , false , ) . await . ok ( ) ; } ) ; return response_rx ; }
Brings up the settings service environment.
Brings up the settings service environment .
service_dir
ServiceFsDir<'_, ServiceObj<'a, ()>>
components
HashSet<switchboard::base::SettingType>
agents
Vec<AgentHandle>
service_context_handle
ServiceContextHandle
handler_factory
Arc<Mutex<SettingHandlerFactoryImpl<T>>>
service_dir
ServiceFsDir<'_, ServiceObj<'a, ()>>
components
HashSet<switchboard::base::SettingType>
agents
Vec<AgentHandle>
service_context_handle
ServiceContextHandle
handler_factory
Arc<Mutex<SettingHandlerFactoryImpl<T>>>