async fn handle_fidl_requests(
        &self,
        mut profile_test_requests: mpsc::Receiver<bredr::ProfileTestRequest>,
    ) {
        // A combined stream of all the active peers' MockPeerRequestStreams.
        // Each MockPeerRequest is tagged with its corresponding PeerId.
        let mut mock_peer_requests = SelectAll::new();

        // A channel used for relaying the ProfileRequestStream of a peer.
        let (profile_stream_sender, mut profile_stream_receiver) = mpsc::channel(1);

        // A combined stream of all the active peers' ProfileRequestStreams.
        // Each ProfileRequest is tagged with it's corresponding PeerId.
        let mut profile_requests = SelectAll::new();

        loop {
            select! {
                // A request from the `ProfileTest` FIDL request stream has been received.
                test_request = profile_test_requests.select_next_some() => {
                    let bredr::ProfileTestRequest::RegisterPeer { peer_id, peer, observer, responder, .. } = test_request;
                    let id = peer_id.into();
                    info!("Received ProfileTest request to register peer: {:?}", id);
                    let request_stream = match peer.into_stream() {
                        Ok(stream) => stream,
                        Err(_) => {
                            responder.control_handle().shutdown_with_epitaph(zx::Status::BAD_HANDLE);
                            continue;
                        }
                    };
                    let registration =
                        self.register_peer(id, observer, profile_stream_sender.clone());

                    // If registration was successful, tag the stream with the client's `id` and add
                    // to the combinator.
                    match registration {
                        Ok(_) => {
                            mock_peer_requests.push(request_stream.tagged(id).with_epitaph(id));
                        }
                        Err(e) => {
                            error!("Error registering peer {}: {:?}", id, e);
                        }
                    }
                    let _ = responder.send();
                }
                // A request from the `MockPeer` FIDL request stream.
                mock_peer_request = mock_peer_requests.next() => {
                    match mock_peer_request {
                        Some(StreamItem::Item((peer_id, Ok(request)))) => {
                            self.handle_mock_peer_request(peer_id, request, &mut profile_requests);
                        },
                        Some(StreamItem::Item((peer_id, Err(e)))) => {
                            error!("Peer {} received MockPeerRequest error: {:?}", peer_id, e);
                        }
                        Some(StreamItem::Epitaph(peer_id)) => {
                            // The MockPeerRequestStream associated with `peer_id` has been
                            // exhausted, signaled by the epitaph. This means the peer has
                            // disconnected from the piconet.
                            if let Err(e) = self.unregister_peer(peer_id) {
                                error!("Error unregistering peer {}: {:?}", peer_id, e);
                            }
                        },
                        None => (),
                    }
                }
                // A request from the `Profile` FIDL request stream has been received.
                profile_request = profile_requests.next() => {
                    match profile_request {
                        Some(StreamItem::Item((peer_id, request))) => {
                            if let Ok(req) = request {
                                self.handle_profile_request(peer_id, req);
                            }
                        },
                        Some(StreamItem::Epitaph(_)) | None =>  (),
                    }
                }
                // A new ProfileRequestStream has been received. Tag with the relevant PeerId, and
                // add to the Profile handler combinator.
                request_stream = profile_stream_receiver.select_next_some() => {
                    let (id, request_stream) = request_stream;
                    profile_requests.push(request_stream.tagged(id).with_epitaph(id));
                }
                // There are no active streams to be polled.
                complete => break,
            }
        }
    }
