Skip to main content

fidl_fuchsia_nodegroup_test/
fidl_fuchsia_nodegroup_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_nodegroup_test_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 GetNumberResponseFut: std::future::Future<Output = Result<u32, fidl::Error>> + Send;
28    fn r#get_number(&self) -> Self::GetNumberResponseFut;
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        Self { client: fidl::client::sync::Client::new(channel) }
58    }
59
60    pub fn into_channel(self) -> fidl::Channel {
61        self.client.into_channel()
62    }
63
64    /// Waits until an event arrives and returns it. It is safe for other
65    /// threads to make concurrent requests while waiting for an event.
66    pub fn wait_for_event(
67        &self,
68        deadline: zx::MonotonicInstant,
69    ) -> Result<DeviceEvent, fidl::Error> {
70        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
71    }
72
73    pub fn r#get_number(&self, ___deadline: zx::MonotonicInstant) -> Result<u32, fidl::Error> {
74        let _response = self
75            .client
76            .send_query::<fidl::encoding::EmptyPayload, DeviceGetNumberResponse, DeviceMarker>(
77                (),
78                0x6af95f9d3bd37367,
79                fidl::encoding::DynamicFlags::empty(),
80                ___deadline,
81            )?;
82        Ok(_response.number)
83    }
84}
85
86#[cfg(target_os = "fuchsia")]
87impl From<DeviceSynchronousProxy> for zx::NullableHandle {
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.nodegroup.test/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#get_number(
147        &self,
148    ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
149        DeviceProxyInterface::r#get_number(self)
150    }
151}
152
153impl DeviceProxyInterface for DeviceProxy {
154    type GetNumberResponseFut =
155        fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
156    fn r#get_number(&self) -> Self::GetNumberResponseFut {
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                DeviceGetNumberResponse,
162                fidl::encoding::DefaultFuchsiaResourceDialect,
163                0x6af95f9d3bd37367,
164            >(_buf?)?;
165            Ok(_response.number)
166        }
167        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
168            (),
169            0x6af95f9d3bd37367,
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.nodegroup.test/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                    0x6af95f9d3bd37367 => {
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::GetNumber {
310                            responder: DeviceGetNumberResponder {
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    GetNumber { responder: DeviceGetNumberResponder },
330}
331
332impl DeviceRequest {
333    #[allow(irrefutable_let_patterns)]
334    pub fn into_get_number(self) -> Option<(DeviceGetNumberResponder)> {
335        if let DeviceRequest::GetNumber { 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::GetNumber { .. } => "get_number",
342        }
343    }
344}
345
346#[derive(Debug, Clone)]
347pub struct DeviceControlHandle {
348    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
349}
350
351impl DeviceControlHandle {
352    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
353        self.inner.shutdown_with_epitaph(status.into())
354    }
355}
356
357impl fidl::endpoints::ControlHandle for DeviceControlHandle {
358    fn shutdown(&self) {
359        self.inner.shutdown()
360    }
361
362    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
363        self.inner.shutdown_with_epitaph(status)
364    }
365
366    fn is_closed(&self) -> bool {
367        self.inner.channel().is_closed()
368    }
369    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
370        self.inner.channel().on_closed()
371    }
372
373    #[cfg(target_os = "fuchsia")]
374    fn signal_peer(
375        &self,
376        clear_mask: zx::Signals,
377        set_mask: zx::Signals,
378    ) -> Result<(), zx_status::Status> {
379        use fidl::Peered;
380        self.inner.channel().signal_peer(clear_mask, set_mask)
381    }
382}
383
384impl DeviceControlHandle {}
385
386#[must_use = "FIDL methods require a response to be sent"]
387#[derive(Debug)]
388pub struct DeviceGetNumberResponder {
389    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
390    tx_id: u32,
391}
392
393/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
394/// if the responder is dropped without sending a response, so that the client
395/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
396impl std::ops::Drop for DeviceGetNumberResponder {
397    fn drop(&mut self) {
398        self.control_handle.shutdown();
399        // Safety: drops once, never accessed again
400        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
401    }
402}
403
404impl fidl::endpoints::Responder for DeviceGetNumberResponder {
405    type ControlHandle = DeviceControlHandle;
406
407    fn control_handle(&self) -> &DeviceControlHandle {
408        &self.control_handle
409    }
410
411    fn drop_without_shutdown(mut self) {
412        // Safety: drops once, never accessed again due to mem::forget
413        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
414        // Prevent Drop from running (which would shut down the channel)
415        std::mem::forget(self);
416    }
417}
418
419impl DeviceGetNumberResponder {
420    /// Sends a response to the FIDL transaction.
421    ///
422    /// Sets the channel to shutdown if an error occurs.
423    pub fn send(self, mut number: u32) -> Result<(), fidl::Error> {
424        let _result = self.send_raw(number);
425        if _result.is_err() {
426            self.control_handle.shutdown();
427        }
428        self.drop_without_shutdown();
429        _result
430    }
431
432    /// Similar to "send" but does not shutdown the channel if an error occurs.
433    pub fn send_no_shutdown_on_err(self, mut number: u32) -> Result<(), fidl::Error> {
434        let _result = self.send_raw(number);
435        self.drop_without_shutdown();
436        _result
437    }
438
439    fn send_raw(&self, mut number: u32) -> Result<(), fidl::Error> {
440        self.control_handle.inner.send::<DeviceGetNumberResponse>(
441            (number,),
442            self.tx_id,
443            0x6af95f9d3bd37367,
444            fidl::encoding::DynamicFlags::empty(),
445        )
446    }
447}
448
449#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
450pub struct WaiterMarker;
451
452impl fidl::endpoints::ProtocolMarker for WaiterMarker {
453    type Proxy = WaiterProxy;
454    type RequestStream = WaiterRequestStream;
455    #[cfg(target_os = "fuchsia")]
456    type SynchronousProxy = WaiterSynchronousProxy;
457
458    const DEBUG_NAME: &'static str = "fuchsia.nodegroup.test.Waiter";
459}
460impl fidl::endpoints::DiscoverableProtocolMarker for WaiterMarker {}
461
462pub trait WaiterProxyInterface: Send + Sync {
463    fn r#ack(&self, status: i32) -> Result<(), fidl::Error>;
464}
465#[derive(Debug)]
466#[cfg(target_os = "fuchsia")]
467pub struct WaiterSynchronousProxy {
468    client: fidl::client::sync::Client,
469}
470
471#[cfg(target_os = "fuchsia")]
472impl fidl::endpoints::SynchronousProxy for WaiterSynchronousProxy {
473    type Proxy = WaiterProxy;
474    type Protocol = WaiterMarker;
475
476    fn from_channel(inner: fidl::Channel) -> Self {
477        Self::new(inner)
478    }
479
480    fn into_channel(self) -> fidl::Channel {
481        self.client.into_channel()
482    }
483
484    fn as_channel(&self) -> &fidl::Channel {
485        self.client.as_channel()
486    }
487}
488
489#[cfg(target_os = "fuchsia")]
490impl WaiterSynchronousProxy {
491    pub fn new(channel: fidl::Channel) -> Self {
492        Self { client: fidl::client::sync::Client::new(channel) }
493    }
494
495    pub fn into_channel(self) -> fidl::Channel {
496        self.client.into_channel()
497    }
498
499    /// Waits until an event arrives and returns it. It is safe for other
500    /// threads to make concurrent requests while waiting for an event.
501    pub fn wait_for_event(
502        &self,
503        deadline: zx::MonotonicInstant,
504    ) -> Result<WaiterEvent, fidl::Error> {
505        WaiterEvent::decode(self.client.wait_for_event::<WaiterMarker>(deadline)?)
506    }
507
508    pub fn r#ack(&self, mut status: i32) -> Result<(), fidl::Error> {
509        self.client.send::<WaiterAckRequest>(
510            (status,),
511            0x13b7e3e83c507878,
512            fidl::encoding::DynamicFlags::empty(),
513        )
514    }
515}
516
517#[cfg(target_os = "fuchsia")]
518impl From<WaiterSynchronousProxy> for zx::NullableHandle {
519    fn from(value: WaiterSynchronousProxy) -> Self {
520        value.into_channel().into()
521    }
522}
523
524#[cfg(target_os = "fuchsia")]
525impl From<fidl::Channel> for WaiterSynchronousProxy {
526    fn from(value: fidl::Channel) -> Self {
527        Self::new(value)
528    }
529}
530
531#[cfg(target_os = "fuchsia")]
532impl fidl::endpoints::FromClient for WaiterSynchronousProxy {
533    type Protocol = WaiterMarker;
534
535    fn from_client(value: fidl::endpoints::ClientEnd<WaiterMarker>) -> Self {
536        Self::new(value.into_channel())
537    }
538}
539
540#[derive(Debug, Clone)]
541pub struct WaiterProxy {
542    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
543}
544
545impl fidl::endpoints::Proxy for WaiterProxy {
546    type Protocol = WaiterMarker;
547
548    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
549        Self::new(inner)
550    }
551
552    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
553        self.client.into_channel().map_err(|client| Self { client })
554    }
555
556    fn as_channel(&self) -> &::fidl::AsyncChannel {
557        self.client.as_channel()
558    }
559}
560
561impl WaiterProxy {
562    /// Create a new Proxy for fuchsia.nodegroup.test/Waiter.
563    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
564        let protocol_name = <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
565        Self { client: fidl::client::Client::new(channel, protocol_name) }
566    }
567
568    /// Get a Stream of events from the remote end of the protocol.
569    ///
570    /// # Panics
571    ///
572    /// Panics if the event stream was already taken.
573    pub fn take_event_stream(&self) -> WaiterEventStream {
574        WaiterEventStream { event_receiver: self.client.take_event_receiver() }
575    }
576
577    pub fn r#ack(&self, mut status: i32) -> Result<(), fidl::Error> {
578        WaiterProxyInterface::r#ack(self, status)
579    }
580}
581
582impl WaiterProxyInterface for WaiterProxy {
583    fn r#ack(&self, mut status: i32) -> Result<(), fidl::Error> {
584        self.client.send::<WaiterAckRequest>(
585            (status,),
586            0x13b7e3e83c507878,
587            fidl::encoding::DynamicFlags::empty(),
588        )
589    }
590}
591
592pub struct WaiterEventStream {
593    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
594}
595
596impl std::marker::Unpin for WaiterEventStream {}
597
598impl futures::stream::FusedStream for WaiterEventStream {
599    fn is_terminated(&self) -> bool {
600        self.event_receiver.is_terminated()
601    }
602}
603
604impl futures::Stream for WaiterEventStream {
605    type Item = Result<WaiterEvent, fidl::Error>;
606
607    fn poll_next(
608        mut self: std::pin::Pin<&mut Self>,
609        cx: &mut std::task::Context<'_>,
610    ) -> std::task::Poll<Option<Self::Item>> {
611        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
612            &mut self.event_receiver,
613            cx
614        )?) {
615            Some(buf) => std::task::Poll::Ready(Some(WaiterEvent::decode(buf))),
616            None => std::task::Poll::Ready(None),
617        }
618    }
619}
620
621#[derive(Debug)]
622pub enum WaiterEvent {}
623
624impl WaiterEvent {
625    /// Decodes a message buffer as a [`WaiterEvent`].
626    fn decode(
627        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
628    ) -> Result<WaiterEvent, fidl::Error> {
629        let (bytes, _handles) = buf.split_mut();
630        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
631        debug_assert_eq!(tx_header.tx_id, 0);
632        match tx_header.ordinal {
633            _ => Err(fidl::Error::UnknownOrdinal {
634                ordinal: tx_header.ordinal,
635                protocol_name: <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
636            }),
637        }
638    }
639}
640
641/// A Stream of incoming requests for fuchsia.nodegroup.test/Waiter.
642pub struct WaiterRequestStream {
643    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
644    is_terminated: bool,
645}
646
647impl std::marker::Unpin for WaiterRequestStream {}
648
649impl futures::stream::FusedStream for WaiterRequestStream {
650    fn is_terminated(&self) -> bool {
651        self.is_terminated
652    }
653}
654
655impl fidl::endpoints::RequestStream for WaiterRequestStream {
656    type Protocol = WaiterMarker;
657    type ControlHandle = WaiterControlHandle;
658
659    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
660        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
661    }
662
663    fn control_handle(&self) -> Self::ControlHandle {
664        WaiterControlHandle { inner: self.inner.clone() }
665    }
666
667    fn into_inner(
668        self,
669    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
670    {
671        (self.inner, self.is_terminated)
672    }
673
674    fn from_inner(
675        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
676        is_terminated: bool,
677    ) -> Self {
678        Self { inner, is_terminated }
679    }
680}
681
682impl futures::Stream for WaiterRequestStream {
683    type Item = Result<WaiterRequest, fidl::Error>;
684
685    fn poll_next(
686        mut self: std::pin::Pin<&mut Self>,
687        cx: &mut std::task::Context<'_>,
688    ) -> std::task::Poll<Option<Self::Item>> {
689        let this = &mut *self;
690        if this.inner.check_shutdown(cx) {
691            this.is_terminated = true;
692            return std::task::Poll::Ready(None);
693        }
694        if this.is_terminated {
695            panic!("polled WaiterRequestStream after completion");
696        }
697        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
698            |bytes, handles| {
699                match this.inner.channel().read_etc(cx, bytes, handles) {
700                    std::task::Poll::Ready(Ok(())) => {}
701                    std::task::Poll::Pending => return std::task::Poll::Pending,
702                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
703                        this.is_terminated = true;
704                        return std::task::Poll::Ready(None);
705                    }
706                    std::task::Poll::Ready(Err(e)) => {
707                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
708                            e.into(),
709                        ))));
710                    }
711                }
712
713                // A message has been received from the channel
714                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
715
716                std::task::Poll::Ready(Some(match header.ordinal {
717                    0x13b7e3e83c507878 => {
718                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
719                        let mut req = fidl::new_empty!(
720                            WaiterAckRequest,
721                            fidl::encoding::DefaultFuchsiaResourceDialect
722                        );
723                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<WaiterAckRequest>(&header, _body_bytes, handles, &mut req)?;
724                        let control_handle = WaiterControlHandle { inner: this.inner.clone() };
725                        Ok(WaiterRequest::Ack { status: req.status, control_handle })
726                    }
727                    _ => Err(fidl::Error::UnknownOrdinal {
728                        ordinal: header.ordinal,
729                        protocol_name:
730                            <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
731                    }),
732                }))
733            },
734        )
735    }
736}
737
738#[derive(Debug)]
739pub enum WaiterRequest {
740    Ack { status: i32, control_handle: WaiterControlHandle },
741}
742
743impl WaiterRequest {
744    #[allow(irrefutable_let_patterns)]
745    pub fn into_ack(self) -> Option<(i32, WaiterControlHandle)> {
746        if let WaiterRequest::Ack { status, control_handle } = self {
747            Some((status, control_handle))
748        } else {
749            None
750        }
751    }
752
753    /// Name of the method defined in FIDL
754    pub fn method_name(&self) -> &'static str {
755        match *self {
756            WaiterRequest::Ack { .. } => "ack",
757        }
758    }
759}
760
761#[derive(Debug, Clone)]
762pub struct WaiterControlHandle {
763    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
764}
765
766impl WaiterControlHandle {
767    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
768        self.inner.shutdown_with_epitaph(status.into())
769    }
770}
771
772impl fidl::endpoints::ControlHandle for WaiterControlHandle {
773    fn shutdown(&self) {
774        self.inner.shutdown()
775    }
776
777    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
778        self.inner.shutdown_with_epitaph(status)
779    }
780
781    fn is_closed(&self) -> bool {
782        self.inner.channel().is_closed()
783    }
784    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
785        self.inner.channel().on_closed()
786    }
787
788    #[cfg(target_os = "fuchsia")]
789    fn signal_peer(
790        &self,
791        clear_mask: zx::Signals,
792        set_mask: zx::Signals,
793    ) -> Result<(), zx_status::Status> {
794        use fidl::Peered;
795        self.inner.channel().signal_peer(clear_mask, set_mask)
796    }
797}
798
799impl WaiterControlHandle {}
800
801#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
802pub struct ServiceMarker;
803
804#[cfg(target_os = "fuchsia")]
805impl fidl::endpoints::ServiceMarker for ServiceMarker {
806    type Proxy = ServiceProxy;
807    type Request = ServiceRequest;
808    const SERVICE_NAME: &'static str = "fuchsia.nodegroup.test.Service";
809}
810
811/// A request for one of the member protocols of Service.
812///
813#[cfg(target_os = "fuchsia")]
814pub enum ServiceRequest {
815    Device(DeviceRequestStream),
816}
817
818#[cfg(target_os = "fuchsia")]
819impl fidl::endpoints::ServiceRequest for ServiceRequest {
820    type Service = ServiceMarker;
821
822    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
823        match name {
824            "device" => Self::Device(
825                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
826            ),
827            _ => panic!("no such member protocol name for service Service"),
828        }
829    }
830
831    fn member_names() -> &'static [&'static str] {
832        &["device"]
833    }
834}
835#[cfg(target_os = "fuchsia")]
836pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
837
838#[cfg(target_os = "fuchsia")]
839impl fidl::endpoints::ServiceProxy for ServiceProxy {
840    type Service = ServiceMarker;
841
842    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
843        Self(opener)
844    }
845}
846
847#[cfg(target_os = "fuchsia")]
848impl ServiceProxy {
849    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
850        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
851        self.connect_channel_to_device(server_end)?;
852        Ok(proxy)
853    }
854
855    /// Like `connect_to_device`, but returns a sync proxy.
856    /// See [`Self::connect_to_device`] for more details.
857    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
858        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
859        self.connect_channel_to_device(server_end)?;
860        Ok(proxy)
861    }
862
863    /// Like `connect_to_device`, but accepts a server end.
864    /// See [`Self::connect_to_device`] for more details.
865    pub fn connect_channel_to_device(
866        &self,
867        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
868    ) -> Result<(), fidl::Error> {
869        self.0.open_member("device", server_end.into_channel())
870    }
871
872    pub fn instance_name(&self) -> &str {
873        self.0.instance_name()
874    }
875}
876
877mod internal {
878    use super::*;
879}