/// Attempts to launch the profile specified by the `launch_info`.
///
/// Returns a stream that monitors component state. The returned stream _must_ be polled
/// in order to complete component launching. Furthermore, it should also be polled to
/// detect component termination - state will be cleaned up thereafter.
Attempts to launch the profile specified by the `launch_info`.
Returns a stream that monitors component state. The returned stream _must_ be polled
in order to complete component launching. Furthermore, it should also be polled to
detect component termination - state will be cleaned up thereafter.
Attempts to launch the profile specified by the ` launch_info ` . Returns a stream that monitors component state . The returned stream _must_ be polled in order to complete component launching . Furthermore it should also be polled to detect component termination - state will be cleaned up thereafter .
pub fn launch_profile(
        &mut self,
        launch_info: LaunchInfo,
    ) -> Result<(ProfileHandle, impl Stream<Item = Result<ComponentStatus, fidl::Error>>), Error>
    {
        let next_profile_handle = self.get_next_profile_handle();
        let profile_url = launch_info.url;
        // Launch the component and grab the event stream.
        let app = {
            // if there is no launcher we might have been started as part of a v2
            // profile server
            let launcher = self
                .env
                .as_ref()
                .ok_or_else(|| {
                    format_err!("Failed to launch profile, no environment provided to mock peer")
                })?
                .launcher();
            client::launch(launcher, profile_url.clone(), Some(launch_info.arguments))?
        };
        let component_stream = app.controller().take_event_stream();
        let entry = self.launched_profiles.lazy_entry(&next_profile_handle);
        let detached_component = match entry.try_insert((profile_url.clone(), app)) {
            Ok(component) => component,
            Err(_) => return Err(format_err!("Launched component already exists")),
        };
        // The returned `component_stream` processes events from the launched component's
        // event stream.
        let peer_id = self.id.clone();
        let handle = next_profile_handle.clone();
        let observer = self.observer.clone();
        let component_stream = component_stream.map_ok(move |event| {
            let detached = detached_component.clone();
            let url_clone = profile_url.clone();
            let observer_clone = observer.clone();
            match event {
                ComponentControllerEvent::OnTerminated { return_code, termination_reason } => {
                    info!(
                        "Peer {:?}: Component {:?} terminated. Code: {}. Reason: {:?}",
                        peer_id, handle, return_code, termination_reason
                    );
                    detached.detach();
                    let _ = observer_clone.map(|o| Self::relay_terminated(&o, url_clone));
                    ComponentStatus::Terminated
                }
                ComponentControllerEvent::OnDirectoryReady { .. } => {
                    ComponentStatus::DirectoryReady
                }
            }
        });
        Ok((next_profile_handle, component_stream))
    }
pub fn launch_profile ( & mut self , launch_info : LaunchInfo , ) -> Result < ( ProfileHandle , impl Stream < Item = Result < ComponentStatus , fidl :: Error > > ) , Error > { let next_profile_handle = self . get_next_profile_handle ( ) ; let profile_url = launch_info . url ; // Launch the component and grab the event stream. let app = { // if there is no launcher we might have been started as part of a v2 // profile server let launcher = self . env . as_ref ( ) . ok_or_else ( | | { format_err ! ( " " ) } ) ? . launcher ( ) ; client :: launch ( launcher , profile_url . clone ( ) , Some ( launch_info . arguments ) ) ? } ; let component_stream = app . controller ( ) . take_event_stream ( ) ; let entry = self . launched_profiles . lazy_entry ( & next_profile_handle ) ; let detached_component = match entry . try_insert ( ( profile_url . clone ( ) , app ) ) { Ok ( component ) => component , Err ( _ ) => return Err ( format_err ! ( " " ) ) , } ; // The returned `component_stream` processes events from the launched component's // event stream. let peer_id = self . id . clone ( ) ; let handle = next_profile_handle . clone ( ) ; let observer = self . observer . clone ( ) ; let component_stream = component_stream . map_ok ( move | event | { let detached = detached_component . clone ( ) ; let url_clone = profile_url . clone ( ) ; let observer_clone = observer . clone ( ) ; match event { ComponentControllerEvent :: OnTerminated { return_code , termination_reason } => { info ! ( " " peer_id handle return_code termination_reason ) ; detached . detach ( ) ; let _ = observer_clone . map ( | o | Self :: relay_terminated ( & o , url_clone ) ) ; ComponentStatus :: Terminated } ComponentControllerEvent :: OnDirectoryReady { .. } => { ComponentStatus :: DirectoryReady } } } ) ; Ok ( ( next_profile_handle , component_stream ) ) }
Attempts to launch the profile specified by the `launch_info`.
Attempts to launch the profile specified by the ` launch_info ` .
&mut self
launch_info
LaunchInfo