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