fidl_fuchsia_bluetooth_fastpair/
fidl_fuchsia_bluetooth_fastpair.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14pub struct ProviderEnableRequest {
15    pub watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
16}
17
18impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ProviderEnableRequest {}
19
20#[derive(Clone, Debug, PartialEq)]
21pub struct ProviderWatcherOnPairingCompleteRequest {
22    pub id: fidl_fuchsia_bluetooth::PeerId,
23}
24
25impl fidl::Persistable for ProviderWatcherOnPairingCompleteRequest {}
26
27#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
28pub struct ProviderMarker;
29
30impl fidl::endpoints::ProtocolMarker for ProviderMarker {
31    type Proxy = ProviderProxy;
32    type RequestStream = ProviderRequestStream;
33    #[cfg(target_os = "fuchsia")]
34    type SynchronousProxy = ProviderSynchronousProxy;
35
36    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.fastpair.Provider";
37}
38impl fidl::endpoints::DiscoverableProtocolMarker for ProviderMarker {}
39pub type ProviderEnableResult = Result<(), i32>;
40
41pub trait ProviderProxyInterface: Send + Sync {
42    type EnableResponseFut: std::future::Future<Output = Result<ProviderEnableResult, fidl::Error>>
43        + Send;
44    fn r#enable(
45        &self,
46        watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
47    ) -> Self::EnableResponseFut;
48}
49#[derive(Debug)]
50#[cfg(target_os = "fuchsia")]
51pub struct ProviderSynchronousProxy {
52    client: fidl::client::sync::Client,
53}
54
55#[cfg(target_os = "fuchsia")]
56impl fidl::endpoints::SynchronousProxy for ProviderSynchronousProxy {
57    type Proxy = ProviderProxy;
58    type Protocol = ProviderMarker;
59
60    fn from_channel(inner: fidl::Channel) -> Self {
61        Self::new(inner)
62    }
63
64    fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    fn as_channel(&self) -> &fidl::Channel {
69        self.client.as_channel()
70    }
71}
72
73#[cfg(target_os = "fuchsia")]
74impl ProviderSynchronousProxy {
75    pub fn new(channel: fidl::Channel) -> Self {
76        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
77        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
78    }
79
80    pub fn into_channel(self) -> fidl::Channel {
81        self.client.into_channel()
82    }
83
84    /// Waits until an event arrives and returns it. It is safe for other
85    /// threads to make concurrent requests while waiting for an event.
86    pub fn wait_for_event(
87        &self,
88        deadline: zx::MonotonicInstant,
89    ) -> Result<ProviderEvent, fidl::Error> {
90        ProviderEvent::decode(self.client.wait_for_event(deadline)?)
91    }
92
93    /// Request to enable the Fast Pair Provider service.
94    ///
95    /// Only one client can register to enable the Fast Pair service. An Error will be returned
96    /// for subsequent requests.
97    ///
98    /// The lifetime of the service is tied to the provided `watcher`. To disable Fast Pair
99    /// functionality, close the `watcher`.
100    ///
101    /// + request `watcher` The client end of the ProviderWatcher which determines the lifetime of
102    ///   the Fast Pair service.
103    /// - response An empty response will be sent when the server has processed the
104    ///   request.
105    /// * error Returns `ALREADY_BOUND` if a subsequent request is made to enable
106    ///   the service.
107    pub fn r#enable(
108        &self,
109        mut watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<ProviderEnableResult, fidl::Error> {
112        let _response = self.client.send_query::<
113            ProviderEnableRequest,
114            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
115        >(
116            (watcher,),
117            0x141c1c4f3b6645ad,
118            fidl::encoding::DynamicFlags::empty(),
119            ___deadline,
120        )?;
121        Ok(_response.map(|x| x))
122    }
123}
124
125#[derive(Debug, Clone)]
126pub struct ProviderProxy {
127    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
128}
129
130impl fidl::endpoints::Proxy for ProviderProxy {
131    type Protocol = ProviderMarker;
132
133    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
134        Self::new(inner)
135    }
136
137    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
138        self.client.into_channel().map_err(|client| Self { client })
139    }
140
141    fn as_channel(&self) -> &::fidl::AsyncChannel {
142        self.client.as_channel()
143    }
144}
145
146impl ProviderProxy {
147    /// Create a new Proxy for fuchsia.bluetooth.fastpair/Provider.
148    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
149        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
150        Self { client: fidl::client::Client::new(channel, protocol_name) }
151    }
152
153    /// Get a Stream of events from the remote end of the protocol.
154    ///
155    /// # Panics
156    ///
157    /// Panics if the event stream was already taken.
158    pub fn take_event_stream(&self) -> ProviderEventStream {
159        ProviderEventStream { event_receiver: self.client.take_event_receiver() }
160    }
161
162    /// Request to enable the Fast Pair Provider service.
163    ///
164    /// Only one client can register to enable the Fast Pair service. An Error will be returned
165    /// for subsequent requests.
166    ///
167    /// The lifetime of the service is tied to the provided `watcher`. To disable Fast Pair
168    /// functionality, close the `watcher`.
169    ///
170    /// + request `watcher` The client end of the ProviderWatcher which determines the lifetime of
171    ///   the Fast Pair service.
172    /// - response An empty response will be sent when the server has processed the
173    ///   request.
174    /// * error Returns `ALREADY_BOUND` if a subsequent request is made to enable
175    ///   the service.
176    pub fn r#enable(
177        &self,
178        mut watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
179    ) -> fidl::client::QueryResponseFut<
180        ProviderEnableResult,
181        fidl::encoding::DefaultFuchsiaResourceDialect,
182    > {
183        ProviderProxyInterface::r#enable(self, watcher)
184    }
185}
186
187impl ProviderProxyInterface for ProviderProxy {
188    type EnableResponseFut = fidl::client::QueryResponseFut<
189        ProviderEnableResult,
190        fidl::encoding::DefaultFuchsiaResourceDialect,
191    >;
192    fn r#enable(
193        &self,
194        mut watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
195    ) -> Self::EnableResponseFut {
196        fn _decode(
197            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
198        ) -> Result<ProviderEnableResult, fidl::Error> {
199            let _response = fidl::client::decode_transaction_body::<
200                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
201                fidl::encoding::DefaultFuchsiaResourceDialect,
202                0x141c1c4f3b6645ad,
203            >(_buf?)?;
204            Ok(_response.map(|x| x))
205        }
206        self.client.send_query_and_decode::<ProviderEnableRequest, ProviderEnableResult>(
207            (watcher,),
208            0x141c1c4f3b6645ad,
209            fidl::encoding::DynamicFlags::empty(),
210            _decode,
211        )
212    }
213}
214
215pub struct ProviderEventStream {
216    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
217}
218
219impl std::marker::Unpin for ProviderEventStream {}
220
221impl futures::stream::FusedStream for ProviderEventStream {
222    fn is_terminated(&self) -> bool {
223        self.event_receiver.is_terminated()
224    }
225}
226
227impl futures::Stream for ProviderEventStream {
228    type Item = Result<ProviderEvent, fidl::Error>;
229
230    fn poll_next(
231        mut self: std::pin::Pin<&mut Self>,
232        cx: &mut std::task::Context<'_>,
233    ) -> std::task::Poll<Option<Self::Item>> {
234        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
235            &mut self.event_receiver,
236            cx
237        )?) {
238            Some(buf) => std::task::Poll::Ready(Some(ProviderEvent::decode(buf))),
239            None => std::task::Poll::Ready(None),
240        }
241    }
242}
243
244#[derive(Debug)]
245pub enum ProviderEvent {}
246
247impl ProviderEvent {
248    /// Decodes a message buffer as a [`ProviderEvent`].
249    fn decode(
250        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
251    ) -> Result<ProviderEvent, fidl::Error> {
252        let (bytes, _handles) = buf.split_mut();
253        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
254        debug_assert_eq!(tx_header.tx_id, 0);
255        match tx_header.ordinal {
256            _ => Err(fidl::Error::UnknownOrdinal {
257                ordinal: tx_header.ordinal,
258                protocol_name: <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
259            }),
260        }
261    }
262}
263
264/// A Stream of incoming requests for fuchsia.bluetooth.fastpair/Provider.
265pub struct ProviderRequestStream {
266    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
267    is_terminated: bool,
268}
269
270impl std::marker::Unpin for ProviderRequestStream {}
271
272impl futures::stream::FusedStream for ProviderRequestStream {
273    fn is_terminated(&self) -> bool {
274        self.is_terminated
275    }
276}
277
278impl fidl::endpoints::RequestStream for ProviderRequestStream {
279    type Protocol = ProviderMarker;
280    type ControlHandle = ProviderControlHandle;
281
282    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
283        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
284    }
285
286    fn control_handle(&self) -> Self::ControlHandle {
287        ProviderControlHandle { inner: self.inner.clone() }
288    }
289
290    fn into_inner(
291        self,
292    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
293    {
294        (self.inner, self.is_terminated)
295    }
296
297    fn from_inner(
298        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299        is_terminated: bool,
300    ) -> Self {
301        Self { inner, is_terminated }
302    }
303}
304
305impl futures::Stream for ProviderRequestStream {
306    type Item = Result<ProviderRequest, fidl::Error>;
307
308    fn poll_next(
309        mut self: std::pin::Pin<&mut Self>,
310        cx: &mut std::task::Context<'_>,
311    ) -> std::task::Poll<Option<Self::Item>> {
312        let this = &mut *self;
313        if this.inner.check_shutdown(cx) {
314            this.is_terminated = true;
315            return std::task::Poll::Ready(None);
316        }
317        if this.is_terminated {
318            panic!("polled ProviderRequestStream after completion");
319        }
320        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
321            |bytes, handles| {
322                match this.inner.channel().read_etc(cx, bytes, handles) {
323                    std::task::Poll::Ready(Ok(())) => {}
324                    std::task::Poll::Pending => return std::task::Poll::Pending,
325                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
326                        this.is_terminated = true;
327                        return std::task::Poll::Ready(None);
328                    }
329                    std::task::Poll::Ready(Err(e)) => {
330                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
331                            e.into(),
332                        ))))
333                    }
334                }
335
336                // A message has been received from the channel
337                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
338
339                std::task::Poll::Ready(Some(match header.ordinal {
340                    0x141c1c4f3b6645ad => {
341                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
342                        let mut req = fidl::new_empty!(
343                            ProviderEnableRequest,
344                            fidl::encoding::DefaultFuchsiaResourceDialect
345                        );
346                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderEnableRequest>(&header, _body_bytes, handles, &mut req)?;
347                        let control_handle = ProviderControlHandle { inner: this.inner.clone() };
348                        Ok(ProviderRequest::Enable {
349                            watcher: req.watcher,
350
351                            responder: ProviderEnableResponder {
352                                control_handle: std::mem::ManuallyDrop::new(control_handle),
353                                tx_id: header.tx_id,
354                            },
355                        })
356                    }
357                    _ => Err(fidl::Error::UnknownOrdinal {
358                        ordinal: header.ordinal,
359                        protocol_name:
360                            <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
361                    }),
362                }))
363            },
364        )
365    }
366}
367
368/// Protocol to enable the Bluetooth Fast Pair Provider service on the system.
369#[derive(Debug)]
370pub enum ProviderRequest {
371    /// Request to enable the Fast Pair Provider service.
372    ///
373    /// Only one client can register to enable the Fast Pair service. An Error will be returned
374    /// for subsequent requests.
375    ///
376    /// The lifetime of the service is tied to the provided `watcher`. To disable Fast Pair
377    /// functionality, close the `watcher`.
378    ///
379    /// + request `watcher` The client end of the ProviderWatcher which determines the lifetime of
380    ///   the Fast Pair service.
381    /// - response An empty response will be sent when the server has processed the
382    ///   request.
383    /// * error Returns `ALREADY_BOUND` if a subsequent request is made to enable
384    ///   the service.
385    Enable {
386        watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
387        responder: ProviderEnableResponder,
388    },
389}
390
391impl ProviderRequest {
392    #[allow(irrefutable_let_patterns)]
393    pub fn into_enable(
394        self,
395    ) -> Option<(fidl::endpoints::ClientEnd<ProviderWatcherMarker>, ProviderEnableResponder)> {
396        if let ProviderRequest::Enable { watcher, responder } = self {
397            Some((watcher, responder))
398        } else {
399            None
400        }
401    }
402
403    /// Name of the method defined in FIDL
404    pub fn method_name(&self) -> &'static str {
405        match *self {
406            ProviderRequest::Enable { .. } => "enable",
407        }
408    }
409}
410
411#[derive(Debug, Clone)]
412pub struct ProviderControlHandle {
413    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
414}
415
416impl fidl::endpoints::ControlHandle for ProviderControlHandle {
417    fn shutdown(&self) {
418        self.inner.shutdown()
419    }
420    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
421        self.inner.shutdown_with_epitaph(status)
422    }
423
424    fn is_closed(&self) -> bool {
425        self.inner.channel().is_closed()
426    }
427    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
428        self.inner.channel().on_closed()
429    }
430
431    #[cfg(target_os = "fuchsia")]
432    fn signal_peer(
433        &self,
434        clear_mask: zx::Signals,
435        set_mask: zx::Signals,
436    ) -> Result<(), zx_status::Status> {
437        use fidl::Peered;
438        self.inner.channel().signal_peer(clear_mask, set_mask)
439    }
440}
441
442impl ProviderControlHandle {}
443
444#[must_use = "FIDL methods require a response to be sent"]
445#[derive(Debug)]
446pub struct ProviderEnableResponder {
447    control_handle: std::mem::ManuallyDrop<ProviderControlHandle>,
448    tx_id: u32,
449}
450
451/// Set the the channel to be shutdown (see [`ProviderControlHandle::shutdown`])
452/// if the responder is dropped without sending a response, so that the client
453/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
454impl std::ops::Drop for ProviderEnableResponder {
455    fn drop(&mut self) {
456        self.control_handle.shutdown();
457        // Safety: drops once, never accessed again
458        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
459    }
460}
461
462impl fidl::endpoints::Responder for ProviderEnableResponder {
463    type ControlHandle = ProviderControlHandle;
464
465    fn control_handle(&self) -> &ProviderControlHandle {
466        &self.control_handle
467    }
468
469    fn drop_without_shutdown(mut self) {
470        // Safety: drops once, never accessed again due to mem::forget
471        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
472        // Prevent Drop from running (which would shut down the channel)
473        std::mem::forget(self);
474    }
475}
476
477impl ProviderEnableResponder {
478    /// Sends a response to the FIDL transaction.
479    ///
480    /// Sets the channel to shutdown if an error occurs.
481    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
482        let _result = self.send_raw(result);
483        if _result.is_err() {
484            self.control_handle.shutdown();
485        }
486        self.drop_without_shutdown();
487        _result
488    }
489
490    /// Similar to "send" but does not shutdown the channel if an error occurs.
491    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
492        let _result = self.send_raw(result);
493        self.drop_without_shutdown();
494        _result
495    }
496
497    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
498        self.control_handle
499            .inner
500            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
501                result,
502                self.tx_id,
503                0x141c1c4f3b6645ad,
504                fidl::encoding::DynamicFlags::empty(),
505            )
506    }
507}
508
509#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
510pub struct ProviderWatcherMarker;
511
512impl fidl::endpoints::ProtocolMarker for ProviderWatcherMarker {
513    type Proxy = ProviderWatcherProxy;
514    type RequestStream = ProviderWatcherRequestStream;
515    #[cfg(target_os = "fuchsia")]
516    type SynchronousProxy = ProviderWatcherSynchronousProxy;
517
518    const DEBUG_NAME: &'static str = "(anonymous) ProviderWatcher";
519}
520
521pub trait ProviderWatcherProxyInterface: Send + Sync {
522    type OnPairingCompleteResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
523    fn r#on_pairing_complete(
524        &self,
525        id: &fidl_fuchsia_bluetooth::PeerId,
526    ) -> Self::OnPairingCompleteResponseFut;
527}
528#[derive(Debug)]
529#[cfg(target_os = "fuchsia")]
530pub struct ProviderWatcherSynchronousProxy {
531    client: fidl::client::sync::Client,
532}
533
534#[cfg(target_os = "fuchsia")]
535impl fidl::endpoints::SynchronousProxy for ProviderWatcherSynchronousProxy {
536    type Proxy = ProviderWatcherProxy;
537    type Protocol = ProviderWatcherMarker;
538
539    fn from_channel(inner: fidl::Channel) -> Self {
540        Self::new(inner)
541    }
542
543    fn into_channel(self) -> fidl::Channel {
544        self.client.into_channel()
545    }
546
547    fn as_channel(&self) -> &fidl::Channel {
548        self.client.as_channel()
549    }
550}
551
552#[cfg(target_os = "fuchsia")]
553impl ProviderWatcherSynchronousProxy {
554    pub fn new(channel: fidl::Channel) -> Self {
555        let protocol_name = <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
556        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
557    }
558
559    pub fn into_channel(self) -> fidl::Channel {
560        self.client.into_channel()
561    }
562
563    /// Waits until an event arrives and returns it. It is safe for other
564    /// threads to make concurrent requests while waiting for an event.
565    pub fn wait_for_event(
566        &self,
567        deadline: zx::MonotonicInstant,
568    ) -> Result<ProviderWatcherEvent, fidl::Error> {
569        ProviderWatcherEvent::decode(self.client.wait_for_event(deadline)?)
570    }
571
572    /// Called if the Fast Pair pairing procedure for a peer is successfully complete.
573    ///
574    /// + request `id` The unique ID associated with the connected Fast Pair Seeker peer.
575    /// - response Each `OnPairingComplete` request should be acknowledged.
576    pub fn r#on_pairing_complete(
577        &self,
578        mut id: &fidl_fuchsia_bluetooth::PeerId,
579        ___deadline: zx::MonotonicInstant,
580    ) -> Result<(), fidl::Error> {
581        let _response = self
582            .client
583            .send_query::<ProviderWatcherOnPairingCompleteRequest, fidl::encoding::EmptyPayload>(
584                (id,),
585                0x7a918bb5f1ca3581,
586                fidl::encoding::DynamicFlags::empty(),
587                ___deadline,
588            )?;
589        Ok(_response)
590    }
591}
592
593#[derive(Debug, Clone)]
594pub struct ProviderWatcherProxy {
595    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
596}
597
598impl fidl::endpoints::Proxy for ProviderWatcherProxy {
599    type Protocol = ProviderWatcherMarker;
600
601    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
602        Self::new(inner)
603    }
604
605    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
606        self.client.into_channel().map_err(|client| Self { client })
607    }
608
609    fn as_channel(&self) -> &::fidl::AsyncChannel {
610        self.client.as_channel()
611    }
612}
613
614impl ProviderWatcherProxy {
615    /// Create a new Proxy for fuchsia.bluetooth.fastpair/ProviderWatcher.
616    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
617        let protocol_name = <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
618        Self { client: fidl::client::Client::new(channel, protocol_name) }
619    }
620
621    /// Get a Stream of events from the remote end of the protocol.
622    ///
623    /// # Panics
624    ///
625    /// Panics if the event stream was already taken.
626    pub fn take_event_stream(&self) -> ProviderWatcherEventStream {
627        ProviderWatcherEventStream { event_receiver: self.client.take_event_receiver() }
628    }
629
630    /// Called if the Fast Pair pairing procedure for a peer is successfully complete.
631    ///
632    /// + request `id` The unique ID associated with the connected Fast Pair Seeker peer.
633    /// - response Each `OnPairingComplete` request should be acknowledged.
634    pub fn r#on_pairing_complete(
635        &self,
636        mut id: &fidl_fuchsia_bluetooth::PeerId,
637    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
638        ProviderWatcherProxyInterface::r#on_pairing_complete(self, id)
639    }
640}
641
642impl ProviderWatcherProxyInterface for ProviderWatcherProxy {
643    type OnPairingCompleteResponseFut =
644        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
645    fn r#on_pairing_complete(
646        &self,
647        mut id: &fidl_fuchsia_bluetooth::PeerId,
648    ) -> Self::OnPairingCompleteResponseFut {
649        fn _decode(
650            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
651        ) -> Result<(), fidl::Error> {
652            let _response = fidl::client::decode_transaction_body::<
653                fidl::encoding::EmptyPayload,
654                fidl::encoding::DefaultFuchsiaResourceDialect,
655                0x7a918bb5f1ca3581,
656            >(_buf?)?;
657            Ok(_response)
658        }
659        self.client.send_query_and_decode::<ProviderWatcherOnPairingCompleteRequest, ()>(
660            (id,),
661            0x7a918bb5f1ca3581,
662            fidl::encoding::DynamicFlags::empty(),
663            _decode,
664        )
665    }
666}
667
668pub struct ProviderWatcherEventStream {
669    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
670}
671
672impl std::marker::Unpin for ProviderWatcherEventStream {}
673
674impl futures::stream::FusedStream for ProviderWatcherEventStream {
675    fn is_terminated(&self) -> bool {
676        self.event_receiver.is_terminated()
677    }
678}
679
680impl futures::Stream for ProviderWatcherEventStream {
681    type Item = Result<ProviderWatcherEvent, fidl::Error>;
682
683    fn poll_next(
684        mut self: std::pin::Pin<&mut Self>,
685        cx: &mut std::task::Context<'_>,
686    ) -> std::task::Poll<Option<Self::Item>> {
687        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
688            &mut self.event_receiver,
689            cx
690        )?) {
691            Some(buf) => std::task::Poll::Ready(Some(ProviderWatcherEvent::decode(buf))),
692            None => std::task::Poll::Ready(None),
693        }
694    }
695}
696
697#[derive(Debug)]
698pub enum ProviderWatcherEvent {}
699
700impl ProviderWatcherEvent {
701    /// Decodes a message buffer as a [`ProviderWatcherEvent`].
702    fn decode(
703        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
704    ) -> Result<ProviderWatcherEvent, fidl::Error> {
705        let (bytes, _handles) = buf.split_mut();
706        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
707        debug_assert_eq!(tx_header.tx_id, 0);
708        match tx_header.ordinal {
709            _ => Err(fidl::Error::UnknownOrdinal {
710                ordinal: tx_header.ordinal,
711                protocol_name:
712                    <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
713            }),
714        }
715    }
716}
717
718/// A Stream of incoming requests for fuchsia.bluetooth.fastpair/ProviderWatcher.
719pub struct ProviderWatcherRequestStream {
720    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
721    is_terminated: bool,
722}
723
724impl std::marker::Unpin for ProviderWatcherRequestStream {}
725
726impl futures::stream::FusedStream for ProviderWatcherRequestStream {
727    fn is_terminated(&self) -> bool {
728        self.is_terminated
729    }
730}
731
732impl fidl::endpoints::RequestStream for ProviderWatcherRequestStream {
733    type Protocol = ProviderWatcherMarker;
734    type ControlHandle = ProviderWatcherControlHandle;
735
736    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
737        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
738    }
739
740    fn control_handle(&self) -> Self::ControlHandle {
741        ProviderWatcherControlHandle { inner: self.inner.clone() }
742    }
743
744    fn into_inner(
745        self,
746    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
747    {
748        (self.inner, self.is_terminated)
749    }
750
751    fn from_inner(
752        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
753        is_terminated: bool,
754    ) -> Self {
755        Self { inner, is_terminated }
756    }
757}
758
759impl futures::Stream for ProviderWatcherRequestStream {
760    type Item = Result<ProviderWatcherRequest, fidl::Error>;
761
762    fn poll_next(
763        mut self: std::pin::Pin<&mut Self>,
764        cx: &mut std::task::Context<'_>,
765    ) -> std::task::Poll<Option<Self::Item>> {
766        let this = &mut *self;
767        if this.inner.check_shutdown(cx) {
768            this.is_terminated = true;
769            return std::task::Poll::Ready(None);
770        }
771        if this.is_terminated {
772            panic!("polled ProviderWatcherRequestStream after completion");
773        }
774        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
775            |bytes, handles| {
776                match this.inner.channel().read_etc(cx, bytes, handles) {
777                    std::task::Poll::Ready(Ok(())) => {}
778                    std::task::Poll::Pending => return std::task::Poll::Pending,
779                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
780                        this.is_terminated = true;
781                        return std::task::Poll::Ready(None);
782                    }
783                    std::task::Poll::Ready(Err(e)) => {
784                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
785                            e.into(),
786                        ))))
787                    }
788                }
789
790                // A message has been received from the channel
791                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
792
793                std::task::Poll::Ready(Some(match header.ordinal {
794                    0x7a918bb5f1ca3581 => {
795                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
796                        let mut req = fidl::new_empty!(
797                            ProviderWatcherOnPairingCompleteRequest,
798                            fidl::encoding::DefaultFuchsiaResourceDialect
799                        );
800                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderWatcherOnPairingCompleteRequest>(&header, _body_bytes, handles, &mut req)?;
801                        let control_handle =
802                            ProviderWatcherControlHandle { inner: this.inner.clone() };
803                        Ok(ProviderWatcherRequest::OnPairingComplete {
804                            id: req.id,
805
806                            responder: ProviderWatcherOnPairingCompleteResponder {
807                                control_handle: std::mem::ManuallyDrop::new(control_handle),
808                                tx_id: header.tx_id,
809                            },
810                        })
811                    }
812                    _ => Err(fidl::Error::UnknownOrdinal {
813                        ordinal: header.ordinal,
814                        protocol_name:
815                            <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
816                    }),
817                }))
818            },
819        )
820    }
821}
822
823/// Represents an active Fast Pair Provider service. The lifetime of the service is tied to this
824/// protocol.
825///
826/// Closing the protocol disables the service.
827///
828/// The system may close the protocol to communicate that the service was terminated
829/// for internal reasons.
830#[derive(Debug)]
831pub enum ProviderWatcherRequest {
832    /// Called if the Fast Pair pairing procedure for a peer is successfully complete.
833    ///
834    /// + request `id` The unique ID associated with the connected Fast Pair Seeker peer.
835    /// - response Each `OnPairingComplete` request should be acknowledged.
836    OnPairingComplete {
837        id: fidl_fuchsia_bluetooth::PeerId,
838        responder: ProviderWatcherOnPairingCompleteResponder,
839    },
840}
841
842impl ProviderWatcherRequest {
843    #[allow(irrefutable_let_patterns)]
844    pub fn into_on_pairing_complete(
845        self,
846    ) -> Option<(fidl_fuchsia_bluetooth::PeerId, ProviderWatcherOnPairingCompleteResponder)> {
847        if let ProviderWatcherRequest::OnPairingComplete { id, responder } = self {
848            Some((id, responder))
849        } else {
850            None
851        }
852    }
853
854    /// Name of the method defined in FIDL
855    pub fn method_name(&self) -> &'static str {
856        match *self {
857            ProviderWatcherRequest::OnPairingComplete { .. } => "on_pairing_complete",
858        }
859    }
860}
861
862#[derive(Debug, Clone)]
863pub struct ProviderWatcherControlHandle {
864    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
865}
866
867impl fidl::endpoints::ControlHandle for ProviderWatcherControlHandle {
868    fn shutdown(&self) {
869        self.inner.shutdown()
870    }
871    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
872        self.inner.shutdown_with_epitaph(status)
873    }
874
875    fn is_closed(&self) -> bool {
876        self.inner.channel().is_closed()
877    }
878    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
879        self.inner.channel().on_closed()
880    }
881
882    #[cfg(target_os = "fuchsia")]
883    fn signal_peer(
884        &self,
885        clear_mask: zx::Signals,
886        set_mask: zx::Signals,
887    ) -> Result<(), zx_status::Status> {
888        use fidl::Peered;
889        self.inner.channel().signal_peer(clear_mask, set_mask)
890    }
891}
892
893impl ProviderWatcherControlHandle {}
894
895#[must_use = "FIDL methods require a response to be sent"]
896#[derive(Debug)]
897pub struct ProviderWatcherOnPairingCompleteResponder {
898    control_handle: std::mem::ManuallyDrop<ProviderWatcherControlHandle>,
899    tx_id: u32,
900}
901
902/// Set the the channel to be shutdown (see [`ProviderWatcherControlHandle::shutdown`])
903/// if the responder is dropped without sending a response, so that the client
904/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
905impl std::ops::Drop for ProviderWatcherOnPairingCompleteResponder {
906    fn drop(&mut self) {
907        self.control_handle.shutdown();
908        // Safety: drops once, never accessed again
909        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
910    }
911}
912
913impl fidl::endpoints::Responder for ProviderWatcherOnPairingCompleteResponder {
914    type ControlHandle = ProviderWatcherControlHandle;
915
916    fn control_handle(&self) -> &ProviderWatcherControlHandle {
917        &self.control_handle
918    }
919
920    fn drop_without_shutdown(mut self) {
921        // Safety: drops once, never accessed again due to mem::forget
922        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
923        // Prevent Drop from running (which would shut down the channel)
924        std::mem::forget(self);
925    }
926}
927
928impl ProviderWatcherOnPairingCompleteResponder {
929    /// Sends a response to the FIDL transaction.
930    ///
931    /// Sets the channel to shutdown if an error occurs.
932    pub fn send(self) -> Result<(), fidl::Error> {
933        let _result = self.send_raw();
934        if _result.is_err() {
935            self.control_handle.shutdown();
936        }
937        self.drop_without_shutdown();
938        _result
939    }
940
941    /// Similar to "send" but does not shutdown the channel if an error occurs.
942    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
943        let _result = self.send_raw();
944        self.drop_without_shutdown();
945        _result
946    }
947
948    fn send_raw(&self) -> Result<(), fidl::Error> {
949        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
950            (),
951            self.tx_id,
952            0x7a918bb5f1ca3581,
953            fidl::encoding::DynamicFlags::empty(),
954        )
955    }
956}
957
958mod internal {
959    use super::*;
960
961    impl fidl::encoding::ResourceTypeMarker for ProviderEnableRequest {
962        type Borrowed<'a> = &'a mut Self;
963        fn take_or_borrow<'a>(
964            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
965        ) -> Self::Borrowed<'a> {
966            value
967        }
968    }
969
970    unsafe impl fidl::encoding::TypeMarker for ProviderEnableRequest {
971        type Owned = Self;
972
973        #[inline(always)]
974        fn inline_align(_context: fidl::encoding::Context) -> usize {
975            4
976        }
977
978        #[inline(always)]
979        fn inline_size(_context: fidl::encoding::Context) -> usize {
980            4
981        }
982    }
983
984    unsafe impl
985        fidl::encoding::Encode<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
986        for &mut ProviderEnableRequest
987    {
988        #[inline]
989        unsafe fn encode(
990            self,
991            encoder: &mut fidl::encoding::Encoder<
992                '_,
993                fidl::encoding::DefaultFuchsiaResourceDialect,
994            >,
995            offset: usize,
996            _depth: fidl::encoding::Depth,
997        ) -> fidl::Result<()> {
998            encoder.debug_check_bounds::<ProviderEnableRequest>(offset);
999            // Delegate to tuple encoding.
1000            fidl::encoding::Encode::<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1001                (
1002                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.watcher),
1003                ),
1004                encoder, offset, _depth
1005            )
1006        }
1007    }
1008    unsafe impl<
1009            T0: fidl::encoding::Encode<
1010                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1011                fidl::encoding::DefaultFuchsiaResourceDialect,
1012            >,
1013        >
1014        fidl::encoding::Encode<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1015        for (T0,)
1016    {
1017        #[inline]
1018        unsafe fn encode(
1019            self,
1020            encoder: &mut fidl::encoding::Encoder<
1021                '_,
1022                fidl::encoding::DefaultFuchsiaResourceDialect,
1023            >,
1024            offset: usize,
1025            depth: fidl::encoding::Depth,
1026        ) -> fidl::Result<()> {
1027            encoder.debug_check_bounds::<ProviderEnableRequest>(offset);
1028            // Zero out padding regions. There's no need to apply masks
1029            // because the unmasked parts will be overwritten by fields.
1030            // Write the fields.
1031            self.0.encode(encoder, offset + 0, depth)?;
1032            Ok(())
1033        }
1034    }
1035
1036    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1037        for ProviderEnableRequest
1038    {
1039        #[inline(always)]
1040        fn new_empty() -> Self {
1041            Self {
1042                watcher: fidl::new_empty!(
1043                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1044                    fidl::encoding::DefaultFuchsiaResourceDialect
1045                ),
1046            }
1047        }
1048
1049        #[inline]
1050        unsafe fn decode(
1051            &mut self,
1052            decoder: &mut fidl::encoding::Decoder<
1053                '_,
1054                fidl::encoding::DefaultFuchsiaResourceDialect,
1055            >,
1056            offset: usize,
1057            _depth: fidl::encoding::Depth,
1058        ) -> fidl::Result<()> {
1059            decoder.debug_check_bounds::<Self>(offset);
1060            // Verify that padding bytes are zero.
1061            fidl::decode!(
1062                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1063                fidl::encoding::DefaultFuchsiaResourceDialect,
1064                &mut self.watcher,
1065                decoder,
1066                offset + 0,
1067                _depth
1068            )?;
1069            Ok(())
1070        }
1071    }
1072
1073    impl fidl::encoding::ValueTypeMarker for ProviderWatcherOnPairingCompleteRequest {
1074        type Borrowed<'a> = &'a Self;
1075        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1076            value
1077        }
1078    }
1079
1080    unsafe impl fidl::encoding::TypeMarker for ProviderWatcherOnPairingCompleteRequest {
1081        type Owned = Self;
1082
1083        #[inline(always)]
1084        fn inline_align(_context: fidl::encoding::Context) -> usize {
1085            8
1086        }
1087
1088        #[inline(always)]
1089        fn inline_size(_context: fidl::encoding::Context) -> usize {
1090            8
1091        }
1092    }
1093
1094    unsafe impl<D: fidl::encoding::ResourceDialect>
1095        fidl::encoding::Encode<ProviderWatcherOnPairingCompleteRequest, D>
1096        for &ProviderWatcherOnPairingCompleteRequest
1097    {
1098        #[inline]
1099        unsafe fn encode(
1100            self,
1101            encoder: &mut fidl::encoding::Encoder<'_, D>,
1102            offset: usize,
1103            _depth: fidl::encoding::Depth,
1104        ) -> fidl::Result<()> {
1105            encoder.debug_check_bounds::<ProviderWatcherOnPairingCompleteRequest>(offset);
1106            // Delegate to tuple encoding.
1107            fidl::encoding::Encode::<ProviderWatcherOnPairingCompleteRequest, D>::encode(
1108                (<fidl_fuchsia_bluetooth::PeerId as fidl::encoding::ValueTypeMarker>::borrow(
1109                    &self.id,
1110                ),),
1111                encoder,
1112                offset,
1113                _depth,
1114            )
1115        }
1116    }
1117    unsafe impl<
1118            D: fidl::encoding::ResourceDialect,
1119            T0: fidl::encoding::Encode<fidl_fuchsia_bluetooth::PeerId, D>,
1120        > fidl::encoding::Encode<ProviderWatcherOnPairingCompleteRequest, D> for (T0,)
1121    {
1122        #[inline]
1123        unsafe fn encode(
1124            self,
1125            encoder: &mut fidl::encoding::Encoder<'_, D>,
1126            offset: usize,
1127            depth: fidl::encoding::Depth,
1128        ) -> fidl::Result<()> {
1129            encoder.debug_check_bounds::<ProviderWatcherOnPairingCompleteRequest>(offset);
1130            // Zero out padding regions. There's no need to apply masks
1131            // because the unmasked parts will be overwritten by fields.
1132            // Write the fields.
1133            self.0.encode(encoder, offset + 0, depth)?;
1134            Ok(())
1135        }
1136    }
1137
1138    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1139        for ProviderWatcherOnPairingCompleteRequest
1140    {
1141        #[inline(always)]
1142        fn new_empty() -> Self {
1143            Self { id: fidl::new_empty!(fidl_fuchsia_bluetooth::PeerId, D) }
1144        }
1145
1146        #[inline]
1147        unsafe fn decode(
1148            &mut self,
1149            decoder: &mut fidl::encoding::Decoder<'_, D>,
1150            offset: usize,
1151            _depth: fidl::encoding::Depth,
1152        ) -> fidl::Result<()> {
1153            decoder.debug_check_bounds::<Self>(offset);
1154            // Verify that padding bytes are zero.
1155            fidl::decode!(
1156                fidl_fuchsia_bluetooth::PeerId,
1157                D,
1158                &mut self.id,
1159                decoder,
1160                offset + 0,
1161                _depth
1162            )?;
1163            Ok(())
1164        }
1165    }
1166}