/// Processes |DebugDataController| requests and component lifecycle events.
/// This collects the debug data sets that are defined over the |DebugDataController|
/// and |DebugDataSetController| processes, and demultiplixes the events into streams
/// per data set.
///
/// The output is a terminated stream of |DebugData| connection requests and an |DebugDataIterator|
/// request for each set. This output is passed to |debug_request_handler| for processing.
///
/// The stream is terminated by observing the passed lifecycle events and determining when all
/// realms in a set have stopped. To do this, a number of assumptions about ordering of events:
///  * A new realm is reported via DebugDataSetController::AddRealm before any events for that
///    realm are sent
///  * After a realm is stopped, no child components will start under it
/// If these assumptions are broken, events may be lost.
Processes |DebugDataController| requests and component lifecycle events.
This collects the debug data sets that are defined over the |DebugDataController|
and |DebugDataSetController| processes, and demultiplixes the events into streams
per data set.

The output is a terminated stream of |DebugData| connection requests and an |DebugDataIterator|
request for each set. This output is passed to |debug_request_handler| for processing.

The stream is terminated by observing the passed lifecycle events and determining when all
realms in a set have stopped. To do this, a number of assumptions about ordering of events:
A new realm is reported via DebugDataSetController::AddRealm before any events for that
realm are sent
After a realm is stopped, no child components will start under it
If these assumptions are broken, events may be lost.
Processes |DebugDataController| requests and component lifecycle events . This collects the debug data sets that are defined over the |DebugDataController| and |DebugDataSetController| processes and demultiplixes the events into streams per data set . The output is a terminated stream of |DebugData| connection requests and an |DebugDataIterator| request for each set . This output is passed to |debug_request_handler| for processing . The stream is terminated by observing the passed lifecycle events and determining when all realms in a set have stopped . To do this a number of assumptions about ordering of events : A new realm is reported via DebugDataSetController :: AddRealm before any events for that realm are sent After a realm is stopped no child components will start under it If these assumptions are broken events may be lost .
pub async fn handle_debug_data_controller_and_events<CS, D>(
    controller_requests: CS,
    events: fsys::EventStreamRequestStream,
    debug_request_handler: D,
    inspect_node: &Node,
) where
    CS: Stream<Item = Result<ftest_internal::DebugDataControllerRequest, fidl::Error>>
        + std::marker::Unpin,
    D: DebugRequestHandler,
{
    let debug_data_sets: Mutex<Vec<Weak<Mutex<inner::DebugDataSet>>>> = Mutex::new(vec![]);
    let debug_data_sets_ref = &debug_data_sets;
    let debug_request_handler_ref = &debug_request_handler;
    let inspect_node_count = std::sync::atomic::AtomicU32::new(0);
    let inspect_node_count_ref = &inspect_node_count;
    let controller_fut = controller_requests.for_each_concurrent(None, |request_result| {
        async move {
            let ftest_internal::DebugDataControllerRequest::NewSet { iter, controller, .. } =
                request_result?;
            let iter = iter.into_stream()?;
            let controller = controller.into_stream()?;
            let controller_handle = controller.control_handle();
            let (debug_request_send, debug_request_recv) = mpsc::channel(5);
            let debug_data_set =
                inner::DebugDataSet::new(debug_request_send, move |debug_data_requested| {
                    if debug_data_requested {
                        let _ = controller_handle.send_on_debug_data_produced();
                    }
                })
                .with_inspect(
                    inspect_node,
                    &format!(
                        "{:?}",
                        inspect_node_count_ref.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
                    ),
                );
            debug_data_sets_ref.lock().await.push(Arc::downgrade(&debug_data_set));
            futures::future::try_join(
                serve_debug_data_set_controller(&*debug_data_set, controller),
                debug_request_handler_ref.handle_debug_requests(debug_request_recv, iter),
            )
            .await?;
            Result::<(), Error>::Ok(())
        }
        .unwrap_or_else(|e| warn!("Error serving debug data set: {:?}", e))
    });
    let event_fut = route_events(events, debug_data_sets_ref)
        .unwrap_or_else(|e| error!("Error routing debug data events: {:?}", e));
    futures::future::join(controller_fut, event_fut).await;
}
pub async fn handle_debug_data_controller_and_events < CS , D > ( controller_requests : CS , events : fsys :: EventStreamRequestStream , debug_request_handler : D , inspect_node : & Node , ) where CS : Stream < Item = Result < ftest_internal :: DebugDataControllerRequest , fidl :: Error > > + std :: marker :: Unpin , D : DebugRequestHandler , { let debug_data_sets : Mutex < Vec < Weak < Mutex < inner :: DebugDataSet > > > > = Mutex :: new ( vec ! [ ] ) ; let debug_data_sets_ref = & debug_data_sets ; let debug_request_handler_ref = & debug_request_handler ; let inspect_node_count = std :: sync :: atomic :: AtomicU32 :: new ( 0 ) ; let inspect_node_count_ref = & inspect_node_count ; let controller_fut = controller_requests . for_each_concurrent ( None , | request_result | { async move { let ftest_internal :: DebugDataControllerRequest :: NewSet { iter , controller , .. } = request_result ? ; let iter = iter . into_stream ( ) ? ; let controller = controller . into_stream ( ) ? ; let controller_handle = controller . control_handle ( ) ; let ( debug_request_send , debug_request_recv ) = mpsc :: channel ( 5 ) ; let debug_data_set = inner :: DebugDataSet :: new ( debug_request_send , move | debug_data_requested | { if debug_data_requested { let _ = controller_handle . send_on_debug_data_produced ( ) ; } } ) . with_inspect ( inspect_node , & format ! ( " " inspect_node_count_ref fetch_add ( 1 std sync atomic Ordering Relaxed ) ) , ) ; debug_data_sets_ref . lock ( ) . await . push ( Arc :: downgrade ( & debug_data_set ) ) ; futures :: future :: try_join ( serve_debug_data_set_controller ( & * debug_data_set , controller ) , debug_request_handler_ref . handle_debug_requests ( debug_request_recv , iter ) , ) . await ? ; Result :: < ( ) , Error > :: Ok ( ( ) ) } . unwrap_or_else ( | e | warn ! ( " " e ) ) } ) ; let event_fut = route_events ( events , debug_data_sets_ref ) . unwrap_or_else ( | e | error ! ( " " e ) ) ; futures :: future :: join ( controller_fut , event_fut ) . await ; }
Processes |DebugDataController| requests and component lifecycle events.
Processes |DebugDataController| requests and component lifecycle events .
controller_requests
CS
events
fsys::EventStreamRequestStream
debug_request_handler
D
inspect_node
&Node