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