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