fidl_fuchsia_test_pwrbtn/
fidl_fuchsia_test_pwrbtn.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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
14pub struct TestsMarker;
15
16impl fidl::endpoints::ProtocolMarker for TestsMarker {
17    type Proxy = TestsProxy;
18    type RequestStream = TestsRequestStream;
19    #[cfg(target_os = "fuchsia")]
20    type SynchronousProxy = TestsSynchronousProxy;
21
22    const DEBUG_NAME: &'static str = "fuchsia.test.pwrbtn.Tests";
23}
24impl fidl::endpoints::DiscoverableProtocolMarker for TestsMarker {}
25
26pub trait TestsProxyInterface: Send + Sync {
27    type RunResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
28    fn r#run(&self) -> Self::RunResponseFut;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct TestsSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for TestsSynchronousProxy {
38    type Proxy = TestsProxy;
39    type Protocol = TestsMarker;
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 TestsSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        let protocol_name = <TestsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
58        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
59    }
60
61    pub fn into_channel(self) -> fidl::Channel {
62        self.client.into_channel()
63    }
64
65    /// Waits until an event arrives and returns it. It is safe for other
66    /// threads to make concurrent requests while waiting for an event.
67    pub fn wait_for_event(
68        &self,
69        deadline: zx::MonotonicInstant,
70    ) -> Result<TestsEvent, fidl::Error> {
71        TestsEvent::decode(self.client.wait_for_event(deadline)?)
72    }
73
74    /// Run the tests. This function returns when the tests have successfully
75    /// passed, and is closed without a response when the tests fail.
76    pub fn r#run(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
77        let _response =
78            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
79                (),
80                0x29284fb599240423,
81                fidl::encoding::DynamicFlags::empty(),
82                ___deadline,
83            )?;
84        Ok(_response)
85    }
86}
87
88#[derive(Debug, Clone)]
89pub struct TestsProxy {
90    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
91}
92
93impl fidl::endpoints::Proxy for TestsProxy {
94    type Protocol = TestsMarker;
95
96    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
97        Self::new(inner)
98    }
99
100    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
101        self.client.into_channel().map_err(|client| Self { client })
102    }
103
104    fn as_channel(&self) -> &::fidl::AsyncChannel {
105        self.client.as_channel()
106    }
107}
108
109impl TestsProxy {
110    /// Create a new Proxy for fuchsia.test.pwrbtn/Tests.
111    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
112        let protocol_name = <TestsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
113        Self { client: fidl::client::Client::new(channel, protocol_name) }
114    }
115
116    /// Get a Stream of events from the remote end of the protocol.
117    ///
118    /// # Panics
119    ///
120    /// Panics if the event stream was already taken.
121    pub fn take_event_stream(&self) -> TestsEventStream {
122        TestsEventStream { event_receiver: self.client.take_event_receiver() }
123    }
124
125    /// Run the tests. This function returns when the tests have successfully
126    /// passed, and is closed without a response when the tests fail.
127    pub fn r#run(
128        &self,
129    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
130        TestsProxyInterface::r#run(self)
131    }
132}
133
134impl TestsProxyInterface for TestsProxy {
135    type RunResponseFut =
136        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
137    fn r#run(&self) -> Self::RunResponseFut {
138        fn _decode(
139            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
140        ) -> Result<(), fidl::Error> {
141            let _response = fidl::client::decode_transaction_body::<
142                fidl::encoding::EmptyPayload,
143                fidl::encoding::DefaultFuchsiaResourceDialect,
144                0x29284fb599240423,
145            >(_buf?)?;
146            Ok(_response)
147        }
148        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
149            (),
150            0x29284fb599240423,
151            fidl::encoding::DynamicFlags::empty(),
152            _decode,
153        )
154    }
155}
156
157pub struct TestsEventStream {
158    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
159}
160
161impl std::marker::Unpin for TestsEventStream {}
162
163impl futures::stream::FusedStream for TestsEventStream {
164    fn is_terminated(&self) -> bool {
165        self.event_receiver.is_terminated()
166    }
167}
168
169impl futures::Stream for TestsEventStream {
170    type Item = Result<TestsEvent, fidl::Error>;
171
172    fn poll_next(
173        mut self: std::pin::Pin<&mut Self>,
174        cx: &mut std::task::Context<'_>,
175    ) -> std::task::Poll<Option<Self::Item>> {
176        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
177            &mut self.event_receiver,
178            cx
179        )?) {
180            Some(buf) => std::task::Poll::Ready(Some(TestsEvent::decode(buf))),
181            None => std::task::Poll::Ready(None),
182        }
183    }
184}
185
186#[derive(Debug)]
187pub enum TestsEvent {}
188
189impl TestsEvent {
190    /// Decodes a message buffer as a [`TestsEvent`].
191    fn decode(
192        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
193    ) -> Result<TestsEvent, fidl::Error> {
194        let (bytes, _handles) = buf.split_mut();
195        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
196        debug_assert_eq!(tx_header.tx_id, 0);
197        match tx_header.ordinal {
198            _ => Err(fidl::Error::UnknownOrdinal {
199                ordinal: tx_header.ordinal,
200                protocol_name: <TestsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
201            }),
202        }
203    }
204}
205
206/// A Stream of incoming requests for fuchsia.test.pwrbtn/Tests.
207pub struct TestsRequestStream {
208    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
209    is_terminated: bool,
210}
211
212impl std::marker::Unpin for TestsRequestStream {}
213
214impl futures::stream::FusedStream for TestsRequestStream {
215    fn is_terminated(&self) -> bool {
216        self.is_terminated
217    }
218}
219
220impl fidl::endpoints::RequestStream for TestsRequestStream {
221    type Protocol = TestsMarker;
222    type ControlHandle = TestsControlHandle;
223
224    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
225        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
226    }
227
228    fn control_handle(&self) -> Self::ControlHandle {
229        TestsControlHandle { inner: self.inner.clone() }
230    }
231
232    fn into_inner(
233        self,
234    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
235    {
236        (self.inner, self.is_terminated)
237    }
238
239    fn from_inner(
240        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241        is_terminated: bool,
242    ) -> Self {
243        Self { inner, is_terminated }
244    }
245}
246
247impl futures::Stream for TestsRequestStream {
248    type Item = Result<TestsRequest, fidl::Error>;
249
250    fn poll_next(
251        mut self: std::pin::Pin<&mut Self>,
252        cx: &mut std::task::Context<'_>,
253    ) -> std::task::Poll<Option<Self::Item>> {
254        let this = &mut *self;
255        if this.inner.check_shutdown(cx) {
256            this.is_terminated = true;
257            return std::task::Poll::Ready(None);
258        }
259        if this.is_terminated {
260            panic!("polled TestsRequestStream after completion");
261        }
262        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
263            |bytes, handles| {
264                match this.inner.channel().read_etc(cx, bytes, handles) {
265                    std::task::Poll::Ready(Ok(())) => {}
266                    std::task::Poll::Pending => return std::task::Poll::Pending,
267                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
268                        this.is_terminated = true;
269                        return std::task::Poll::Ready(None);
270                    }
271                    std::task::Poll::Ready(Err(e)) => {
272                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
273                            e.into(),
274                        ))))
275                    }
276                }
277
278                // A message has been received from the channel
279                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
280
281                std::task::Poll::Ready(Some(match header.ordinal {
282                    0x29284fb599240423 => {
283                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
284                        let mut req = fidl::new_empty!(
285                            fidl::encoding::EmptyPayload,
286                            fidl::encoding::DefaultFuchsiaResourceDialect
287                        );
288                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
289                        let control_handle = TestsControlHandle { inner: this.inner.clone() };
290                        Ok(TestsRequest::Run {
291                            responder: TestsRunResponder {
292                                control_handle: std::mem::ManuallyDrop::new(control_handle),
293                                tx_id: header.tx_id,
294                            },
295                        })
296                    }
297                    _ => Err(fidl::Error::UnknownOrdinal {
298                        ordinal: header.ordinal,
299                        protocol_name: <TestsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
300                    }),
301                }))
302            },
303        )
304    }
305}
306
307#[derive(Debug)]
308pub enum TestsRequest {
309    /// Run the tests. This function returns when the tests have successfully
310    /// passed, and is closed without a response when the tests fail.
311    Run { responder: TestsRunResponder },
312}
313
314impl TestsRequest {
315    #[allow(irrefutable_let_patterns)]
316    pub fn into_run(self) -> Option<(TestsRunResponder)> {
317        if let TestsRequest::Run { responder } = self {
318            Some((responder))
319        } else {
320            None
321        }
322    }
323
324    /// Name of the method defined in FIDL
325    pub fn method_name(&self) -> &'static str {
326        match *self {
327            TestsRequest::Run { .. } => "run",
328        }
329    }
330}
331
332#[derive(Debug, Clone)]
333pub struct TestsControlHandle {
334    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
335}
336
337impl fidl::endpoints::ControlHandle for TestsControlHandle {
338    fn shutdown(&self) {
339        self.inner.shutdown()
340    }
341    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
342        self.inner.shutdown_with_epitaph(status)
343    }
344
345    fn is_closed(&self) -> bool {
346        self.inner.channel().is_closed()
347    }
348    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
349        self.inner.channel().on_closed()
350    }
351
352    #[cfg(target_os = "fuchsia")]
353    fn signal_peer(
354        &self,
355        clear_mask: zx::Signals,
356        set_mask: zx::Signals,
357    ) -> Result<(), zx_status::Status> {
358        use fidl::Peered;
359        self.inner.channel().signal_peer(clear_mask, set_mask)
360    }
361}
362
363impl TestsControlHandle {}
364
365#[must_use = "FIDL methods require a response to be sent"]
366#[derive(Debug)]
367pub struct TestsRunResponder {
368    control_handle: std::mem::ManuallyDrop<TestsControlHandle>,
369    tx_id: u32,
370}
371
372/// Set the the channel to be shutdown (see [`TestsControlHandle::shutdown`])
373/// if the responder is dropped without sending a response, so that the client
374/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
375impl std::ops::Drop for TestsRunResponder {
376    fn drop(&mut self) {
377        self.control_handle.shutdown();
378        // Safety: drops once, never accessed again
379        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
380    }
381}
382
383impl fidl::endpoints::Responder for TestsRunResponder {
384    type ControlHandle = TestsControlHandle;
385
386    fn control_handle(&self) -> &TestsControlHandle {
387        &self.control_handle
388    }
389
390    fn drop_without_shutdown(mut self) {
391        // Safety: drops once, never accessed again due to mem::forget
392        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
393        // Prevent Drop from running (which would shut down the channel)
394        std::mem::forget(self);
395    }
396}
397
398impl TestsRunResponder {
399    /// Sends a response to the FIDL transaction.
400    ///
401    /// Sets the channel to shutdown if an error occurs.
402    pub fn send(self) -> Result<(), fidl::Error> {
403        let _result = self.send_raw();
404        if _result.is_err() {
405            self.control_handle.shutdown();
406        }
407        self.drop_without_shutdown();
408        _result
409    }
410
411    /// Similar to "send" but does not shutdown the channel if an error occurs.
412    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
413        let _result = self.send_raw();
414        self.drop_without_shutdown();
415        _result
416    }
417
418    fn send_raw(&self) -> Result<(), fidl::Error> {
419        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
420            (),
421            self.tx_id,
422            0x29284fb599240423,
423            fidl::encoding::DynamicFlags::empty(),
424        )
425    }
426}
427
428mod internal {
429    use super::*;
430}