Skip to main content

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        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<ControllerEvent, fidl::Error> {
83        ControllerEvent::decode(self.client.wait_for_event::<ControllerMarker>(deadline)?)
84    }
85
86    /// Request to suspend the A2DP media stream.
87    ///
88    /// Any active stream with the specified peer will be suspended. No new streams can
89    /// be started with the peer until the `token` has been closed. It is valid to have multiple
90    /// outstanding tokens for a single peer. The restriction on streaming will be uplifted
91    /// when all outstanding handles have been closed.
92    ///
93    /// This method will resolve when the `token` is closed and the server has processed the
94    /// close request.
95    ///
96    /// + request `peer_id` is the unique identifier of the remote peer whose streaming
97    ///           connection should be suspended. If no `peer_id` is provided, all active streams
98    ///           will be suspended and no new streams can be started.
99    /// + request `token` is used to manage the state of the streaming connection. The media
100    ///           stream will remain suspended as long as the server end of the channel is open.
101    ///           The streaming restrictions will be removed when `token` is closed with any
102    ///           epitaph.
103    ///
104    /// If the suspend request cannot be processed due to an internal error, the server will close
105    /// the `token` channel with the zx::Status::INTERNAL signal and the method will resolve.
106    pub fn r#suspend(
107        &self,
108        mut peer_id: Option<&fidl_fuchsia_bluetooth::PeerId>,
109        mut token: fidl::endpoints::ServerEnd<StreamSuspenderMarker>,
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<(), fidl::Error> {
112        let _response = self
113            .client
114            .send_query::<ControllerSuspendRequest, fidl::encoding::EmptyPayload, ControllerMarker>(
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        Self { client: fidl::client::sync::Client::new(channel) }
586    }
587
588    pub fn into_channel(self) -> fidl::Channel {
589        self.client.into_channel()
590    }
591
592    /// Waits until an event arrives and returns it. It is safe for other
593    /// threads to make concurrent requests while waiting for an event.
594    pub fn wait_for_event(
595        &self,
596        deadline: zx::MonotonicInstant,
597    ) -> Result<StreamSuspenderEvent, fidl::Error> {
598        StreamSuspenderEvent::decode(self.client.wait_for_event::<StreamSuspenderMarker>(deadline)?)
599    }
600}
601
602#[cfg(target_os = "fuchsia")]
603impl From<StreamSuspenderSynchronousProxy> for zx::NullableHandle {
604    fn from(value: StreamSuspenderSynchronousProxy) -> Self {
605        value.into_channel().into()
606    }
607}
608
609#[cfg(target_os = "fuchsia")]
610impl From<fidl::Channel> for StreamSuspenderSynchronousProxy {
611    fn from(value: fidl::Channel) -> Self {
612        Self::new(value)
613    }
614}
615
616#[cfg(target_os = "fuchsia")]
617impl fidl::endpoints::FromClient for StreamSuspenderSynchronousProxy {
618    type Protocol = StreamSuspenderMarker;
619
620    fn from_client(value: fidl::endpoints::ClientEnd<StreamSuspenderMarker>) -> Self {
621        Self::new(value.into_channel())
622    }
623}
624
625#[derive(Debug, Clone)]
626pub struct StreamSuspenderProxy {
627    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
628}
629
630impl fidl::endpoints::Proxy for StreamSuspenderProxy {
631    type Protocol = StreamSuspenderMarker;
632
633    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
634        Self::new(inner)
635    }
636
637    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
638        self.client.into_channel().map_err(|client| Self { client })
639    }
640
641    fn as_channel(&self) -> &::fidl::AsyncChannel {
642        self.client.as_channel()
643    }
644}
645
646impl StreamSuspenderProxy {
647    /// Create a new Proxy for fuchsia.bluetooth.internal.a2dp/StreamSuspender.
648    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
649        let protocol_name = <StreamSuspenderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
650        Self { client: fidl::client::Client::new(channel, protocol_name) }
651    }
652
653    /// Get a Stream of events from the remote end of the protocol.
654    ///
655    /// # Panics
656    ///
657    /// Panics if the event stream was already taken.
658    pub fn take_event_stream(&self) -> StreamSuspenderEventStream {
659        StreamSuspenderEventStream { event_receiver: self.client.take_event_receiver() }
660    }
661}
662
663impl StreamSuspenderProxyInterface for StreamSuspenderProxy {}
664
665pub struct StreamSuspenderEventStream {
666    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
667}
668
669impl std::marker::Unpin for StreamSuspenderEventStream {}
670
671impl futures::stream::FusedStream for StreamSuspenderEventStream {
672    fn is_terminated(&self) -> bool {
673        self.event_receiver.is_terminated()
674    }
675}
676
677impl futures::Stream for StreamSuspenderEventStream {
678    type Item = Result<StreamSuspenderEvent, fidl::Error>;
679
680    fn poll_next(
681        mut self: std::pin::Pin<&mut Self>,
682        cx: &mut std::task::Context<'_>,
683    ) -> std::task::Poll<Option<Self::Item>> {
684        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
685            &mut self.event_receiver,
686            cx
687        )?) {
688            Some(buf) => std::task::Poll::Ready(Some(StreamSuspenderEvent::decode(buf))),
689            None => std::task::Poll::Ready(None),
690        }
691    }
692}
693
694#[derive(Debug)]
695pub enum StreamSuspenderEvent {
696    OnSuspended {},
697}
698
699impl StreamSuspenderEvent {
700    #[allow(irrefutable_let_patterns)]
701    pub fn into_on_suspended(self) -> Option<()> {
702        if let StreamSuspenderEvent::OnSuspended {} = self { Some(()) } else { None }
703    }
704
705    /// Decodes a message buffer as a [`StreamSuspenderEvent`].
706    fn decode(
707        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
708    ) -> Result<StreamSuspenderEvent, fidl::Error> {
709        let (bytes, _handles) = buf.split_mut();
710        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
711        debug_assert_eq!(tx_header.tx_id, 0);
712        match tx_header.ordinal {
713            0x3f927abc531cba34 => {
714                let mut out = fidl::new_empty!(
715                    fidl::encoding::EmptyPayload,
716                    fidl::encoding::DefaultFuchsiaResourceDialect
717                );
718                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&tx_header, _body_bytes, _handles, &mut out)?;
719                Ok((StreamSuspenderEvent::OnSuspended {}))
720            }
721            _ => Err(fidl::Error::UnknownOrdinal {
722                ordinal: tx_header.ordinal,
723                protocol_name:
724                    <StreamSuspenderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
725            }),
726        }
727    }
728}
729
730/// A Stream of incoming requests for fuchsia.bluetooth.internal.a2dp/StreamSuspender.
731pub struct StreamSuspenderRequestStream {
732    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
733    is_terminated: bool,
734}
735
736impl std::marker::Unpin for StreamSuspenderRequestStream {}
737
738impl futures::stream::FusedStream for StreamSuspenderRequestStream {
739    fn is_terminated(&self) -> bool {
740        self.is_terminated
741    }
742}
743
744impl fidl::endpoints::RequestStream for StreamSuspenderRequestStream {
745    type Protocol = StreamSuspenderMarker;
746    type ControlHandle = StreamSuspenderControlHandle;
747
748    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
749        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
750    }
751
752    fn control_handle(&self) -> Self::ControlHandle {
753        StreamSuspenderControlHandle { inner: self.inner.clone() }
754    }
755
756    fn into_inner(
757        self,
758    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
759    {
760        (self.inner, self.is_terminated)
761    }
762
763    fn from_inner(
764        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
765        is_terminated: bool,
766    ) -> Self {
767        Self { inner, is_terminated }
768    }
769}
770
771impl futures::Stream for StreamSuspenderRequestStream {
772    type Item = Result<StreamSuspenderRequest, fidl::Error>;
773
774    fn poll_next(
775        mut self: std::pin::Pin<&mut Self>,
776        cx: &mut std::task::Context<'_>,
777    ) -> std::task::Poll<Option<Self::Item>> {
778        let this = &mut *self;
779        if this.inner.check_shutdown(cx) {
780            this.is_terminated = true;
781            return std::task::Poll::Ready(None);
782        }
783        if this.is_terminated {
784            panic!("polled StreamSuspenderRequestStream after completion");
785        }
786        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
787            |bytes, handles| {
788                match this.inner.channel().read_etc(cx, bytes, handles) {
789                    std::task::Poll::Ready(Ok(())) => {}
790                    std::task::Poll::Pending => return std::task::Poll::Pending,
791                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
792                        this.is_terminated = true;
793                        return std::task::Poll::Ready(None);
794                    }
795                    std::task::Poll::Ready(Err(e)) => {
796                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
797                            e.into(),
798                        ))));
799                    }
800                }
801
802                // A message has been received from the channel
803                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
804
805                std::task::Poll::Ready(Some(match header.ordinal {
806                    _ => Err(fidl::Error::UnknownOrdinal {
807                        ordinal: header.ordinal,
808                        protocol_name:
809                            <StreamSuspenderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
810                    }),
811                }))
812            },
813        )
814    }
815}
816
817/// Represents a hold on a media stream.
818#[derive(Debug)]
819pub enum StreamSuspenderRequest {}
820
821impl StreamSuspenderRequest {
822    /// Name of the method defined in FIDL
823    pub fn method_name(&self) -> &'static str {
824        match *self {}
825    }
826}
827
828#[derive(Debug, Clone)]
829pub struct StreamSuspenderControlHandle {
830    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
831}
832
833impl fidl::endpoints::ControlHandle for StreamSuspenderControlHandle {
834    fn shutdown(&self) {
835        self.inner.shutdown()
836    }
837
838    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
839        self.inner.shutdown_with_epitaph(status)
840    }
841
842    fn is_closed(&self) -> bool {
843        self.inner.channel().is_closed()
844    }
845    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
846        self.inner.channel().on_closed()
847    }
848
849    #[cfg(target_os = "fuchsia")]
850    fn signal_peer(
851        &self,
852        clear_mask: zx::Signals,
853        set_mask: zx::Signals,
854    ) -> Result<(), zx_status::Status> {
855        use fidl::Peered;
856        self.inner.channel().signal_peer(clear_mask, set_mask)
857    }
858}
859
860impl StreamSuspenderControlHandle {
861    pub fn send_on_suspended(&self) -> Result<(), fidl::Error> {
862        self.inner.send::<fidl::encoding::EmptyPayload>(
863            (),
864            0,
865            0x3f927abc531cba34,
866            fidl::encoding::DynamicFlags::empty(),
867        )
868    }
869}
870
871mod internal {
872    use super::*;
873
874    impl fidl::encoding::ResourceTypeMarker for ControllerSuspendRequest {
875        type Borrowed<'a> = &'a mut Self;
876        fn take_or_borrow<'a>(
877            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
878        ) -> Self::Borrowed<'a> {
879            value
880        }
881    }
882
883    unsafe impl fidl::encoding::TypeMarker for ControllerSuspendRequest {
884        type Owned = Self;
885
886        #[inline(always)]
887        fn inline_align(_context: fidl::encoding::Context) -> usize {
888            8
889        }
890
891        #[inline(always)]
892        fn inline_size(_context: fidl::encoding::Context) -> usize {
893            16
894        }
895    }
896
897    unsafe impl
898        fidl::encoding::Encode<
899            ControllerSuspendRequest,
900            fidl::encoding::DefaultFuchsiaResourceDialect,
901        > for &mut ControllerSuspendRequest
902    {
903        #[inline]
904        unsafe fn encode(
905            self,
906            encoder: &mut fidl::encoding::Encoder<
907                '_,
908                fidl::encoding::DefaultFuchsiaResourceDialect,
909            >,
910            offset: usize,
911            _depth: fidl::encoding::Depth,
912        ) -> fidl::Result<()> {
913            encoder.debug_check_bounds::<ControllerSuspendRequest>(offset);
914            // Delegate to tuple encoding.
915            fidl::encoding::Encode::<ControllerSuspendRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
916                (
917                    <fidl::encoding::Boxed<fidl_fuchsia_bluetooth::PeerId> as fidl::encoding::ValueTypeMarker>::borrow(&self.peer_id),
918                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<StreamSuspenderMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.token),
919                ),
920                encoder, offset, _depth
921            )
922        }
923    }
924    unsafe impl<
925        T0: fidl::encoding::Encode<
926                fidl::encoding::Boxed<fidl_fuchsia_bluetooth::PeerId>,
927                fidl::encoding::DefaultFuchsiaResourceDialect,
928            >,
929        T1: fidl::encoding::Encode<
930                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<StreamSuspenderMarker>>,
931                fidl::encoding::DefaultFuchsiaResourceDialect,
932            >,
933    >
934        fidl::encoding::Encode<
935            ControllerSuspendRequest,
936            fidl::encoding::DefaultFuchsiaResourceDialect,
937        > for (T0, T1)
938    {
939        #[inline]
940        unsafe fn encode(
941            self,
942            encoder: &mut fidl::encoding::Encoder<
943                '_,
944                fidl::encoding::DefaultFuchsiaResourceDialect,
945            >,
946            offset: usize,
947            depth: fidl::encoding::Depth,
948        ) -> fidl::Result<()> {
949            encoder.debug_check_bounds::<ControllerSuspendRequest>(offset);
950            // Zero out padding regions. There's no need to apply masks
951            // because the unmasked parts will be overwritten by fields.
952            unsafe {
953                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
954                (ptr as *mut u64).write_unaligned(0);
955            }
956            // Write the fields.
957            self.0.encode(encoder, offset + 0, depth)?;
958            self.1.encode(encoder, offset + 8, depth)?;
959            Ok(())
960        }
961    }
962
963    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
964        for ControllerSuspendRequest
965    {
966        #[inline(always)]
967        fn new_empty() -> Self {
968            Self {
969                peer_id: fidl::new_empty!(
970                    fidl::encoding::Boxed<fidl_fuchsia_bluetooth::PeerId>,
971                    fidl::encoding::DefaultFuchsiaResourceDialect
972                ),
973                token: fidl::new_empty!(
974                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<StreamSuspenderMarker>>,
975                    fidl::encoding::DefaultFuchsiaResourceDialect
976                ),
977            }
978        }
979
980        #[inline]
981        unsafe fn decode(
982            &mut self,
983            decoder: &mut fidl::encoding::Decoder<
984                '_,
985                fidl::encoding::DefaultFuchsiaResourceDialect,
986            >,
987            offset: usize,
988            _depth: fidl::encoding::Depth,
989        ) -> fidl::Result<()> {
990            decoder.debug_check_bounds::<Self>(offset);
991            // Verify that padding bytes are zero.
992            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(8) };
993            let padval = unsafe { (ptr as *const u64).read_unaligned() };
994            let mask = 0xffffffff00000000u64;
995            let maskedval = padval & mask;
996            if maskedval != 0 {
997                return Err(fidl::Error::NonZeroPadding {
998                    padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
999                });
1000            }
1001            fidl::decode!(
1002                fidl::encoding::Boxed<fidl_fuchsia_bluetooth::PeerId>,
1003                fidl::encoding::DefaultFuchsiaResourceDialect,
1004                &mut self.peer_id,
1005                decoder,
1006                offset + 0,
1007                _depth
1008            )?;
1009            fidl::decode!(
1010                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<StreamSuspenderMarker>>,
1011                fidl::encoding::DefaultFuchsiaResourceDialect,
1012                &mut self.token,
1013                decoder,
1014                offset + 8,
1015                _depth
1016            )?;
1017            Ok(())
1018        }
1019    }
1020}