// Handles `Watch()` requests from the stream by iterating over the responses.  Does only
// minimal validation of the request arguments.  Specifically, only checks that the correct
// number of responses is sent by the client.
//
// Returns the `request_stream` so that e.g. this function can be called again with different
// events; this is useful for verifying that not-yet-granted events are buffered properly.
Handles `Watch()` requests from the stream by iterating over the responses.  Does only
minimal validation of the request arguments.  Specifically, only checks that the correct
number of responses is sent by the client.

Returns the `request_stream` so that e.g. this function can be called again with different
events; this is useful for verifying that not-yet-granted events are buffered properly.
Handles ` Watch () ` requests from the stream by iterating over the responses . Does only minimal validation of the request arguments . Specifically only checks that the correct number of responses is sent by the client . Returns the ` request_stream ` so that e . g . this function can be called again with different events ; this is useful for verifying that not - yet - granted events are buffered properly .
async fn handle_touch_source_watch_requests(
        mut request_stream: fptr::TouchSourceRequestStream,
        responses: Vec<Vec<TouchEvent>>,
    ) -> Result<fptr::TouchSourceRequestStream, anyhow::Error> {
        // With each call to `Watch()` the client must pass a vector of `TouchResponse` equal in
        // size to the number of `TouchEvent` that they received in response to their previous call
        // to `Watch()`.  This number is initially zero, because there was no previous call to
        // `Watch()`.
        let mut expected_client_response_count: usize = 0;
        // For the purposes of validating the args to `Watch()`, we treat the first loop iteration
        // differently.  See comments below.
        let mut is_first_loop_iteration = true;
        // Each time we receive a `Watch()` request from the client, we respond with the next
        // response provided by the caller of this function.
        let mut response_iter = responses.iter();
        while let Some(events) = response_iter.next() {
            if let Ok(Some(request)) = request_stream.try_next().await {
                match request {
                    fptr::TouchSourceRequest::Watch { responses, responder } => {
                        // Verify that the number of responses matches the number of events sent in
                        // response to the *previous* call to Watch().
                        if is_first_loop_iteration {
                            // Some tests may want to call handle_touch_source_watch_requests() multiple
                            // times, and assert conditions after each batch of events has been sent.
                            // In such cases, we don't know which (if any) events were previously sent,
                            // so we can't verify that the client sent the correct number of responses.
                            is_first_loop_iteration = false;
                        } else {
                            assert_eq!(expected_client_response_count, responses.len());
                        }
                        expected_client_response_count = events.len();
                        responder.send(&mut events.clone().into_iter())?;
                    }
                    _ => {
                        return Err(anyhow!("unexpected request: only Watch() is supported"));
                    }
                }
            } else {
                return Err(anyhow!("not all responses were consumed by client"));
            }
        }
        Ok(request_stream)
    }
async fn handle_touch_source_watch_requests ( mut request_stream : fptr :: TouchSourceRequestStream , responses : Vec < Vec < TouchEvent > > , ) -> Result < fptr :: TouchSourceRequestStream , anyhow :: Error > { // With each call to `Watch()` the client must pass a vector of `TouchResponse` equal in // size to the number of `TouchEvent` that they received in response to their previous call // to `Watch()`.  This number is initially zero, because there was no previous call to // `Watch()`. let mut expected_client_response_count : usize = 0 ; // For the purposes of validating the args to `Watch()`, we treat the first loop iteration // differently.  See comments below. let mut is_first_loop_iteration = true ; // Each time we receive a `Watch()` request from the client, we respond with the next // response provided by the caller of this function. let mut response_iter = responses . iter ( ) ; while let Some ( events ) = response_iter . next ( ) { if let Ok ( Some ( request ) ) = request_stream . try_next ( ) . await { match request { fptr :: TouchSourceRequest :: Watch { responses , responder } => { // Verify that the number of responses matches the number of events sent in // response to the *previous* call to Watch(). if is_first_loop_iteration { // Some tests may want to call handle_touch_source_watch_requests() multiple // times, and assert conditions after each batch of events has been sent. // In such cases, we don't know which (if any) events were previously sent, // so we can't verify that the client sent the correct number of responses. is_first_loop_iteration = false ; } else { assert_eq ! ( expected_client_response_count responses len ( ) ) ; } expected_client_response_count = events . len ( ) ; responder . send ( & mut events . clone ( ) . into_iter ( ) ) ? ; } _ => { return Err ( anyhow ! ( " " ) ) ; } } } else { return Err ( anyhow ! ( " " ) ) ; } } Ok ( request_stream ) }
Handles `Watch()` requests from the stream by iterating over the responses.
Handles ` Watch () ` requests from the stream by iterating over the responses .
request_stream
fptr::TouchSourceRequestStream
responses
Vec<Vec<TouchEvent>>