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