fidl_fuchsia_component_tests/
fidl_fuchsia_component_tests.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 ShutdownerMarker;
15
16impl fidl::endpoints::ProtocolMarker for ShutdownerMarker {
17    type Proxy = ShutdownerProxy;
18    type RequestStream = ShutdownerRequestStream;
19    #[cfg(target_os = "fuchsia")]
20    type SynchronousProxy = ShutdownerSynchronousProxy;
21
22    const DEBUG_NAME: &'static str = "fuchsia.component.tests.Shutdowner";
23}
24impl fidl::endpoints::DiscoverableProtocolMarker for ShutdownerMarker {}
25
26pub trait ShutdownerProxyInterface: Send + Sync {
27    fn r#shutdown(&self) -> Result<(), fidl::Error>;
28}
29#[derive(Debug)]
30#[cfg(target_os = "fuchsia")]
31pub struct ShutdownerSynchronousProxy {
32    client: fidl::client::sync::Client,
33}
34
35#[cfg(target_os = "fuchsia")]
36impl fidl::endpoints::SynchronousProxy for ShutdownerSynchronousProxy {
37    type Proxy = ShutdownerProxy;
38    type Protocol = ShutdownerMarker;
39
40    fn from_channel(inner: fidl::Channel) -> Self {
41        Self::new(inner)
42    }
43
44    fn into_channel(self) -> fidl::Channel {
45        self.client.into_channel()
46    }
47
48    fn as_channel(&self) -> &fidl::Channel {
49        self.client.as_channel()
50    }
51}
52
53#[cfg(target_os = "fuchsia")]
54impl ShutdownerSynchronousProxy {
55    pub fn new(channel: fidl::Channel) -> Self {
56        let protocol_name = <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
57        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
58    }
59
60    pub fn into_channel(self) -> fidl::Channel {
61        self.client.into_channel()
62    }
63
64    /// Waits until an event arrives and returns it. It is safe for other
65    /// threads to make concurrent requests while waiting for an event.
66    pub fn wait_for_event(
67        &self,
68        deadline: zx::MonotonicInstant,
69    ) -> Result<ShutdownerEvent, fidl::Error> {
70        ShutdownerEvent::decode(self.client.wait_for_event(deadline)?)
71    }
72
73    pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
74        self.client.send::<fidl::encoding::EmptyPayload>(
75            (),
76            0x4da8a4e818bef187,
77            fidl::encoding::DynamicFlags::empty(),
78        )
79    }
80}
81
82#[derive(Debug, Clone)]
83pub struct ShutdownerProxy {
84    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
85}
86
87impl fidl::endpoints::Proxy for ShutdownerProxy {
88    type Protocol = ShutdownerMarker;
89
90    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
91        Self::new(inner)
92    }
93
94    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
95        self.client.into_channel().map_err(|client| Self { client })
96    }
97
98    fn as_channel(&self) -> &::fidl::AsyncChannel {
99        self.client.as_channel()
100    }
101}
102
103impl ShutdownerProxy {
104    /// Create a new Proxy for fuchsia.component.tests/Shutdowner.
105    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
106        let protocol_name = <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
107        Self { client: fidl::client::Client::new(channel, protocol_name) }
108    }
109
110    /// Get a Stream of events from the remote end of the protocol.
111    ///
112    /// # Panics
113    ///
114    /// Panics if the event stream was already taken.
115    pub fn take_event_stream(&self) -> ShutdownerEventStream {
116        ShutdownerEventStream { event_receiver: self.client.take_event_receiver() }
117    }
118
119    pub fn r#shutdown(&self) -> Result<(), fidl::Error> {
120        ShutdownerProxyInterface::r#shutdown(self)
121    }
122}
123
124impl ShutdownerProxyInterface for ShutdownerProxy {
125    fn r#shutdown(&self) -> Result<(), fidl::Error> {
126        self.client.send::<fidl::encoding::EmptyPayload>(
127            (),
128            0x4da8a4e818bef187,
129            fidl::encoding::DynamicFlags::empty(),
130        )
131    }
132}
133
134pub struct ShutdownerEventStream {
135    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
136}
137
138impl std::marker::Unpin for ShutdownerEventStream {}
139
140impl futures::stream::FusedStream for ShutdownerEventStream {
141    fn is_terminated(&self) -> bool {
142        self.event_receiver.is_terminated()
143    }
144}
145
146impl futures::Stream for ShutdownerEventStream {
147    type Item = Result<ShutdownerEvent, fidl::Error>;
148
149    fn poll_next(
150        mut self: std::pin::Pin<&mut Self>,
151        cx: &mut std::task::Context<'_>,
152    ) -> std::task::Poll<Option<Self::Item>> {
153        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
154            &mut self.event_receiver,
155            cx
156        )?) {
157            Some(buf) => std::task::Poll::Ready(Some(ShutdownerEvent::decode(buf))),
158            None => std::task::Poll::Ready(None),
159        }
160    }
161}
162
163#[derive(Debug)]
164pub enum ShutdownerEvent {}
165
166impl ShutdownerEvent {
167    /// Decodes a message buffer as a [`ShutdownerEvent`].
168    fn decode(
169        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
170    ) -> Result<ShutdownerEvent, fidl::Error> {
171        let (bytes, _handles) = buf.split_mut();
172        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
173        debug_assert_eq!(tx_header.tx_id, 0);
174        match tx_header.ordinal {
175            _ => Err(fidl::Error::UnknownOrdinal {
176                ordinal: tx_header.ordinal,
177                protocol_name: <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
178            }),
179        }
180    }
181}
182
183/// A Stream of incoming requests for fuchsia.component.tests/Shutdowner.
184pub struct ShutdownerRequestStream {
185    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
186    is_terminated: bool,
187}
188
189impl std::marker::Unpin for ShutdownerRequestStream {}
190
191impl futures::stream::FusedStream for ShutdownerRequestStream {
192    fn is_terminated(&self) -> bool {
193        self.is_terminated
194    }
195}
196
197impl fidl::endpoints::RequestStream for ShutdownerRequestStream {
198    type Protocol = ShutdownerMarker;
199    type ControlHandle = ShutdownerControlHandle;
200
201    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
202        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
203    }
204
205    fn control_handle(&self) -> Self::ControlHandle {
206        ShutdownerControlHandle { inner: self.inner.clone() }
207    }
208
209    fn into_inner(
210        self,
211    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
212    {
213        (self.inner, self.is_terminated)
214    }
215
216    fn from_inner(
217        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
218        is_terminated: bool,
219    ) -> Self {
220        Self { inner, is_terminated }
221    }
222}
223
224impl futures::Stream for ShutdownerRequestStream {
225    type Item = Result<ShutdownerRequest, fidl::Error>;
226
227    fn poll_next(
228        mut self: std::pin::Pin<&mut Self>,
229        cx: &mut std::task::Context<'_>,
230    ) -> std::task::Poll<Option<Self::Item>> {
231        let this = &mut *self;
232        if this.inner.check_shutdown(cx) {
233            this.is_terminated = true;
234            return std::task::Poll::Ready(None);
235        }
236        if this.is_terminated {
237            panic!("polled ShutdownerRequestStream after completion");
238        }
239        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
240            |bytes, handles| {
241                match this.inner.channel().read_etc(cx, bytes, handles) {
242                    std::task::Poll::Ready(Ok(())) => {}
243                    std::task::Poll::Pending => return std::task::Poll::Pending,
244                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
245                        this.is_terminated = true;
246                        return std::task::Poll::Ready(None);
247                    }
248                    std::task::Poll::Ready(Err(e)) => {
249                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
250                            e.into(),
251                        ))))
252                    }
253                }
254
255                // A message has been received from the channel
256                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
257
258                std::task::Poll::Ready(Some(match header.ordinal {
259                    0x4da8a4e818bef187 => {
260                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
261                        let mut req = fidl::new_empty!(
262                            fidl::encoding::EmptyPayload,
263                            fidl::encoding::DefaultFuchsiaResourceDialect
264                        );
265                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
266                        let control_handle = ShutdownerControlHandle { inner: this.inner.clone() };
267                        Ok(ShutdownerRequest::Shutdown { control_handle })
268                    }
269                    _ => Err(fidl::Error::UnknownOrdinal {
270                        ordinal: header.ordinal,
271                        protocol_name:
272                            <ShutdownerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
273                    }),
274                }))
275            },
276        )
277    }
278}
279
280/// Simple FIDL protocol for tests that notifies server to shutdown.
281#[derive(Debug)]
282pub enum ShutdownerRequest {
283    Shutdown { control_handle: ShutdownerControlHandle },
284}
285
286impl ShutdownerRequest {
287    #[allow(irrefutable_let_patterns)]
288    pub fn into_shutdown(self) -> Option<(ShutdownerControlHandle)> {
289        if let ShutdownerRequest::Shutdown { control_handle } = self {
290            Some((control_handle))
291        } else {
292            None
293        }
294    }
295
296    /// Name of the method defined in FIDL
297    pub fn method_name(&self) -> &'static str {
298        match *self {
299            ShutdownerRequest::Shutdown { .. } => "shutdown",
300        }
301    }
302}
303
304#[derive(Debug, Clone)]
305pub struct ShutdownerControlHandle {
306    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
307}
308
309impl fidl::endpoints::ControlHandle for ShutdownerControlHandle {
310    fn shutdown(&self) {
311        self.inner.shutdown()
312    }
313    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
314        self.inner.shutdown_with_epitaph(status)
315    }
316
317    fn is_closed(&self) -> bool {
318        self.inner.channel().is_closed()
319    }
320    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
321        self.inner.channel().on_closed()
322    }
323
324    #[cfg(target_os = "fuchsia")]
325    fn signal_peer(
326        &self,
327        clear_mask: zx::Signals,
328        set_mask: zx::Signals,
329    ) -> Result<(), zx_status::Status> {
330        use fidl::Peered;
331        self.inner.channel().signal_peer(clear_mask, set_mask)
332    }
333}
334
335impl ShutdownerControlHandle {}
336
337mod internal {
338    use super::*;
339}