Skip to main content

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