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