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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
620        self.inner.shutdown_with_epitaph(status)
621    }
622
623    fn is_closed(&self) -> bool {
624        self.inner.channel().is_closed()
625    }
626    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
627        self.inner.channel().on_closed()
628    }
629
630    #[cfg(target_os = "fuchsia")]
631    fn signal_peer(
632        &self,
633        clear_mask: zx::Signals,
634        set_mask: zx::Signals,
635    ) -> Result<(), zx_status::Status> {
636        use fidl::Peered;
637        self.inner.channel().signal_peer(clear_mask, set_mask)
638    }
639}
640
641impl ChannelControlHandle {}
642
643#[must_use = "FIDL methods require a response to be sent"]
644#[derive(Debug)]
645pub struct ChannelSend_Responder {
646    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
647    tx_id: u32,
648}
649
650/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
651/// if the responder is dropped without sending a response, so that the client
652/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
653impl std::ops::Drop for ChannelSend_Responder {
654    fn drop(&mut self) {
655        self.control_handle.shutdown();
656        // Safety: drops once, never accessed again
657        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
658    }
659}
660
661impl fidl::endpoints::Responder for ChannelSend_Responder {
662    type ControlHandle = ChannelControlHandle;
663
664    fn control_handle(&self) -> &ChannelControlHandle {
665        &self.control_handle
666    }
667
668    fn drop_without_shutdown(mut self) {
669        // Safety: drops once, never accessed again due to mem::forget
670        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
671        // Prevent Drop from running (which would shut down the channel)
672        std::mem::forget(self);
673    }
674}
675
676impl ChannelSend_Responder {
677    /// Sends a response to the FIDL transaction.
678    ///
679    /// Sets the channel to shutdown if an error occurs.
680    pub fn send(self) -> Result<(), fidl::Error> {
681        let _result = self.send_raw();
682        if _result.is_err() {
683            self.control_handle.shutdown();
684        }
685        self.drop_without_shutdown();
686        _result
687    }
688
689    /// Similar to "send" but does not shutdown the channel if an error occurs.
690    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
691        let _result = self.send_raw();
692        self.drop_without_shutdown();
693        _result
694    }
695
696    fn send_raw(&self) -> Result<(), fidl::Error> {
697        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
698            fidl::encoding::Flexible::new(()),
699            self.tx_id,
700            0x6fc4419c2e763324,
701            fidl::encoding::DynamicFlags::FLEXIBLE,
702        )
703    }
704}
705
706#[must_use = "FIDL methods require a response to be sent"]
707#[derive(Debug)]
708pub struct ChannelReceiveResponder {
709    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
710    tx_id: u32,
711}
712
713/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
714/// if the responder is dropped without sending a response, so that the client
715/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
716impl std::ops::Drop for ChannelReceiveResponder {
717    fn drop(&mut self) {
718        self.control_handle.shutdown();
719        // Safety: drops once, never accessed again
720        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
721    }
722}
723
724impl fidl::endpoints::Responder for ChannelReceiveResponder {
725    type ControlHandle = ChannelControlHandle;
726
727    fn control_handle(&self) -> &ChannelControlHandle {
728        &self.control_handle
729    }
730
731    fn drop_without_shutdown(mut self) {
732        // Safety: drops once, never accessed again due to mem::forget
733        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
734        // Prevent Drop from running (which would shut down the channel)
735        std::mem::forget(self);
736    }
737}
738
739impl ChannelReceiveResponder {
740    /// Sends a response to the FIDL transaction.
741    ///
742    /// Sets the channel to shutdown if an error occurs.
743    pub fn send(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
744        let _result = self.send_raw(packets);
745        if _result.is_err() {
746            self.control_handle.shutdown();
747        }
748        self.drop_without_shutdown();
749        _result
750    }
751
752    /// Similar to "send" but does not shutdown the channel if an error occurs.
753    pub fn send_no_shutdown_on_err(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
754        let _result = self.send_raw(packets);
755        self.drop_without_shutdown();
756        _result
757    }
758
759    fn send_raw(&self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
760        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelReceiveResponse>>(
761            fidl::encoding::Flexible::new((packets,)),
762            self.tx_id,
763            0x3498d7bdb7cdbfd4,
764            fidl::encoding::DynamicFlags::FLEXIBLE,
765        )
766    }
767}
768
769#[must_use = "FIDL methods require a response to be sent"]
770#[derive(Debug)]
771pub struct ChannelWatchChannelParametersResponder {
772    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
773    tx_id: u32,
774}
775
776/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
777/// if the responder is dropped without sending a response, so that the client
778/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
779impl std::ops::Drop for ChannelWatchChannelParametersResponder {
780    fn drop(&mut self) {
781        self.control_handle.shutdown();
782        // Safety: drops once, never accessed again
783        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
784    }
785}
786
787impl fidl::endpoints::Responder for ChannelWatchChannelParametersResponder {
788    type ControlHandle = ChannelControlHandle;
789
790    fn control_handle(&self) -> &ChannelControlHandle {
791        &self.control_handle
792    }
793
794    fn drop_without_shutdown(mut self) {
795        // Safety: drops once, never accessed again due to mem::forget
796        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
797        // Prevent Drop from running (which would shut down the channel)
798        std::mem::forget(self);
799    }
800}
801
802impl ChannelWatchChannelParametersResponder {
803    /// Sends a response to the FIDL transaction.
804    ///
805    /// Sets the channel to shutdown if an error occurs.
806    pub fn send(self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
807        let _result = self.send_raw(payload);
808        if _result.is_err() {
809            self.control_handle.shutdown();
810        }
811        self.drop_without_shutdown();
812        _result
813    }
814
815    /// Similar to "send" but does not shutdown the channel if an error occurs.
816    pub fn send_no_shutdown_on_err(
817        self,
818        mut payload: &ChannelParameters,
819    ) -> Result<(), fidl::Error> {
820        let _result = self.send_raw(payload);
821        self.drop_without_shutdown();
822        _result
823    }
824
825    fn send_raw(&self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
826        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelParameters>>(
827            fidl::encoding::Flexible::new(payload),
828            self.tx_id,
829            0x5a0cec81d5076c12,
830            fidl::encoding::DynamicFlags::FLEXIBLE,
831        )
832    }
833}
834
835mod internal {
836    use super::*;
837}