/// Central handler that consumes requests from several sources.
///   1. Processes requests over the `bredr.ProfileTest` protocol.
///   2. Processes requests over the `bredr.MockPeer` protocol.
///   3. Processes requests over the `bredr.Profile` protocol.
///   4. Processes messages over a local mpsc channel. This relays the ProfileRequestStream
///      that is created when a sandboxed instance of a Bluetooth Profile is launched.
Central handler that consumes requests from several sources.
1. Processes requests over the `bredr.ProfileTest` protocol.
2. Processes requests over the `bredr.MockPeer` protocol.
3. Processes requests over the `bredr.Profile` protocol.
4. Processes messages over a local mpsc channel. This relays the ProfileRequestStream
that is created when a sandboxed instance of a Bluetooth Profile is launched.
Central handler that consumes requests from several sources . 1 . Processes requests over the ` bredr . ProfileTest ` protocol . 2 . Processes requests over the ` bredr . MockPeer ` protocol . 3 . Processes requests over the ` bredr . Profile ` protocol . 4 . Processes messages over a local mpsc channel . This relays the ProfileRequestStream that is created when a sandboxed instance of a Bluetooth Profile is launched .
async fn handle_fidl_requests(
        &self,
        mut profile_test_requests: mpsc::Receiver<bredr::ProfileTestRequest>,
    ) {
        // A combined stream of all the active peers' MockPeerRequestStreams.
        // Each MockPeerRequest is tagged with its corresponding PeerId.
        let mut mock_peer_requests = SelectAll::new();
        // A channel used for relaying the ProfileRequestStream of a peer.
        let (profile_stream_sender, mut profile_stream_receiver) = mpsc::channel(1);
        // A combined stream of all the active peers' ProfileRequestStreams.
        // Each ProfileRequest is tagged with it's corresponding PeerId.
        let mut profile_requests = SelectAll::new();
        loop {
            select! {
                // A request from the `ProfileTest` FIDL request stream has been received.
                test_request = profile_test_requests.select_next_some() => {
                    let bredr::ProfileTestRequest::RegisterPeer { peer_id, peer, observer, responder, .. } = test_request;
                    let id = peer_id.into();
                    info!("Received ProfileTest request to register peer: {:?}", id);
                    let request_stream = match peer.into_stream() {
                        Ok(stream) => stream,
                        Err(_) => {
                            responder.control_handle().shutdown_with_epitaph(zx::Status::BAD_HANDLE);
                            continue;
                        }
                    };
                    let registration =
                        self.register_peer(id, observer, profile_stream_sender.clone());
                    // If registration was successful, tag the stream with the client's `id` and add
                    // to the combinator.
                    match registration {
                        Ok(_) => {
                            mock_peer_requests.push(request_stream.tagged(id).with_epitaph(id));
                        }
                        Err(e) => {
                            error!("Error registering peer {}: {:?}", id, e);
                        }
                    }
                    let _ = responder.send();
                }
                // A request from the `MockPeer` FIDL request stream.
                mock_peer_request = mock_peer_requests.next() => {
                    match mock_peer_request {
                        Some(StreamItem::Item((peer_id, Ok(request)))) => {
                            self.handle_mock_peer_request(peer_id, request, &mut profile_requests);
                        },
                        Some(StreamItem::Item((peer_id, Err(e)))) => {
                            error!("Peer {} received MockPeerRequest error: {:?}", peer_id, e);
                        }
                        Some(StreamItem::Epitaph(peer_id)) => {
                            // The MockPeerRequestStream associated with `peer_id` has been
                            // exhausted, signaled by the epitaph. This means the peer has
                            // disconnected from the piconet.
                            if let Err(e) = self.unregister_peer(peer_id) {
                                error!("Error unregistering peer {}: {:?}", peer_id, e);
                            }
                        },
                        None => (),
                    }
                }
                // A request from the `Profile` FIDL request stream has been received.
                profile_request = profile_requests.next() => {
                    match profile_request {
                        Some(StreamItem::Item((peer_id, request))) => {
                            if let Ok(req) = request {
                                self.handle_profile_request(peer_id, req);
                            }
                        },
                        Some(StreamItem::Epitaph(_)) | None =>  (),
                    }
                }
                // A new ProfileRequestStream has been received. Tag with the relevant PeerId, and
                // add to the Profile handler combinator.
                request_stream = profile_stream_receiver.select_next_some() => {
                    let (id, request_stream) = request_stream;
                    profile_requests.push(request_stream.tagged(id).with_epitaph(id));
                }
                // There are no active streams to be polled.
                complete => break,
            }
        }
    }
async fn handle_fidl_requests ( & self , mut profile_test_requests : mpsc :: Receiver < bredr :: ProfileTestRequest > , ) { // A combined stream of all the active peers' MockPeerRequestStreams. // Each MockPeerRequest is tagged with its corresponding PeerId. let mut mock_peer_requests = SelectAll :: new ( ) ; // A channel used for relaying the ProfileRequestStream of a peer. let ( profile_stream_sender , mut profile_stream_receiver ) = mpsc :: channel ( 1 ) ; // A combined stream of all the active peers' ProfileRequestStreams. // Each ProfileRequest is tagged with it's corresponding PeerId. let mut profile_requests = SelectAll :: new ( ) ; loop { select ! { // A request from the `ProfileTest` FIDL request stream has been received. test_request profile_test_requests select_next_some ( ) { let bredr ProfileTestRequest RegisterPeer { peer_id peer observer responder } test_request let id peer_id into ( ) info ( " " id ) let request_stream match peer into_stream ( ) { Ok ( stream ) stream Err ( ) { responder control_handle ( ) shutdown_with_epitaph ( zx Status BAD_HANDLE ) continue } } let registration self register_peer ( id observer profile_stream_sender clone ( ) ) // If registration was successful, tag the stream with the client's `id` and add // to the combinator. match registration { Ok ( ) { mock_peer_requests push ( request_stream tagged ( id ) with_epitaph ( id ) ) } Err ( e ) { error ( " " id e ) } } let responder send ( ) } // A request from the `MockPeer` FIDL request stream. mock_peer_request mock_peer_requests next ( ) { match mock_peer_request { Some ( StreamItem Item ( ( peer_id Ok ( request ) ) ) ) { self handle_mock_peer_request ( peer_id request mut profile_requests ) } Some ( StreamItem Item ( ( peer_id Err ( e ) ) ) ) { error ( " " peer_id e ) } Some ( StreamItem Epitaph ( peer_id ) ) { // The MockPeerRequestStream associated with `peer_id` has been // exhausted, signaled by the epitaph. This means the peer has // disconnected from the piconet. if let Err ( e ) self unregister_peer ( peer_id ) { error ( " " peer_id e ) } } None ( ) } } // A request from the `Profile` FIDL request stream has been received. profile_request profile_requests next ( ) { match profile_request { Some ( StreamItem Item ( ( peer_id request ) ) ) { if let Ok ( req ) request { self handle_profile_request ( peer_id req ) } } Some ( StreamItem Epitaph ( ) ) None ( ) } } // A new ProfileRequestStream has been received. Tag with the relevant PeerId, and // add to the Profile handler combinator. request_stream profile_stream_receiver select_next_some ( ) { let ( id request_stream ) request_stream profile_requests push ( request_stream tagged ( id ) with_epitaph ( id ) ) } // There are no active streams to be polled. complete break } } }
Central handler that consumes requests from several sources.
Central handler that consumes requests from several sources .
&self
profile_test_requests
mpsc::Receiver<bredr::ProfileTestRequest>
&self
profile_test_requests
mpsc::Receiver<bredr::ProfileTestRequest>