Skip to main content

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        Self { client: fidl::client::sync::Client::new(channel) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<ProviderEvent, fidl::Error> {
83        ProviderEvent::decode(self.client.wait_for_event::<ProviderMarker>(deadline)?)
84    }
85
86    /// Request to enable the Fast Pair Provider service.
87    ///
88    /// Only one client can register to enable the Fast Pair service. An Error will be returned
89    /// for subsequent requests.
90    ///
91    /// The lifetime of the service is tied to the provided `watcher`. To disable Fast Pair
92    /// functionality, close the `watcher`.
93    ///
94    /// + request `watcher` The client end of the ProviderWatcher which determines the lifetime of
95    ///   the Fast Pair service.
96    /// - response An empty response will be sent when the server has processed the
97    ///   request.
98    /// * error Returns `ALREADY_BOUND` if a subsequent request is made to enable
99    ///   the service.
100    pub fn r#enable(
101        &self,
102        mut watcher: fidl::endpoints::ClientEnd<ProviderWatcherMarker>,
103        ___deadline: zx::MonotonicInstant,
104    ) -> Result<ProviderEnableResult, fidl::Error> {
105        let _response = self.client.send_query::<
106            ProviderEnableRequest,
107            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
108            ProviderMarker,
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::NullableHandle {
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
438    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
439        self.inner.shutdown_with_epitaph(status)
440    }
441
442    fn is_closed(&self) -> bool {
443        self.inner.channel().is_closed()
444    }
445    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
446        self.inner.channel().on_closed()
447    }
448
449    #[cfg(target_os = "fuchsia")]
450    fn signal_peer(
451        &self,
452        clear_mask: zx::Signals,
453        set_mask: zx::Signals,
454    ) -> Result<(), zx_status::Status> {
455        use fidl::Peered;
456        self.inner.channel().signal_peer(clear_mask, set_mask)
457    }
458}
459
460impl ProviderControlHandle {}
461
462#[must_use = "FIDL methods require a response to be sent"]
463#[derive(Debug)]
464pub struct ProviderEnableResponder {
465    control_handle: std::mem::ManuallyDrop<ProviderControlHandle>,
466    tx_id: u32,
467}
468
469/// Set the the channel to be shutdown (see [`ProviderControlHandle::shutdown`])
470/// if the responder is dropped without sending a response, so that the client
471/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
472impl std::ops::Drop for ProviderEnableResponder {
473    fn drop(&mut self) {
474        self.control_handle.shutdown();
475        // Safety: drops once, never accessed again
476        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
477    }
478}
479
480impl fidl::endpoints::Responder for ProviderEnableResponder {
481    type ControlHandle = ProviderControlHandle;
482
483    fn control_handle(&self) -> &ProviderControlHandle {
484        &self.control_handle
485    }
486
487    fn drop_without_shutdown(mut self) {
488        // Safety: drops once, never accessed again due to mem::forget
489        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
490        // Prevent Drop from running (which would shut down the channel)
491        std::mem::forget(self);
492    }
493}
494
495impl ProviderEnableResponder {
496    /// Sends a response to the FIDL transaction.
497    ///
498    /// Sets the channel to shutdown if an error occurs.
499    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
500        let _result = self.send_raw(result);
501        if _result.is_err() {
502            self.control_handle.shutdown();
503        }
504        self.drop_without_shutdown();
505        _result
506    }
507
508    /// Similar to "send" but does not shutdown the channel if an error occurs.
509    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
510        let _result = self.send_raw(result);
511        self.drop_without_shutdown();
512        _result
513    }
514
515    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
516        self.control_handle
517            .inner
518            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
519                result,
520                self.tx_id,
521                0x141c1c4f3b6645ad,
522                fidl::encoding::DynamicFlags::empty(),
523            )
524    }
525}
526
527#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
528pub struct ProviderWatcherMarker;
529
530impl fidl::endpoints::ProtocolMarker for ProviderWatcherMarker {
531    type Proxy = ProviderWatcherProxy;
532    type RequestStream = ProviderWatcherRequestStream;
533    #[cfg(target_os = "fuchsia")]
534    type SynchronousProxy = ProviderWatcherSynchronousProxy;
535
536    const DEBUG_NAME: &'static str = "(anonymous) ProviderWatcher";
537}
538
539pub trait ProviderWatcherProxyInterface: Send + Sync {
540    type OnPairingCompleteResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
541    fn r#on_pairing_complete(
542        &self,
543        id: &fidl_fuchsia_bluetooth::PeerId,
544    ) -> Self::OnPairingCompleteResponseFut;
545}
546#[derive(Debug)]
547#[cfg(target_os = "fuchsia")]
548pub struct ProviderWatcherSynchronousProxy {
549    client: fidl::client::sync::Client,
550}
551
552#[cfg(target_os = "fuchsia")]
553impl fidl::endpoints::SynchronousProxy for ProviderWatcherSynchronousProxy {
554    type Proxy = ProviderWatcherProxy;
555    type Protocol = ProviderWatcherMarker;
556
557    fn from_channel(inner: fidl::Channel) -> Self {
558        Self::new(inner)
559    }
560
561    fn into_channel(self) -> fidl::Channel {
562        self.client.into_channel()
563    }
564
565    fn as_channel(&self) -> &fidl::Channel {
566        self.client.as_channel()
567    }
568}
569
570#[cfg(target_os = "fuchsia")]
571impl ProviderWatcherSynchronousProxy {
572    pub fn new(channel: fidl::Channel) -> Self {
573        Self { client: fidl::client::sync::Client::new(channel) }
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::<ProviderWatcherMarker>(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.client.send_query::<
599            ProviderWatcherOnPairingCompleteRequest,
600            fidl::encoding::EmptyPayload,
601            ProviderWatcherMarker,
602        >(
603            (id,),
604            0x7a918bb5f1ca3581,
605            fidl::encoding::DynamicFlags::empty(),
606            ___deadline,
607        )?;
608        Ok(_response)
609    }
610}
611
612#[cfg(target_os = "fuchsia")]
613impl From<ProviderWatcherSynchronousProxy> for zx::NullableHandle {
614    fn from(value: ProviderWatcherSynchronousProxy) -> Self {
615        value.into_channel().into()
616    }
617}
618
619#[cfg(target_os = "fuchsia")]
620impl From<fidl::Channel> for ProviderWatcherSynchronousProxy {
621    fn from(value: fidl::Channel) -> Self {
622        Self::new(value)
623    }
624}
625
626#[cfg(target_os = "fuchsia")]
627impl fidl::endpoints::FromClient for ProviderWatcherSynchronousProxy {
628    type Protocol = ProviderWatcherMarker;
629
630    fn from_client(value: fidl::endpoints::ClientEnd<ProviderWatcherMarker>) -> Self {
631        Self::new(value.into_channel())
632    }
633}
634
635#[derive(Debug, Clone)]
636pub struct ProviderWatcherProxy {
637    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
638}
639
640impl fidl::endpoints::Proxy for ProviderWatcherProxy {
641    type Protocol = ProviderWatcherMarker;
642
643    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
644        Self::new(inner)
645    }
646
647    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
648        self.client.into_channel().map_err(|client| Self { client })
649    }
650
651    fn as_channel(&self) -> &::fidl::AsyncChannel {
652        self.client.as_channel()
653    }
654}
655
656impl ProviderWatcherProxy {
657    /// Create a new Proxy for fuchsia.bluetooth.fastpair/ProviderWatcher.
658    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
659        let protocol_name = <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
660        Self { client: fidl::client::Client::new(channel, protocol_name) }
661    }
662
663    /// Get a Stream of events from the remote end of the protocol.
664    ///
665    /// # Panics
666    ///
667    /// Panics if the event stream was already taken.
668    pub fn take_event_stream(&self) -> ProviderWatcherEventStream {
669        ProviderWatcherEventStream { event_receiver: self.client.take_event_receiver() }
670    }
671
672    /// Called if the Fast Pair pairing procedure for a peer is successfully complete.
673    ///
674    /// + request `id` The unique ID associated with the connected Fast Pair Seeker peer.
675    /// - response Each `OnPairingComplete` request should be acknowledged.
676    pub fn r#on_pairing_complete(
677        &self,
678        mut id: &fidl_fuchsia_bluetooth::PeerId,
679    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
680        ProviderWatcherProxyInterface::r#on_pairing_complete(self, id)
681    }
682}
683
684impl ProviderWatcherProxyInterface for ProviderWatcherProxy {
685    type OnPairingCompleteResponseFut =
686        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
687    fn r#on_pairing_complete(
688        &self,
689        mut id: &fidl_fuchsia_bluetooth::PeerId,
690    ) -> Self::OnPairingCompleteResponseFut {
691        fn _decode(
692            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
693        ) -> Result<(), fidl::Error> {
694            let _response = fidl::client::decode_transaction_body::<
695                fidl::encoding::EmptyPayload,
696                fidl::encoding::DefaultFuchsiaResourceDialect,
697                0x7a918bb5f1ca3581,
698            >(_buf?)?;
699            Ok(_response)
700        }
701        self.client.send_query_and_decode::<ProviderWatcherOnPairingCompleteRequest, ()>(
702            (id,),
703            0x7a918bb5f1ca3581,
704            fidl::encoding::DynamicFlags::empty(),
705            _decode,
706        )
707    }
708}
709
710pub struct ProviderWatcherEventStream {
711    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
712}
713
714impl std::marker::Unpin for ProviderWatcherEventStream {}
715
716impl futures::stream::FusedStream for ProviderWatcherEventStream {
717    fn is_terminated(&self) -> bool {
718        self.event_receiver.is_terminated()
719    }
720}
721
722impl futures::Stream for ProviderWatcherEventStream {
723    type Item = Result<ProviderWatcherEvent, fidl::Error>;
724
725    fn poll_next(
726        mut self: std::pin::Pin<&mut Self>,
727        cx: &mut std::task::Context<'_>,
728    ) -> std::task::Poll<Option<Self::Item>> {
729        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
730            &mut self.event_receiver,
731            cx
732        )?) {
733            Some(buf) => std::task::Poll::Ready(Some(ProviderWatcherEvent::decode(buf))),
734            None => std::task::Poll::Ready(None),
735        }
736    }
737}
738
739#[derive(Debug)]
740pub enum ProviderWatcherEvent {}
741
742impl ProviderWatcherEvent {
743    /// Decodes a message buffer as a [`ProviderWatcherEvent`].
744    fn decode(
745        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
746    ) -> Result<ProviderWatcherEvent, fidl::Error> {
747        let (bytes, _handles) = buf.split_mut();
748        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
749        debug_assert_eq!(tx_header.tx_id, 0);
750        match tx_header.ordinal {
751            _ => Err(fidl::Error::UnknownOrdinal {
752                ordinal: tx_header.ordinal,
753                protocol_name:
754                    <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
755            }),
756        }
757    }
758}
759
760/// A Stream of incoming requests for fuchsia.bluetooth.fastpair/ProviderWatcher.
761pub struct ProviderWatcherRequestStream {
762    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
763    is_terminated: bool,
764}
765
766impl std::marker::Unpin for ProviderWatcherRequestStream {}
767
768impl futures::stream::FusedStream for ProviderWatcherRequestStream {
769    fn is_terminated(&self) -> bool {
770        self.is_terminated
771    }
772}
773
774impl fidl::endpoints::RequestStream for ProviderWatcherRequestStream {
775    type Protocol = ProviderWatcherMarker;
776    type ControlHandle = ProviderWatcherControlHandle;
777
778    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
779        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
780    }
781
782    fn control_handle(&self) -> Self::ControlHandle {
783        ProviderWatcherControlHandle { inner: self.inner.clone() }
784    }
785
786    fn into_inner(
787        self,
788    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
789    {
790        (self.inner, self.is_terminated)
791    }
792
793    fn from_inner(
794        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
795        is_terminated: bool,
796    ) -> Self {
797        Self { inner, is_terminated }
798    }
799}
800
801impl futures::Stream for ProviderWatcherRequestStream {
802    type Item = Result<ProviderWatcherRequest, fidl::Error>;
803
804    fn poll_next(
805        mut self: std::pin::Pin<&mut Self>,
806        cx: &mut std::task::Context<'_>,
807    ) -> std::task::Poll<Option<Self::Item>> {
808        let this = &mut *self;
809        if this.inner.check_shutdown(cx) {
810            this.is_terminated = true;
811            return std::task::Poll::Ready(None);
812        }
813        if this.is_terminated {
814            panic!("polled ProviderWatcherRequestStream after completion");
815        }
816        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
817            |bytes, handles| {
818                match this.inner.channel().read_etc(cx, bytes, handles) {
819                    std::task::Poll::Ready(Ok(())) => {}
820                    std::task::Poll::Pending => return std::task::Poll::Pending,
821                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
822                        this.is_terminated = true;
823                        return std::task::Poll::Ready(None);
824                    }
825                    std::task::Poll::Ready(Err(e)) => {
826                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
827                            e.into(),
828                        ))));
829                    }
830                }
831
832                // A message has been received from the channel
833                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
834
835                std::task::Poll::Ready(Some(match header.ordinal {
836                    0x7a918bb5f1ca3581 => {
837                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
838                        let mut req = fidl::new_empty!(
839                            ProviderWatcherOnPairingCompleteRequest,
840                            fidl::encoding::DefaultFuchsiaResourceDialect
841                        );
842                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderWatcherOnPairingCompleteRequest>(&header, _body_bytes, handles, &mut req)?;
843                        let control_handle =
844                            ProviderWatcherControlHandle { inner: this.inner.clone() };
845                        Ok(ProviderWatcherRequest::OnPairingComplete {
846                            id: req.id,
847
848                            responder: ProviderWatcherOnPairingCompleteResponder {
849                                control_handle: std::mem::ManuallyDrop::new(control_handle),
850                                tx_id: header.tx_id,
851                            },
852                        })
853                    }
854                    _ => Err(fidl::Error::UnknownOrdinal {
855                        ordinal: header.ordinal,
856                        protocol_name:
857                            <ProviderWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
858                    }),
859                }))
860            },
861        )
862    }
863}
864
865/// Represents an active Fast Pair Provider service. The lifetime of the service is tied to this
866/// protocol.
867///
868/// Closing the protocol disables the service.
869///
870/// The system may close the protocol to communicate that the service was terminated
871/// for internal reasons.
872#[derive(Debug)]
873pub enum ProviderWatcherRequest {
874    /// Called if the Fast Pair pairing procedure for a peer is successfully complete.
875    ///
876    /// + request `id` The unique ID associated with the connected Fast Pair Seeker peer.
877    /// - response Each `OnPairingComplete` request should be acknowledged.
878    OnPairingComplete {
879        id: fidl_fuchsia_bluetooth::PeerId,
880        responder: ProviderWatcherOnPairingCompleteResponder,
881    },
882}
883
884impl ProviderWatcherRequest {
885    #[allow(irrefutable_let_patterns)]
886    pub fn into_on_pairing_complete(
887        self,
888    ) -> Option<(fidl_fuchsia_bluetooth::PeerId, ProviderWatcherOnPairingCompleteResponder)> {
889        if let ProviderWatcherRequest::OnPairingComplete { id, responder } = self {
890            Some((id, responder))
891        } else {
892            None
893        }
894    }
895
896    /// Name of the method defined in FIDL
897    pub fn method_name(&self) -> &'static str {
898        match *self {
899            ProviderWatcherRequest::OnPairingComplete { .. } => "on_pairing_complete",
900        }
901    }
902}
903
904#[derive(Debug, Clone)]
905pub struct ProviderWatcherControlHandle {
906    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
907}
908
909impl fidl::endpoints::ControlHandle for ProviderWatcherControlHandle {
910    fn shutdown(&self) {
911        self.inner.shutdown()
912    }
913
914    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
915        self.inner.shutdown_with_epitaph(status)
916    }
917
918    fn is_closed(&self) -> bool {
919        self.inner.channel().is_closed()
920    }
921    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
922        self.inner.channel().on_closed()
923    }
924
925    #[cfg(target_os = "fuchsia")]
926    fn signal_peer(
927        &self,
928        clear_mask: zx::Signals,
929        set_mask: zx::Signals,
930    ) -> Result<(), zx_status::Status> {
931        use fidl::Peered;
932        self.inner.channel().signal_peer(clear_mask, set_mask)
933    }
934}
935
936impl ProviderWatcherControlHandle {}
937
938#[must_use = "FIDL methods require a response to be sent"]
939#[derive(Debug)]
940pub struct ProviderWatcherOnPairingCompleteResponder {
941    control_handle: std::mem::ManuallyDrop<ProviderWatcherControlHandle>,
942    tx_id: u32,
943}
944
945/// Set the the channel to be shutdown (see [`ProviderWatcherControlHandle::shutdown`])
946/// if the responder is dropped without sending a response, so that the client
947/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
948impl std::ops::Drop for ProviderWatcherOnPairingCompleteResponder {
949    fn drop(&mut self) {
950        self.control_handle.shutdown();
951        // Safety: drops once, never accessed again
952        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
953    }
954}
955
956impl fidl::endpoints::Responder for ProviderWatcherOnPairingCompleteResponder {
957    type ControlHandle = ProviderWatcherControlHandle;
958
959    fn control_handle(&self) -> &ProviderWatcherControlHandle {
960        &self.control_handle
961    }
962
963    fn drop_without_shutdown(mut self) {
964        // Safety: drops once, never accessed again due to mem::forget
965        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
966        // Prevent Drop from running (which would shut down the channel)
967        std::mem::forget(self);
968    }
969}
970
971impl ProviderWatcherOnPairingCompleteResponder {
972    /// Sends a response to the FIDL transaction.
973    ///
974    /// Sets the channel to shutdown if an error occurs.
975    pub fn send(self) -> Result<(), fidl::Error> {
976        let _result = self.send_raw();
977        if _result.is_err() {
978            self.control_handle.shutdown();
979        }
980        self.drop_without_shutdown();
981        _result
982    }
983
984    /// Similar to "send" but does not shutdown the channel if an error occurs.
985    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
986        let _result = self.send_raw();
987        self.drop_without_shutdown();
988        _result
989    }
990
991    fn send_raw(&self) -> Result<(), fidl::Error> {
992        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
993            (),
994            self.tx_id,
995            0x7a918bb5f1ca3581,
996            fidl::encoding::DynamicFlags::empty(),
997        )
998    }
999}
1000
1001mod internal {
1002    use super::*;
1003
1004    impl fidl::encoding::ResourceTypeMarker for ProviderEnableRequest {
1005        type Borrowed<'a> = &'a mut Self;
1006        fn take_or_borrow<'a>(
1007            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1008        ) -> Self::Borrowed<'a> {
1009            value
1010        }
1011    }
1012
1013    unsafe impl fidl::encoding::TypeMarker for ProviderEnableRequest {
1014        type Owned = Self;
1015
1016        #[inline(always)]
1017        fn inline_align(_context: fidl::encoding::Context) -> usize {
1018            4
1019        }
1020
1021        #[inline(always)]
1022        fn inline_size(_context: fidl::encoding::Context) -> usize {
1023            4
1024        }
1025    }
1026
1027    unsafe impl
1028        fidl::encoding::Encode<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1029        for &mut ProviderEnableRequest
1030    {
1031        #[inline]
1032        unsafe fn encode(
1033            self,
1034            encoder: &mut fidl::encoding::Encoder<
1035                '_,
1036                fidl::encoding::DefaultFuchsiaResourceDialect,
1037            >,
1038            offset: usize,
1039            _depth: fidl::encoding::Depth,
1040        ) -> fidl::Result<()> {
1041            encoder.debug_check_bounds::<ProviderEnableRequest>(offset);
1042            // Delegate to tuple encoding.
1043            fidl::encoding::Encode::<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1044                (
1045                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.watcher),
1046                ),
1047                encoder, offset, _depth
1048            )
1049        }
1050    }
1051    unsafe impl<
1052        T0: fidl::encoding::Encode<
1053                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1054                fidl::encoding::DefaultFuchsiaResourceDialect,
1055            >,
1056    >
1057        fidl::encoding::Encode<ProviderEnableRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1058        for (T0,)
1059    {
1060        #[inline]
1061        unsafe fn encode(
1062            self,
1063            encoder: &mut fidl::encoding::Encoder<
1064                '_,
1065                fidl::encoding::DefaultFuchsiaResourceDialect,
1066            >,
1067            offset: usize,
1068            depth: fidl::encoding::Depth,
1069        ) -> fidl::Result<()> {
1070            encoder.debug_check_bounds::<ProviderEnableRequest>(offset);
1071            // Zero out padding regions. There's no need to apply masks
1072            // because the unmasked parts will be overwritten by fields.
1073            // Write the fields.
1074            self.0.encode(encoder, offset + 0, depth)?;
1075            Ok(())
1076        }
1077    }
1078
1079    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1080        for ProviderEnableRequest
1081    {
1082        #[inline(always)]
1083        fn new_empty() -> Self {
1084            Self {
1085                watcher: fidl::new_empty!(
1086                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1087                    fidl::encoding::DefaultFuchsiaResourceDialect
1088                ),
1089            }
1090        }
1091
1092        #[inline]
1093        unsafe fn decode(
1094            &mut self,
1095            decoder: &mut fidl::encoding::Decoder<
1096                '_,
1097                fidl::encoding::DefaultFuchsiaResourceDialect,
1098            >,
1099            offset: usize,
1100            _depth: fidl::encoding::Depth,
1101        ) -> fidl::Result<()> {
1102            decoder.debug_check_bounds::<Self>(offset);
1103            // Verify that padding bytes are zero.
1104            fidl::decode!(
1105                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ProviderWatcherMarker>>,
1106                fidl::encoding::DefaultFuchsiaResourceDialect,
1107                &mut self.watcher,
1108                decoder,
1109                offset + 0,
1110                _depth
1111            )?;
1112            Ok(())
1113        }
1114    }
1115}