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