fidl_fuchsia_bluetooth/
fidl_fuchsia_bluetooth.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__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ChannelMarker;
16
17impl fidl::endpoints::ProtocolMarker for ChannelMarker {
18    type Proxy = ChannelProxy;
19    type RequestStream = ChannelRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ChannelSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) Channel";
24}
25
26pub trait ChannelProxyInterface: Send + Sync {
27    type Send_ResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
28    fn r#send_(&self, packets: &[Packet]) -> Self::Send_ResponseFut;
29    type ReceiveResponseFut: std::future::Future<Output = Result<Vec<Packet>, fidl::Error>> + Send;
30    fn r#receive(&self) -> Self::ReceiveResponseFut;
31    type WatchChannelParametersResponseFut: std::future::Future<Output = Result<ChannelParameters, fidl::Error>>
32        + Send;
33    fn r#watch_channel_parameters(&self) -> Self::WatchChannelParametersResponseFut;
34}
35#[derive(Debug)]
36#[cfg(target_os = "fuchsia")]
37pub struct ChannelSynchronousProxy {
38    client: fidl::client::sync::Client,
39}
40
41#[cfg(target_os = "fuchsia")]
42impl fidl::endpoints::SynchronousProxy for ChannelSynchronousProxy {
43    type Proxy = ChannelProxy;
44    type Protocol = ChannelMarker;
45
46    fn from_channel(inner: fidl::Channel) -> Self {
47        Self::new(inner)
48    }
49
50    fn into_channel(self) -> fidl::Channel {
51        self.client.into_channel()
52    }
53
54    fn as_channel(&self) -> &fidl::Channel {
55        self.client.as_channel()
56    }
57}
58
59#[cfg(target_os = "fuchsia")]
60impl ChannelSynchronousProxy {
61    pub fn new(channel: fidl::Channel) -> Self {
62        let protocol_name = <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
63        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
64    }
65
66    pub fn into_channel(self) -> fidl::Channel {
67        self.client.into_channel()
68    }
69
70    /// Waits until an event arrives and returns it. It is safe for other
71    /// threads to make concurrent requests while waiting for an event.
72    pub fn wait_for_event(
73        &self,
74        deadline: zx::MonotonicInstant,
75    ) -> Result<ChannelEvent, fidl::Error> {
76        ChannelEvent::decode(self.client.wait_for_event(deadline)?)
77    }
78
79    /// Send multiple packets of data over the channel. Only one `Send`
80    /// may be pending at a time.
81    pub fn r#send_(
82        &self,
83        mut packets: &[Packet],
84        ___deadline: zx::MonotonicInstant,
85    ) -> Result<(), fidl::Error> {
86        let _response = self.client.send_query::<
87            ChannelSendRequest,
88            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
89        >(
90            (packets,),
91            0x6fc4419c2e763324,
92            fidl::encoding::DynamicFlags::FLEXIBLE,
93            ___deadline,
94        )?
95        .into_result::<ChannelMarker>("send_")?;
96        Ok(_response)
97    }
98
99    /// Hanging get that waits for inbound packets. Only one `Receive`
100    /// may be pending at a time.
101    pub fn r#receive(&self, ___deadline: zx::MonotonicInstant) -> Result<Vec<Packet>, fidl::Error> {
102        let _response = self.client.send_query::<
103            fidl::encoding::EmptyPayload,
104            fidl::encoding::FlexibleType<ChannelReceiveResponse>,
105        >(
106            (),
107            0x3498d7bdb7cdbfd4,
108            fidl::encoding::DynamicFlags::FLEXIBLE,
109            ___deadline,
110        )?
111        .into_result::<ChannelMarker>("receive")?;
112        Ok(_response.packets)
113    }
114
115    /// For RFCOMM channels, this will not return and calls will hang
116    /// indefinitely.
117    ///
118    /// For BR/EDR L2CAP connection-oriented channels this will currently not
119    /// return and calls will hang indefinitely. The initial channel parameters
120    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
121    ///
122    /// For LE L2CAP connection-oriented channels, the first call will
123    /// immediately return the parameters of the remote side of the channel.
124    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
125    /// which point it will return the new parameters, including those that have
126    /// not changed.
127    pub fn r#watch_channel_parameters(
128        &self,
129        ___deadline: zx::MonotonicInstant,
130    ) -> Result<ChannelParameters, fidl::Error> {
131        let _response = self.client.send_query::<
132            fidl::encoding::EmptyPayload,
133            fidl::encoding::FlexibleType<ChannelParameters>,
134        >(
135            (),
136            0x5a0cec81d5076c12,
137            fidl::encoding::DynamicFlags::FLEXIBLE,
138            ___deadline,
139        )?
140        .into_result::<ChannelMarker>("watch_channel_parameters")?;
141        Ok(_response)
142    }
143}
144
145#[cfg(target_os = "fuchsia")]
146impl From<ChannelSynchronousProxy> for zx::NullableHandle {
147    fn from(value: ChannelSynchronousProxy) -> Self {
148        value.into_channel().into()
149    }
150}
151
152#[cfg(target_os = "fuchsia")]
153impl From<fidl::Channel> for ChannelSynchronousProxy {
154    fn from(value: fidl::Channel) -> Self {
155        Self::new(value)
156    }
157}
158
159#[cfg(target_os = "fuchsia")]
160impl fidl::endpoints::FromClient for ChannelSynchronousProxy {
161    type Protocol = ChannelMarker;
162
163    fn from_client(value: fidl::endpoints::ClientEnd<ChannelMarker>) -> Self {
164        Self::new(value.into_channel())
165    }
166}
167
168#[derive(Debug, Clone)]
169pub struct ChannelProxy {
170    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
171}
172
173impl fidl::endpoints::Proxy for ChannelProxy {
174    type Protocol = ChannelMarker;
175
176    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
177        Self::new(inner)
178    }
179
180    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
181        self.client.into_channel().map_err(|client| Self { client })
182    }
183
184    fn as_channel(&self) -> &::fidl::AsyncChannel {
185        self.client.as_channel()
186    }
187}
188
189impl ChannelProxy {
190    /// Create a new Proxy for fuchsia.bluetooth/Channel.
191    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
192        let protocol_name = <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
193        Self { client: fidl::client::Client::new(channel, protocol_name) }
194    }
195
196    /// Get a Stream of events from the remote end of the protocol.
197    ///
198    /// # Panics
199    ///
200    /// Panics if the event stream was already taken.
201    pub fn take_event_stream(&self) -> ChannelEventStream {
202        ChannelEventStream { event_receiver: self.client.take_event_receiver() }
203    }
204
205    /// Send multiple packets of data over the channel. Only one `Send`
206    /// may be pending at a time.
207    pub fn r#send_(
208        &self,
209        mut packets: &[Packet],
210    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
211        ChannelProxyInterface::r#send_(self, packets)
212    }
213
214    /// Hanging get that waits for inbound packets. Only one `Receive`
215    /// may be pending at a time.
216    pub fn r#receive(
217        &self,
218    ) -> fidl::client::QueryResponseFut<Vec<Packet>, fidl::encoding::DefaultFuchsiaResourceDialect>
219    {
220        ChannelProxyInterface::r#receive(self)
221    }
222
223    /// For RFCOMM channels, this will not return and calls will hang
224    /// indefinitely.
225    ///
226    /// For BR/EDR L2CAP connection-oriented channels this will currently not
227    /// return and calls will hang indefinitely. The initial channel parameters
228    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
229    ///
230    /// For LE L2CAP connection-oriented channels, the first call will
231    /// immediately return the parameters of the remote side of the channel.
232    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
233    /// which point it will return the new parameters, including those that have
234    /// not changed.
235    pub fn r#watch_channel_parameters(
236        &self,
237    ) -> fidl::client::QueryResponseFut<
238        ChannelParameters,
239        fidl::encoding::DefaultFuchsiaResourceDialect,
240    > {
241        ChannelProxyInterface::r#watch_channel_parameters(self)
242    }
243}
244
245impl ChannelProxyInterface for ChannelProxy {
246    type Send_ResponseFut =
247        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
248    fn r#send_(&self, mut packets: &[Packet]) -> Self::Send_ResponseFut {
249        fn _decode(
250            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
251        ) -> Result<(), fidl::Error> {
252            let _response = fidl::client::decode_transaction_body::<
253                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
254                fidl::encoding::DefaultFuchsiaResourceDialect,
255                0x6fc4419c2e763324,
256            >(_buf?)?
257            .into_result::<ChannelMarker>("send_")?;
258            Ok(_response)
259        }
260        self.client.send_query_and_decode::<ChannelSendRequest, ()>(
261            (packets,),
262            0x6fc4419c2e763324,
263            fidl::encoding::DynamicFlags::FLEXIBLE,
264            _decode,
265        )
266    }
267
268    type ReceiveResponseFut =
269        fidl::client::QueryResponseFut<Vec<Packet>, fidl::encoding::DefaultFuchsiaResourceDialect>;
270    fn r#receive(&self) -> Self::ReceiveResponseFut {
271        fn _decode(
272            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
273        ) -> Result<Vec<Packet>, fidl::Error> {
274            let _response = fidl::client::decode_transaction_body::<
275                fidl::encoding::FlexibleType<ChannelReceiveResponse>,
276                fidl::encoding::DefaultFuchsiaResourceDialect,
277                0x3498d7bdb7cdbfd4,
278            >(_buf?)?
279            .into_result::<ChannelMarker>("receive")?;
280            Ok(_response.packets)
281        }
282        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<Packet>>(
283            (),
284            0x3498d7bdb7cdbfd4,
285            fidl::encoding::DynamicFlags::FLEXIBLE,
286            _decode,
287        )
288    }
289
290    type WatchChannelParametersResponseFut = fidl::client::QueryResponseFut<
291        ChannelParameters,
292        fidl::encoding::DefaultFuchsiaResourceDialect,
293    >;
294    fn r#watch_channel_parameters(&self) -> Self::WatchChannelParametersResponseFut {
295        fn _decode(
296            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
297        ) -> Result<ChannelParameters, fidl::Error> {
298            let _response = fidl::client::decode_transaction_body::<
299                fidl::encoding::FlexibleType<ChannelParameters>,
300                fidl::encoding::DefaultFuchsiaResourceDialect,
301                0x5a0cec81d5076c12,
302            >(_buf?)?
303            .into_result::<ChannelMarker>("watch_channel_parameters")?;
304            Ok(_response)
305        }
306        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ChannelParameters>(
307            (),
308            0x5a0cec81d5076c12,
309            fidl::encoding::DynamicFlags::FLEXIBLE,
310            _decode,
311        )
312    }
313}
314
315pub struct ChannelEventStream {
316    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
317}
318
319impl std::marker::Unpin for ChannelEventStream {}
320
321impl futures::stream::FusedStream for ChannelEventStream {
322    fn is_terminated(&self) -> bool {
323        self.event_receiver.is_terminated()
324    }
325}
326
327impl futures::Stream for ChannelEventStream {
328    type Item = Result<ChannelEvent, fidl::Error>;
329
330    fn poll_next(
331        mut self: std::pin::Pin<&mut Self>,
332        cx: &mut std::task::Context<'_>,
333    ) -> std::task::Poll<Option<Self::Item>> {
334        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
335            &mut self.event_receiver,
336            cx
337        )?) {
338            Some(buf) => std::task::Poll::Ready(Some(ChannelEvent::decode(buf))),
339            None => std::task::Poll::Ready(None),
340        }
341    }
342}
343
344#[derive(Debug)]
345pub enum ChannelEvent {
346    #[non_exhaustive]
347    _UnknownEvent {
348        /// Ordinal of the event that was sent.
349        ordinal: u64,
350    },
351}
352
353impl ChannelEvent {
354    /// Decodes a message buffer as a [`ChannelEvent`].
355    fn decode(
356        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
357    ) -> Result<ChannelEvent, fidl::Error> {
358        let (bytes, _handles) = buf.split_mut();
359        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
360        debug_assert_eq!(tx_header.tx_id, 0);
361        match tx_header.ordinal {
362            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
363                Ok(ChannelEvent::_UnknownEvent { ordinal: tx_header.ordinal })
364            }
365            _ => Err(fidl::Error::UnknownOrdinal {
366                ordinal: tx_header.ordinal,
367                protocol_name: <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
368            }),
369        }
370    }
371}
372
373/// A Stream of incoming requests for fuchsia.bluetooth/Channel.
374pub struct ChannelRequestStream {
375    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
376    is_terminated: bool,
377}
378
379impl std::marker::Unpin for ChannelRequestStream {}
380
381impl futures::stream::FusedStream for ChannelRequestStream {
382    fn is_terminated(&self) -> bool {
383        self.is_terminated
384    }
385}
386
387impl fidl::endpoints::RequestStream for ChannelRequestStream {
388    type Protocol = ChannelMarker;
389    type ControlHandle = ChannelControlHandle;
390
391    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
392        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
393    }
394
395    fn control_handle(&self) -> Self::ControlHandle {
396        ChannelControlHandle { inner: self.inner.clone() }
397    }
398
399    fn into_inner(
400        self,
401    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
402    {
403        (self.inner, self.is_terminated)
404    }
405
406    fn from_inner(
407        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
408        is_terminated: bool,
409    ) -> Self {
410        Self { inner, is_terminated }
411    }
412}
413
414impl futures::Stream for ChannelRequestStream {
415    type Item = Result<ChannelRequest, fidl::Error>;
416
417    fn poll_next(
418        mut self: std::pin::Pin<&mut Self>,
419        cx: &mut std::task::Context<'_>,
420    ) -> std::task::Poll<Option<Self::Item>> {
421        let this = &mut *self;
422        if this.inner.check_shutdown(cx) {
423            this.is_terminated = true;
424            return std::task::Poll::Ready(None);
425        }
426        if this.is_terminated {
427            panic!("polled ChannelRequestStream after completion");
428        }
429        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
430            |bytes, handles| {
431                match this.inner.channel().read_etc(cx, bytes, handles) {
432                    std::task::Poll::Ready(Ok(())) => {}
433                    std::task::Poll::Pending => return std::task::Poll::Pending,
434                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
435                        this.is_terminated = true;
436                        return std::task::Poll::Ready(None);
437                    }
438                    std::task::Poll::Ready(Err(e)) => {
439                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
440                            e.into(),
441                        ))));
442                    }
443                }
444
445                // A message has been received from the channel
446                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
447
448                std::task::Poll::Ready(Some(match header.ordinal {
449                    0x6fc4419c2e763324 => {
450                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
451                        let mut req = fidl::new_empty!(
452                            ChannelSendRequest,
453                            fidl::encoding::DefaultFuchsiaResourceDialect
454                        );
455                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelSendRequest>(&header, _body_bytes, handles, &mut req)?;
456                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
457                        Ok(ChannelRequest::Send_ {
458                            packets: req.packets,
459
460                            responder: ChannelSend_Responder {
461                                control_handle: std::mem::ManuallyDrop::new(control_handle),
462                                tx_id: header.tx_id,
463                            },
464                        })
465                    }
466                    0x3498d7bdb7cdbfd4 => {
467                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
468                        let mut req = fidl::new_empty!(
469                            fidl::encoding::EmptyPayload,
470                            fidl::encoding::DefaultFuchsiaResourceDialect
471                        );
472                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
473                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
474                        Ok(ChannelRequest::Receive {
475                            responder: ChannelReceiveResponder {
476                                control_handle: std::mem::ManuallyDrop::new(control_handle),
477                                tx_id: header.tx_id,
478                            },
479                        })
480                    }
481                    0x5a0cec81d5076c12 => {
482                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
483                        let mut req = fidl::new_empty!(
484                            fidl::encoding::EmptyPayload,
485                            fidl::encoding::DefaultFuchsiaResourceDialect
486                        );
487                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
488                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
489                        Ok(ChannelRequest::WatchChannelParameters {
490                            responder: ChannelWatchChannelParametersResponder {
491                                control_handle: std::mem::ManuallyDrop::new(control_handle),
492                                tx_id: header.tx_id,
493                            },
494                        })
495                    }
496                    _ if header.tx_id == 0
497                        && header
498                            .dynamic_flags()
499                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
500                    {
501                        Ok(ChannelRequest::_UnknownMethod {
502                            ordinal: header.ordinal,
503                            control_handle: ChannelControlHandle { inner: this.inner.clone() },
504                            method_type: fidl::MethodType::OneWay,
505                        })
506                    }
507                    _ if header
508                        .dynamic_flags()
509                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
510                    {
511                        this.inner.send_framework_err(
512                            fidl::encoding::FrameworkErr::UnknownMethod,
513                            header.tx_id,
514                            header.ordinal,
515                            header.dynamic_flags(),
516                            (bytes, handles),
517                        )?;
518                        Ok(ChannelRequest::_UnknownMethod {
519                            ordinal: header.ordinal,
520                            control_handle: ChannelControlHandle { inner: this.inner.clone() },
521                            method_type: fidl::MethodType::TwoWay,
522                        })
523                    }
524                    _ => Err(fidl::Error::UnknownOrdinal {
525                        ordinal: header.ordinal,
526                        protocol_name:
527                            <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
528                    }),
529                }))
530            },
531        )
532    }
533}
534
535/// A duplex channel for sending/recieving [`Packet`]s. This protocol also
536/// serves as a token to keeping the `Channel` open. Closing this protocol (and
537/// the associated `socket` for BR/EDR channels) will close the underlying
538/// channel.
539#[derive(Debug)]
540pub enum ChannelRequest {
541    /// Send multiple packets of data over the channel. Only one `Send`
542    /// may be pending at a time.
543    Send_ { packets: Vec<Packet>, responder: ChannelSend_Responder },
544    /// Hanging get that waits for inbound packets. Only one `Receive`
545    /// may be pending at a time.
546    Receive { responder: ChannelReceiveResponder },
547    /// For RFCOMM channels, this will not return and calls will hang
548    /// indefinitely.
549    ///
550    /// For BR/EDR L2CAP connection-oriented channels this will currently not
551    /// return and calls will hang indefinitely. The initial channel parameters
552    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
553    ///
554    /// For LE L2CAP connection-oriented channels, the first call will
555    /// immediately return the parameters of the remote side of the channel.
556    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
557    /// which point it will return the new parameters, including those that have
558    /// not changed.
559    WatchChannelParameters { responder: ChannelWatchChannelParametersResponder },
560    /// An interaction was received which does not match any known method.
561    #[non_exhaustive]
562    _UnknownMethod {
563        /// Ordinal of the method that was called.
564        ordinal: u64,
565        control_handle: ChannelControlHandle,
566        method_type: fidl::MethodType,
567    },
568}
569
570impl ChannelRequest {
571    #[allow(irrefutable_let_patterns)]
572    pub fn into_send_(self) -> Option<(Vec<Packet>, ChannelSend_Responder)> {
573        if let ChannelRequest::Send_ { packets, responder } = self {
574            Some((packets, responder))
575        } else {
576            None
577        }
578    }
579
580    #[allow(irrefutable_let_patterns)]
581    pub fn into_receive(self) -> Option<(ChannelReceiveResponder)> {
582        if let ChannelRequest::Receive { responder } = self { Some((responder)) } else { None }
583    }
584
585    #[allow(irrefutable_let_patterns)]
586    pub fn into_watch_channel_parameters(self) -> Option<(ChannelWatchChannelParametersResponder)> {
587        if let ChannelRequest::WatchChannelParameters { responder } = self {
588            Some((responder))
589        } else {
590            None
591        }
592    }
593
594    /// Name of the method defined in FIDL
595    pub fn method_name(&self) -> &'static str {
596        match *self {
597            ChannelRequest::Send_ { .. } => "send_",
598            ChannelRequest::Receive { .. } => "receive",
599            ChannelRequest::WatchChannelParameters { .. } => "watch_channel_parameters",
600            ChannelRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
601                "unknown one-way method"
602            }
603            ChannelRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
604                "unknown two-way method"
605            }
606        }
607    }
608}
609
610#[derive(Debug, Clone)]
611pub struct ChannelControlHandle {
612    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
613}
614
615impl fidl::endpoints::ControlHandle for ChannelControlHandle {
616    fn shutdown(&self) {
617        self.inner.shutdown()
618    }
619
620    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
621        self.inner.shutdown_with_epitaph(status)
622    }
623
624    fn is_closed(&self) -> bool {
625        self.inner.channel().is_closed()
626    }
627    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
628        self.inner.channel().on_closed()
629    }
630
631    #[cfg(target_os = "fuchsia")]
632    fn signal_peer(
633        &self,
634        clear_mask: zx::Signals,
635        set_mask: zx::Signals,
636    ) -> Result<(), zx_status::Status> {
637        use fidl::Peered;
638        self.inner.channel().signal_peer(clear_mask, set_mask)
639    }
640}
641
642impl ChannelControlHandle {}
643
644#[must_use = "FIDL methods require a response to be sent"]
645#[derive(Debug)]
646pub struct ChannelSend_Responder {
647    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
648    tx_id: u32,
649}
650
651/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
652/// if the responder is dropped without sending a response, so that the client
653/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
654impl std::ops::Drop for ChannelSend_Responder {
655    fn drop(&mut self) {
656        self.control_handle.shutdown();
657        // Safety: drops once, never accessed again
658        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
659    }
660}
661
662impl fidl::endpoints::Responder for ChannelSend_Responder {
663    type ControlHandle = ChannelControlHandle;
664
665    fn control_handle(&self) -> &ChannelControlHandle {
666        &self.control_handle
667    }
668
669    fn drop_without_shutdown(mut self) {
670        // Safety: drops once, never accessed again due to mem::forget
671        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
672        // Prevent Drop from running (which would shut down the channel)
673        std::mem::forget(self);
674    }
675}
676
677impl ChannelSend_Responder {
678    /// Sends a response to the FIDL transaction.
679    ///
680    /// Sets the channel to shutdown if an error occurs.
681    pub fn send(self) -> Result<(), fidl::Error> {
682        let _result = self.send_raw();
683        if _result.is_err() {
684            self.control_handle.shutdown();
685        }
686        self.drop_without_shutdown();
687        _result
688    }
689
690    /// Similar to "send" but does not shutdown the channel if an error occurs.
691    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
692        let _result = self.send_raw();
693        self.drop_without_shutdown();
694        _result
695    }
696
697    fn send_raw(&self) -> Result<(), fidl::Error> {
698        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
699            fidl::encoding::Flexible::new(()),
700            self.tx_id,
701            0x6fc4419c2e763324,
702            fidl::encoding::DynamicFlags::FLEXIBLE,
703        )
704    }
705}
706
707#[must_use = "FIDL methods require a response to be sent"]
708#[derive(Debug)]
709pub struct ChannelReceiveResponder {
710    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
711    tx_id: u32,
712}
713
714/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
715/// if the responder is dropped without sending a response, so that the client
716/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
717impl std::ops::Drop for ChannelReceiveResponder {
718    fn drop(&mut self) {
719        self.control_handle.shutdown();
720        // Safety: drops once, never accessed again
721        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
722    }
723}
724
725impl fidl::endpoints::Responder for ChannelReceiveResponder {
726    type ControlHandle = ChannelControlHandle;
727
728    fn control_handle(&self) -> &ChannelControlHandle {
729        &self.control_handle
730    }
731
732    fn drop_without_shutdown(mut self) {
733        // Safety: drops once, never accessed again due to mem::forget
734        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
735        // Prevent Drop from running (which would shut down the channel)
736        std::mem::forget(self);
737    }
738}
739
740impl ChannelReceiveResponder {
741    /// Sends a response to the FIDL transaction.
742    ///
743    /// Sets the channel to shutdown if an error occurs.
744    pub fn send(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
745        let _result = self.send_raw(packets);
746        if _result.is_err() {
747            self.control_handle.shutdown();
748        }
749        self.drop_without_shutdown();
750        _result
751    }
752
753    /// Similar to "send" but does not shutdown the channel if an error occurs.
754    pub fn send_no_shutdown_on_err(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
755        let _result = self.send_raw(packets);
756        self.drop_without_shutdown();
757        _result
758    }
759
760    fn send_raw(&self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
761        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelReceiveResponse>>(
762            fidl::encoding::Flexible::new((packets,)),
763            self.tx_id,
764            0x3498d7bdb7cdbfd4,
765            fidl::encoding::DynamicFlags::FLEXIBLE,
766        )
767    }
768}
769
770#[must_use = "FIDL methods require a response to be sent"]
771#[derive(Debug)]
772pub struct ChannelWatchChannelParametersResponder {
773    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
774    tx_id: u32,
775}
776
777/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
778/// if the responder is dropped without sending a response, so that the client
779/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
780impl std::ops::Drop for ChannelWatchChannelParametersResponder {
781    fn drop(&mut self) {
782        self.control_handle.shutdown();
783        // Safety: drops once, never accessed again
784        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
785    }
786}
787
788impl fidl::endpoints::Responder for ChannelWatchChannelParametersResponder {
789    type ControlHandle = ChannelControlHandle;
790
791    fn control_handle(&self) -> &ChannelControlHandle {
792        &self.control_handle
793    }
794
795    fn drop_without_shutdown(mut self) {
796        // Safety: drops once, never accessed again due to mem::forget
797        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
798        // Prevent Drop from running (which would shut down the channel)
799        std::mem::forget(self);
800    }
801}
802
803impl ChannelWatchChannelParametersResponder {
804    /// Sends a response to the FIDL transaction.
805    ///
806    /// Sets the channel to shutdown if an error occurs.
807    pub fn send(self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
808        let _result = self.send_raw(payload);
809        if _result.is_err() {
810            self.control_handle.shutdown();
811        }
812        self.drop_without_shutdown();
813        _result
814    }
815
816    /// Similar to "send" but does not shutdown the channel if an error occurs.
817    pub fn send_no_shutdown_on_err(
818        self,
819        mut payload: &ChannelParameters,
820    ) -> Result<(), fidl::Error> {
821        let _result = self.send_raw(payload);
822        self.drop_without_shutdown();
823        _result
824    }
825
826    fn send_raw(&self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
827        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelParameters>>(
828            fidl::encoding::Flexible::new(payload),
829            self.tx_id,
830            0x5a0cec81d5076c12,
831            fidl::encoding::DynamicFlags::FLEXIBLE,
832        )
833    }
834}
835
836mod internal {
837    use super::*;
838}