fidl_fuchsia_diagnostics_test/
fidl_fuchsia_diagnostics_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_diagnostics_test_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DetectControllerEnterTestModeRequest {
16    pub test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for DetectControllerEnterTestModeRequest
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct DetectControllerMarker;
26
27impl fidl::endpoints::ProtocolMarker for DetectControllerMarker {
28    type Proxy = DetectControllerProxy;
29    type RequestStream = DetectControllerRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = DetectControllerSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "fuchsia.diagnostics.test.DetectController";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for DetectControllerMarker {}
36
37pub trait DetectControllerProxyInterface: Send + Sync {
38    type EnterTestModeResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
39    fn r#enter_test_mode(
40        &self,
41        test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
42    ) -> Self::EnterTestModeResponseFut;
43}
44#[derive(Debug)]
45#[cfg(target_os = "fuchsia")]
46pub struct DetectControllerSynchronousProxy {
47    client: fidl::client::sync::Client,
48}
49
50#[cfg(target_os = "fuchsia")]
51impl fidl::endpoints::SynchronousProxy for DetectControllerSynchronousProxy {
52    type Proxy = DetectControllerProxy;
53    type Protocol = DetectControllerMarker;
54
55    fn from_channel(inner: fidl::Channel) -> Self {
56        Self::new(inner)
57    }
58
59    fn into_channel(self) -> fidl::Channel {
60        self.client.into_channel()
61    }
62
63    fn as_channel(&self) -> &fidl::Channel {
64        self.client.as_channel()
65    }
66}
67
68#[cfg(target_os = "fuchsia")]
69impl DetectControllerSynchronousProxy {
70    pub fn new(channel: fidl::Channel) -> Self {
71        let protocol_name = <DetectControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
72        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
73    }
74
75    pub fn into_channel(self) -> fidl::Channel {
76        self.client.into_channel()
77    }
78
79    /// Waits until an event arrives and returns it. It is safe for other
80    /// threads to make concurrent requests while waiting for an event.
81    pub fn wait_for_event(
82        &self,
83        deadline: zx::MonotonicInstant,
84    ) -> Result<DetectControllerEvent, fidl::Error> {
85        DetectControllerEvent::decode(self.client.wait_for_event(deadline)?)
86    }
87
88    /// Enter the test mode. Return when the program is ready and idle.
89    /// If already in test mode, it will not return until the first test mode is
90    /// exited by closing its test_controller client_end.
91    pub fn r#enter_test_mode(
92        &self,
93        mut test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
94        ___deadline: zx::MonotonicInstant,
95    ) -> Result<(), fidl::Error> {
96        let _response = self
97            .client
98            .send_query::<DetectControllerEnterTestModeRequest, fidl::encoding::EmptyPayload>(
99                (test_controller,),
100                0x6f4bb79cfba4f84,
101                fidl::encoding::DynamicFlags::empty(),
102                ___deadline,
103            )?;
104        Ok(_response)
105    }
106}
107
108#[derive(Debug, Clone)]
109pub struct DetectControllerProxy {
110    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
111}
112
113impl fidl::endpoints::Proxy for DetectControllerProxy {
114    type Protocol = DetectControllerMarker;
115
116    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
117        Self::new(inner)
118    }
119
120    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
121        self.client.into_channel().map_err(|client| Self { client })
122    }
123
124    fn as_channel(&self) -> &::fidl::AsyncChannel {
125        self.client.as_channel()
126    }
127}
128
129impl DetectControllerProxy {
130    /// Create a new Proxy for fuchsia.diagnostics.test/DetectController.
131    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
132        let protocol_name = <DetectControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
133        Self { client: fidl::client::Client::new(channel, protocol_name) }
134    }
135
136    /// Get a Stream of events from the remote end of the protocol.
137    ///
138    /// # Panics
139    ///
140    /// Panics if the event stream was already taken.
141    pub fn take_event_stream(&self) -> DetectControllerEventStream {
142        DetectControllerEventStream { event_receiver: self.client.take_event_receiver() }
143    }
144
145    /// Enter the test mode. Return when the program is ready and idle.
146    /// If already in test mode, it will not return until the first test mode is
147    /// exited by closing its test_controller client_end.
148    pub fn r#enter_test_mode(
149        &self,
150        mut test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
151    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
152        DetectControllerProxyInterface::r#enter_test_mode(self, test_controller)
153    }
154}
155
156impl DetectControllerProxyInterface for DetectControllerProxy {
157    type EnterTestModeResponseFut =
158        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
159    fn r#enter_test_mode(
160        &self,
161        mut test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
162    ) -> Self::EnterTestModeResponseFut {
163        fn _decode(
164            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
165        ) -> Result<(), fidl::Error> {
166            let _response = fidl::client::decode_transaction_body::<
167                fidl::encoding::EmptyPayload,
168                fidl::encoding::DefaultFuchsiaResourceDialect,
169                0x6f4bb79cfba4f84,
170            >(_buf?)?;
171            Ok(_response)
172        }
173        self.client.send_query_and_decode::<DetectControllerEnterTestModeRequest, ()>(
174            (test_controller,),
175            0x6f4bb79cfba4f84,
176            fidl::encoding::DynamicFlags::empty(),
177            _decode,
178        )
179    }
180}
181
182pub struct DetectControllerEventStream {
183    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
184}
185
186impl std::marker::Unpin for DetectControllerEventStream {}
187
188impl futures::stream::FusedStream for DetectControllerEventStream {
189    fn is_terminated(&self) -> bool {
190        self.event_receiver.is_terminated()
191    }
192}
193
194impl futures::Stream for DetectControllerEventStream {
195    type Item = Result<DetectControllerEvent, fidl::Error>;
196
197    fn poll_next(
198        mut self: std::pin::Pin<&mut Self>,
199        cx: &mut std::task::Context<'_>,
200    ) -> std::task::Poll<Option<Self::Item>> {
201        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
202            &mut self.event_receiver,
203            cx
204        )?) {
205            Some(buf) => std::task::Poll::Ready(Some(DetectControllerEvent::decode(buf))),
206            None => std::task::Poll::Ready(None),
207        }
208    }
209}
210
211#[derive(Debug)]
212pub enum DetectControllerEvent {}
213
214impl DetectControllerEvent {
215    /// Decodes a message buffer as a [`DetectControllerEvent`].
216    fn decode(
217        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
218    ) -> Result<DetectControllerEvent, fidl::Error> {
219        let (bytes, _handles) = buf.split_mut();
220        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
221        debug_assert_eq!(tx_header.tx_id, 0);
222        match tx_header.ordinal {
223            _ => Err(fidl::Error::UnknownOrdinal {
224                ordinal: tx_header.ordinal,
225                protocol_name:
226                    <DetectControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
227            }),
228        }
229    }
230}
231
232/// A Stream of incoming requests for fuchsia.diagnostics.test/DetectController.
233pub struct DetectControllerRequestStream {
234    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
235    is_terminated: bool,
236}
237
238impl std::marker::Unpin for DetectControllerRequestStream {}
239
240impl futures::stream::FusedStream for DetectControllerRequestStream {
241    fn is_terminated(&self) -> bool {
242        self.is_terminated
243    }
244}
245
246impl fidl::endpoints::RequestStream for DetectControllerRequestStream {
247    type Protocol = DetectControllerMarker;
248    type ControlHandle = DetectControllerControlHandle;
249
250    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
251        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
252    }
253
254    fn control_handle(&self) -> Self::ControlHandle {
255        DetectControllerControlHandle { inner: self.inner.clone() }
256    }
257
258    fn into_inner(
259        self,
260    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
261    {
262        (self.inner, self.is_terminated)
263    }
264
265    fn from_inner(
266        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
267        is_terminated: bool,
268    ) -> Self {
269        Self { inner, is_terminated }
270    }
271}
272
273impl futures::Stream for DetectControllerRequestStream {
274    type Item = Result<DetectControllerRequest, fidl::Error>;
275
276    fn poll_next(
277        mut self: std::pin::Pin<&mut Self>,
278        cx: &mut std::task::Context<'_>,
279    ) -> std::task::Poll<Option<Self::Item>> {
280        let this = &mut *self;
281        if this.inner.check_shutdown(cx) {
282            this.is_terminated = true;
283            return std::task::Poll::Ready(None);
284        }
285        if this.is_terminated {
286            panic!("polled DetectControllerRequestStream after completion");
287        }
288        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
289            |bytes, handles| {
290                match this.inner.channel().read_etc(cx, bytes, handles) {
291                    std::task::Poll::Ready(Ok(())) => {}
292                    std::task::Poll::Pending => return std::task::Poll::Pending,
293                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
294                        this.is_terminated = true;
295                        return std::task::Poll::Ready(None);
296                    }
297                    std::task::Poll::Ready(Err(e)) => {
298                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
299                            e.into(),
300                        ))))
301                    }
302                }
303
304                // A message has been received from the channel
305                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
306
307                std::task::Poll::Ready(Some(match header.ordinal {
308                    0x6f4bb79cfba4f84 => {
309                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
310                        let mut req = fidl::new_empty!(
311                            DetectControllerEnterTestModeRequest,
312                            fidl::encoding::DefaultFuchsiaResourceDialect
313                        );
314                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DetectControllerEnterTestModeRequest>(&header, _body_bytes, handles, &mut req)?;
315                        let control_handle =
316                            DetectControllerControlHandle { inner: this.inner.clone() };
317                        Ok(DetectControllerRequest::EnterTestMode {
318                            test_controller: req.test_controller,
319
320                            responder: DetectControllerEnterTestModeResponder {
321                                control_handle: std::mem::ManuallyDrop::new(control_handle),
322                                tx_id: header.tx_id,
323                            },
324                        })
325                    }
326                    _ => Err(fidl::Error::UnknownOrdinal {
327                        ordinal: header.ordinal,
328                        protocol_name:
329                            <DetectControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
330                    }),
331                }))
332            },
333        )
334    }
335}
336
337/// Allows a test framework to invoke a special test mode and control program
338/// operations.
339#[derive(Debug)]
340pub enum DetectControllerRequest {
341    /// Enter the test mode. Return when the program is ready and idle.
342    /// If already in test mode, it will not return until the first test mode is
343    /// exited by closing its test_controller client_end.
344    EnterTestMode {
345        test_controller: fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
346        responder: DetectControllerEnterTestModeResponder,
347    },
348}
349
350impl DetectControllerRequest {
351    #[allow(irrefutable_let_patterns)]
352    pub fn into_enter_test_mode(
353        self,
354    ) -> Option<(
355        fidl::endpoints::ServerEnd<TestCaseControllerMarker>,
356        DetectControllerEnterTestModeResponder,
357    )> {
358        if let DetectControllerRequest::EnterTestMode { test_controller, responder } = self {
359            Some((test_controller, responder))
360        } else {
361            None
362        }
363    }
364
365    /// Name of the method defined in FIDL
366    pub fn method_name(&self) -> &'static str {
367        match *self {
368            DetectControllerRequest::EnterTestMode { .. } => "enter_test_mode",
369        }
370    }
371}
372
373#[derive(Debug, Clone)]
374pub struct DetectControllerControlHandle {
375    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
376}
377
378impl fidl::endpoints::ControlHandle for DetectControllerControlHandle {
379    fn shutdown(&self) {
380        self.inner.shutdown()
381    }
382    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
383        self.inner.shutdown_with_epitaph(status)
384    }
385
386    fn is_closed(&self) -> bool {
387        self.inner.channel().is_closed()
388    }
389    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
390        self.inner.channel().on_closed()
391    }
392
393    #[cfg(target_os = "fuchsia")]
394    fn signal_peer(
395        &self,
396        clear_mask: zx::Signals,
397        set_mask: zx::Signals,
398    ) -> Result<(), zx_status::Status> {
399        use fidl::Peered;
400        self.inner.channel().signal_peer(clear_mask, set_mask)
401    }
402}
403
404impl DetectControllerControlHandle {}
405
406#[must_use = "FIDL methods require a response to be sent"]
407#[derive(Debug)]
408pub struct DetectControllerEnterTestModeResponder {
409    control_handle: std::mem::ManuallyDrop<DetectControllerControlHandle>,
410    tx_id: u32,
411}
412
413/// Set the the channel to be shutdown (see [`DetectControllerControlHandle::shutdown`])
414/// if the responder is dropped without sending a response, so that the client
415/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
416impl std::ops::Drop for DetectControllerEnterTestModeResponder {
417    fn drop(&mut self) {
418        self.control_handle.shutdown();
419        // Safety: drops once, never accessed again
420        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
421    }
422}
423
424impl fidl::endpoints::Responder for DetectControllerEnterTestModeResponder {
425    type ControlHandle = DetectControllerControlHandle;
426
427    fn control_handle(&self) -> &DetectControllerControlHandle {
428        &self.control_handle
429    }
430
431    fn drop_without_shutdown(mut self) {
432        // Safety: drops once, never accessed again due to mem::forget
433        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
434        // Prevent Drop from running (which would shut down the channel)
435        std::mem::forget(self);
436    }
437}
438
439impl DetectControllerEnterTestModeResponder {
440    /// Sends a response to the FIDL transaction.
441    ///
442    /// Sets the channel to shutdown if an error occurs.
443    pub fn send(self) -> Result<(), fidl::Error> {
444        let _result = self.send_raw();
445        if _result.is_err() {
446            self.control_handle.shutdown();
447        }
448        self.drop_without_shutdown();
449        _result
450    }
451
452    /// Similar to "send" but does not shutdown the channel if an error occurs.
453    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
454        let _result = self.send_raw();
455        self.drop_without_shutdown();
456        _result
457    }
458
459    fn send_raw(&self) -> Result<(), fidl::Error> {
460        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
461            (),
462            self.tx_id,
463            0x6f4bb79cfba4f84,
464            fidl::encoding::DynamicFlags::empty(),
465        )
466    }
467}
468
469#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
470pub struct TestCaseControllerMarker;
471
472impl fidl::endpoints::ProtocolMarker for TestCaseControllerMarker {
473    type Proxy = TestCaseControllerProxy;
474    type RequestStream = TestCaseControllerRequestStream;
475    #[cfg(target_os = "fuchsia")]
476    type SynchronousProxy = TestCaseControllerSynchronousProxy;
477
478    const DEBUG_NAME: &'static str = "(anonymous) TestCaseController";
479}
480
481pub trait TestCaseControllerProxyInterface: Send + Sync {
482    type RunDefaultCycleResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
483    fn r#run_default_cycle(&self) -> Self::RunDefaultCycleResponseFut;
484}
485#[derive(Debug)]
486#[cfg(target_os = "fuchsia")]
487pub struct TestCaseControllerSynchronousProxy {
488    client: fidl::client::sync::Client,
489}
490
491#[cfg(target_os = "fuchsia")]
492impl fidl::endpoints::SynchronousProxy for TestCaseControllerSynchronousProxy {
493    type Proxy = TestCaseControllerProxy;
494    type Protocol = TestCaseControllerMarker;
495
496    fn from_channel(inner: fidl::Channel) -> Self {
497        Self::new(inner)
498    }
499
500    fn into_channel(self) -> fidl::Channel {
501        self.client.into_channel()
502    }
503
504    fn as_channel(&self) -> &fidl::Channel {
505        self.client.as_channel()
506    }
507}
508
509#[cfg(target_os = "fuchsia")]
510impl TestCaseControllerSynchronousProxy {
511    pub fn new(channel: fidl::Channel) -> Self {
512        let protocol_name =
513            <TestCaseControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
514        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
515    }
516
517    pub fn into_channel(self) -> fidl::Channel {
518        self.client.into_channel()
519    }
520
521    /// Waits until an event arrives and returns it. It is safe for other
522    /// threads to make concurrent requests while waiting for an event.
523    pub fn wait_for_event(
524        &self,
525        deadline: zx::MonotonicInstant,
526    ) -> Result<TestCaseControllerEvent, fidl::Error> {
527        TestCaseControllerEvent::decode(self.client.wait_for_event(deadline)?)
528    }
529
530    /// Run a single default test case. Returns when the test case completes.
531    /// Returns an error if the test case exits abnormally.
532    pub fn r#run_default_cycle(
533        &self,
534        ___deadline: zx::MonotonicInstant,
535    ) -> Result<(), fidl::Error> {
536        let _response =
537            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
538                (),
539                0x6f41c0399849aea2,
540                fidl::encoding::DynamicFlags::empty(),
541                ___deadline,
542            )?;
543        Ok(_response)
544    }
545}
546
547#[derive(Debug, Clone)]
548pub struct TestCaseControllerProxy {
549    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
550}
551
552impl fidl::endpoints::Proxy for TestCaseControllerProxy {
553    type Protocol = TestCaseControllerMarker;
554
555    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
556        Self::new(inner)
557    }
558
559    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
560        self.client.into_channel().map_err(|client| Self { client })
561    }
562
563    fn as_channel(&self) -> &::fidl::AsyncChannel {
564        self.client.as_channel()
565    }
566}
567
568impl TestCaseControllerProxy {
569    /// Create a new Proxy for fuchsia.diagnostics.test/TestCaseController.
570    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
571        let protocol_name =
572            <TestCaseControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
573        Self { client: fidl::client::Client::new(channel, protocol_name) }
574    }
575
576    /// Get a Stream of events from the remote end of the protocol.
577    ///
578    /// # Panics
579    ///
580    /// Panics if the event stream was already taken.
581    pub fn take_event_stream(&self) -> TestCaseControllerEventStream {
582        TestCaseControllerEventStream { event_receiver: self.client.take_event_receiver() }
583    }
584
585    /// Run a single default test case. Returns when the test case completes.
586    /// Returns an error if the test case exits abnormally.
587    pub fn r#run_default_cycle(
588        &self,
589    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
590        TestCaseControllerProxyInterface::r#run_default_cycle(self)
591    }
592}
593
594impl TestCaseControllerProxyInterface for TestCaseControllerProxy {
595    type RunDefaultCycleResponseFut =
596        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
597    fn r#run_default_cycle(&self) -> Self::RunDefaultCycleResponseFut {
598        fn _decode(
599            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
600        ) -> Result<(), fidl::Error> {
601            let _response = fidl::client::decode_transaction_body::<
602                fidl::encoding::EmptyPayload,
603                fidl::encoding::DefaultFuchsiaResourceDialect,
604                0x6f41c0399849aea2,
605            >(_buf?)?;
606            Ok(_response)
607        }
608        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
609            (),
610            0x6f41c0399849aea2,
611            fidl::encoding::DynamicFlags::empty(),
612            _decode,
613        )
614    }
615}
616
617pub struct TestCaseControllerEventStream {
618    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
619}
620
621impl std::marker::Unpin for TestCaseControllerEventStream {}
622
623impl futures::stream::FusedStream for TestCaseControllerEventStream {
624    fn is_terminated(&self) -> bool {
625        self.event_receiver.is_terminated()
626    }
627}
628
629impl futures::Stream for TestCaseControllerEventStream {
630    type Item = Result<TestCaseControllerEvent, fidl::Error>;
631
632    fn poll_next(
633        mut self: std::pin::Pin<&mut Self>,
634        cx: &mut std::task::Context<'_>,
635    ) -> std::task::Poll<Option<Self::Item>> {
636        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
637            &mut self.event_receiver,
638            cx
639        )?) {
640            Some(buf) => std::task::Poll::Ready(Some(TestCaseControllerEvent::decode(buf))),
641            None => std::task::Poll::Ready(None),
642        }
643    }
644}
645
646#[derive(Debug)]
647pub enum TestCaseControllerEvent {}
648
649impl TestCaseControllerEvent {
650    /// Decodes a message buffer as a [`TestCaseControllerEvent`].
651    fn decode(
652        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
653    ) -> Result<TestCaseControllerEvent, fidl::Error> {
654        let (bytes, _handles) = buf.split_mut();
655        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
656        debug_assert_eq!(tx_header.tx_id, 0);
657        match tx_header.ordinal {
658            _ => Err(fidl::Error::UnknownOrdinal {
659                ordinal: tx_header.ordinal,
660                protocol_name:
661                    <TestCaseControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
662            }),
663        }
664    }
665}
666
667/// A Stream of incoming requests for fuchsia.diagnostics.test/TestCaseController.
668pub struct TestCaseControllerRequestStream {
669    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
670    is_terminated: bool,
671}
672
673impl std::marker::Unpin for TestCaseControllerRequestStream {}
674
675impl futures::stream::FusedStream for TestCaseControllerRequestStream {
676    fn is_terminated(&self) -> bool {
677        self.is_terminated
678    }
679}
680
681impl fidl::endpoints::RequestStream for TestCaseControllerRequestStream {
682    type Protocol = TestCaseControllerMarker;
683    type ControlHandle = TestCaseControllerControlHandle;
684
685    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
686        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
687    }
688
689    fn control_handle(&self) -> Self::ControlHandle {
690        TestCaseControllerControlHandle { inner: self.inner.clone() }
691    }
692
693    fn into_inner(
694        self,
695    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
696    {
697        (self.inner, self.is_terminated)
698    }
699
700    fn from_inner(
701        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
702        is_terminated: bool,
703    ) -> Self {
704        Self { inner, is_terminated }
705    }
706}
707
708impl futures::Stream for TestCaseControllerRequestStream {
709    type Item = Result<TestCaseControllerRequest, fidl::Error>;
710
711    fn poll_next(
712        mut self: std::pin::Pin<&mut Self>,
713        cx: &mut std::task::Context<'_>,
714    ) -> std::task::Poll<Option<Self::Item>> {
715        let this = &mut *self;
716        if this.inner.check_shutdown(cx) {
717            this.is_terminated = true;
718            return std::task::Poll::Ready(None);
719        }
720        if this.is_terminated {
721            panic!("polled TestCaseControllerRequestStream after completion");
722        }
723        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
724            |bytes, handles| {
725                match this.inner.channel().read_etc(cx, bytes, handles) {
726                    std::task::Poll::Ready(Ok(())) => {}
727                    std::task::Poll::Pending => return std::task::Poll::Pending,
728                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
729                        this.is_terminated = true;
730                        return std::task::Poll::Ready(None);
731                    }
732                    std::task::Poll::Ready(Err(e)) => {
733                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
734                            e.into(),
735                        ))))
736                    }
737                }
738
739                // A message has been received from the channel
740                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
741
742                std::task::Poll::Ready(Some(match header.ordinal {
743                0x6f41c0399849aea2 => {
744                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
745                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
746                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
747                    let control_handle = TestCaseControllerControlHandle {
748                        inner: this.inner.clone(),
749                    };
750                    Ok(TestCaseControllerRequest::RunDefaultCycle {
751                        responder: TestCaseControllerRunDefaultCycleResponder {
752                            control_handle: std::mem::ManuallyDrop::new(control_handle),
753                            tx_id: header.tx_id,
754                        },
755                    })
756                }
757                _ => Err(fidl::Error::UnknownOrdinal {
758                    ordinal: header.ordinal,
759                    protocol_name: <TestCaseControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
760                }),
761            }))
762            },
763        )
764    }
765}
766
767/// Tell Detect when to run test cases. Close the protocol to exit test mode.
768/// Running a test case (for example, with RunDefaultCycle() does not exit test
769/// mode when the test case completes.
770#[derive(Debug)]
771pub enum TestCaseControllerRequest {
772    /// Run a single default test case. Returns when the test case completes.
773    /// Returns an error if the test case exits abnormally.
774    RunDefaultCycle { responder: TestCaseControllerRunDefaultCycleResponder },
775}
776
777impl TestCaseControllerRequest {
778    #[allow(irrefutable_let_patterns)]
779    pub fn into_run_default_cycle(self) -> Option<(TestCaseControllerRunDefaultCycleResponder)> {
780        if let TestCaseControllerRequest::RunDefaultCycle { responder } = self {
781            Some((responder))
782        } else {
783            None
784        }
785    }
786
787    /// Name of the method defined in FIDL
788    pub fn method_name(&self) -> &'static str {
789        match *self {
790            TestCaseControllerRequest::RunDefaultCycle { .. } => "run_default_cycle",
791        }
792    }
793}
794
795#[derive(Debug, Clone)]
796pub struct TestCaseControllerControlHandle {
797    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
798}
799
800impl fidl::endpoints::ControlHandle for TestCaseControllerControlHandle {
801    fn shutdown(&self) {
802        self.inner.shutdown()
803    }
804    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
805        self.inner.shutdown_with_epitaph(status)
806    }
807
808    fn is_closed(&self) -> bool {
809        self.inner.channel().is_closed()
810    }
811    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
812        self.inner.channel().on_closed()
813    }
814
815    #[cfg(target_os = "fuchsia")]
816    fn signal_peer(
817        &self,
818        clear_mask: zx::Signals,
819        set_mask: zx::Signals,
820    ) -> Result<(), zx_status::Status> {
821        use fidl::Peered;
822        self.inner.channel().signal_peer(clear_mask, set_mask)
823    }
824}
825
826impl TestCaseControllerControlHandle {}
827
828#[must_use = "FIDL methods require a response to be sent"]
829#[derive(Debug)]
830pub struct TestCaseControllerRunDefaultCycleResponder {
831    control_handle: std::mem::ManuallyDrop<TestCaseControllerControlHandle>,
832    tx_id: u32,
833}
834
835/// Set the the channel to be shutdown (see [`TestCaseControllerControlHandle::shutdown`])
836/// if the responder is dropped without sending a response, so that the client
837/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
838impl std::ops::Drop for TestCaseControllerRunDefaultCycleResponder {
839    fn drop(&mut self) {
840        self.control_handle.shutdown();
841        // Safety: drops once, never accessed again
842        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
843    }
844}
845
846impl fidl::endpoints::Responder for TestCaseControllerRunDefaultCycleResponder {
847    type ControlHandle = TestCaseControllerControlHandle;
848
849    fn control_handle(&self) -> &TestCaseControllerControlHandle {
850        &self.control_handle
851    }
852
853    fn drop_without_shutdown(mut self) {
854        // Safety: drops once, never accessed again due to mem::forget
855        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
856        // Prevent Drop from running (which would shut down the channel)
857        std::mem::forget(self);
858    }
859}
860
861impl TestCaseControllerRunDefaultCycleResponder {
862    /// Sends a response to the FIDL transaction.
863    ///
864    /// Sets the channel to shutdown if an error occurs.
865    pub fn send(self) -> Result<(), fidl::Error> {
866        let _result = self.send_raw();
867        if _result.is_err() {
868            self.control_handle.shutdown();
869        }
870        self.drop_without_shutdown();
871        _result
872    }
873
874    /// Similar to "send" but does not shutdown the channel if an error occurs.
875    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
876        let _result = self.send_raw();
877        self.drop_without_shutdown();
878        _result
879    }
880
881    fn send_raw(&self) -> Result<(), fidl::Error> {
882        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
883            (),
884            self.tx_id,
885            0x6f41c0399849aea2,
886            fidl::encoding::DynamicFlags::empty(),
887        )
888    }
889}
890
891mod internal {
892    use super::*;
893
894    impl fidl::encoding::ResourceTypeMarker for DetectControllerEnterTestModeRequest {
895        type Borrowed<'a> = &'a mut Self;
896        fn take_or_borrow<'a>(
897            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
898        ) -> Self::Borrowed<'a> {
899            value
900        }
901    }
902
903    unsafe impl fidl::encoding::TypeMarker for DetectControllerEnterTestModeRequest {
904        type Owned = Self;
905
906        #[inline(always)]
907        fn inline_align(_context: fidl::encoding::Context) -> usize {
908            4
909        }
910
911        #[inline(always)]
912        fn inline_size(_context: fidl::encoding::Context) -> usize {
913            4
914        }
915    }
916
917    unsafe impl
918        fidl::encoding::Encode<
919            DetectControllerEnterTestModeRequest,
920            fidl::encoding::DefaultFuchsiaResourceDialect,
921        > for &mut DetectControllerEnterTestModeRequest
922    {
923        #[inline]
924        unsafe fn encode(
925            self,
926            encoder: &mut fidl::encoding::Encoder<
927                '_,
928                fidl::encoding::DefaultFuchsiaResourceDialect,
929            >,
930            offset: usize,
931            _depth: fidl::encoding::Depth,
932        ) -> fidl::Result<()> {
933            encoder.debug_check_bounds::<DetectControllerEnterTestModeRequest>(offset);
934            // Delegate to tuple encoding.
935            fidl::encoding::Encode::<DetectControllerEnterTestModeRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
936                (
937                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TestCaseControllerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.test_controller),
938                ),
939                encoder, offset, _depth
940            )
941        }
942    }
943    unsafe impl<
944            T0: fidl::encoding::Encode<
945                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TestCaseControllerMarker>>,
946                fidl::encoding::DefaultFuchsiaResourceDialect,
947            >,
948        >
949        fidl::encoding::Encode<
950            DetectControllerEnterTestModeRequest,
951            fidl::encoding::DefaultFuchsiaResourceDialect,
952        > for (T0,)
953    {
954        #[inline]
955        unsafe fn encode(
956            self,
957            encoder: &mut fidl::encoding::Encoder<
958                '_,
959                fidl::encoding::DefaultFuchsiaResourceDialect,
960            >,
961            offset: usize,
962            depth: fidl::encoding::Depth,
963        ) -> fidl::Result<()> {
964            encoder.debug_check_bounds::<DetectControllerEnterTestModeRequest>(offset);
965            // Zero out padding regions. There's no need to apply masks
966            // because the unmasked parts will be overwritten by fields.
967            // Write the fields.
968            self.0.encode(encoder, offset + 0, depth)?;
969            Ok(())
970        }
971    }
972
973    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
974        for DetectControllerEnterTestModeRequest
975    {
976        #[inline(always)]
977        fn new_empty() -> Self {
978            Self {
979                test_controller: fidl::new_empty!(
980                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TestCaseControllerMarker>>,
981                    fidl::encoding::DefaultFuchsiaResourceDialect
982                ),
983            }
984        }
985
986        #[inline]
987        unsafe fn decode(
988            &mut self,
989            decoder: &mut fidl::encoding::Decoder<
990                '_,
991                fidl::encoding::DefaultFuchsiaResourceDialect,
992            >,
993            offset: usize,
994            _depth: fidl::encoding::Depth,
995        ) -> fidl::Result<()> {
996            decoder.debug_check_bounds::<Self>(offset);
997            // Verify that padding bytes are zero.
998            fidl::decode!(
999                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<TestCaseControllerMarker>>,
1000                fidl::encoding::DefaultFuchsiaResourceDialect,
1001                &mut self.test_controller,
1002                decoder,
1003                offset + 0,
1004                _depth
1005            )?;
1006            Ok(())
1007        }
1008    }
1009}