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