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