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