fn start(
    log_size_bytes: usize,
    log_time: Duration,
    max_device_count: usize,
    truncate_payload: Option<usize>,
    hci_dir: File,
) -> Result<(), Error> {
    let mut exec = fasync::Executor::new().expect("Could not create executor");

    let mut service_handler = setup_service_fs()?;
    let mut id_gen = IdGenerator::new();
    let mut hci_device_events = Watcher::new(&hci_dir).context("Cannot create device watcher")?;
    let mut client_requests = ConcurrentClientRequestFutures::new();
    let mut subscribers = SubscriptionManager::new();
    let mut snoopers = ConcurrentSnooperPacketFutures::new();
    let mut packet_logs = PacketLogs::new(max_device_count, log_size_bytes, log_time);

    let main_loop = async {
        fx_vlog!(1, "Capturing snoop packets...");

        loop {
            select! {
                // A new client has connected to one of the exposed services.
                request_stream = service_handler.select_next_some() => {
                    register_new_client(request_stream, &mut client_requests, id_gen.next());
                }

                // A new filesystem event in the hci device watch directory has been received.
                event = hci_device_events.next() => {
                    let message = event
                        .ok_or(err_msg("Cannot reach watch server"))
                        .and_then(|r| Ok(r?));
                    match message {
                        Ok(message) => {
                            handle_hci_device_event(message, &mut snoopers, &mut subscribers,
                                &mut packet_logs);
                        }
                        Err(e) => {
                            // Attempt to recreate watcher in the event of an error.
                            fx_log_warn!("VFS Watcher has died with error: {:?}", e);
                            hci_device_events = Watcher::new(&hci_dir)
                                .context("Cannot create device watcher")?;
                        }
                    }
                },

                // A client has made a request to the server.
                request = client_requests.select_next_some() => {
                    if let Err(e) = handle_client_request(request, &mut client_requests,
                        &mut subscribers, &mut packet_logs)
                    {
                        fx_vlog!(1, "Unable to handle client request: {:?}", e);
                    }
                },

                // A new snoop packet has been received from an hci device.
                (packet, snooper) = snoopers.select_next_some() => {
                    handle_packet(packet, snooper, &mut snoopers, &mut subscribers,
                        &mut packet_logs, truncate_payload);
                },
            }
        }
    };

    exec.run_singlethreaded(main_loop)
}
/// Setup the main loop of execution in a Task and run it.
Setup the main loop of execution in a Task and run it.
Setup the main loop of execution in a Task and run it .
fn start(
    log_size_bytes: usize,
    log_time: Duration,
    max_device_count: usize,
    truncate_payload: Option<usize>,
    hci_dir: File,
) -> Result<(), Error> {
    let mut exec = fasync::Executor::new().expect("Could not create executor");
    let mut service_handler = setup_service_fs()?;
    let mut id_gen = IdGenerator::new();
    let mut hci_device_events = Watcher::new(&hci_dir).context("Cannot create device watcher")?;
    let mut client_requests = ConcurrentClientRequestFutures::new();
    let mut subscribers = SubscriptionManager::new();
    let mut snoopers = ConcurrentSnooperPacketFutures::new();
    let mut packet_logs = PacketLogs::new(max_device_count, log_size_bytes, log_time);
    let main_loop = async {
        fx_vlog!(1, "Capturing snoop packets...");
        loop {
            select! {
                // A new client has connected to one of the exposed services.
                request_stream = service_handler.select_next_some() => {
                    register_new_client(request_stream, &mut client_requests, id_gen.next());
                }
                // A new filesystem event in the hci device watch directory has been received.
                event = hci_device_events.next() => {
                    let message = event
                        .ok_or(err_msg("Cannot reach watch server"))
                        .and_then(|r| Ok(r?));
                    match message {
                        Ok(message) => {
                            handle_hci_device_event(message, &mut snoopers, &mut subscribers,
                                &mut packet_logs);
                        }
                        Err(e) => {
                            // Attempt to recreate watcher in the event of an error.
                            fx_log_warn!("VFS Watcher has died with error: {:?}", e);
                            hci_device_events = Watcher::new(&hci_dir)
                                .context("Cannot create device watcher")?;
                        }
                    }
                },
                // A client has made a request to the server.
                request = client_requests.select_next_some() => {
                    if let Err(e) = handle_client_request(request, &mut client_requests,
                        &mut subscribers, &mut packet_logs)
                    {
                        fx_vlog!(1, "Unable to handle client request: {:?}", e);
                    }
                },
                // A new snoop packet has been received from an hci device.
                (packet, snooper) = snoopers.select_next_some() => {
                    handle_packet(packet, snooper, &mut snoopers, &mut subscribers,
                        &mut packet_logs, truncate_payload);
                },
            }
        }
    };
    exec.run_singlethreaded(main_loop)
}
fn start ( log_size_bytes : usize , log_time : Duration , max_device_count : usize , truncate_payload : Option < usize > , hci_dir : File , ) -> Result < ( ) , Error > { let mut exec = fasync :: Executor :: new ( ) . expect ( " " ) ; let mut service_handler = setup_service_fs ( ) ? ; let mut id_gen = IdGenerator :: new ( ) ; let mut hci_device_events = Watcher :: new ( & hci_dir ) . context ( " " ) ? ; let mut client_requests = ConcurrentClientRequestFutures :: new ( ) ; let mut subscribers = SubscriptionManager :: new ( ) ; let mut snoopers = ConcurrentSnooperPacketFutures :: new ( ) ; let mut packet_logs = PacketLogs :: new ( max_device_count , log_size_bytes , log_time ) ; let main_loop = async { fx_vlog ! ( 1 " " ) ; loop { select ! { // A new client has connected to one of the exposed services. request_stream service_handler select_next_some ( ) { register_new_client ( request_stream mut client_requests id_gen next ( ) ) } // A new filesystem event in the hci device watch directory has been received. event hci_device_events next ( ) { let message event ok_or ( err_msg ( " " ) ) and_then ( r Ok ( r ) ) match message { Ok ( message ) { handle_hci_device_event ( message mut snoopers mut subscribers mut packet_logs ) } Err ( e ) { // Attempt to recreate watcher in the event of an error. fx_log_warn ( " " e ) hci_device_events Watcher new ( hci_dir ) context ( " " ) } } } // A client has made a request to the server. request client_requests select_next_some ( ) { if let Err ( e ) handle_client_request ( request mut client_requests mut subscribers mut packet_logs ) { fx_vlog ( 1 " " e ) } } // A new snoop packet has been received from an hci device. ( packet snooper ) snoopers select_next_some ( ) { handle_packet ( packet snooper mut snoopers mut subscribers mut packet_logs truncate_payload ) } } } } ; exec . run_singlethreaded ( main_loop ) }
Setup the main loop of execution in a Task and run it.
Setup the main loop of execution in a Task and run it .
log_size_bytes
usize
log_time
Duration
max_device_count
usize
truncate_payload
Option<usize>
hci_dir
File
log_size_bytes
usize
log_time
Duration
max_device_count
usize
truncate_payload
Option<usize>
hci_dir
File