fidl_test_policy/
fidl_test_policy.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(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14#[repr(C)]
15pub struct ExitControllerExitRequest {
16    pub code: i32,
17}
18
19impl fidl::Persistable for ExitControllerExitRequest {}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
22pub struct ExitControllerMarker;
23
24impl fidl::endpoints::ProtocolMarker for ExitControllerMarker {
25    type Proxy = ExitControllerProxy;
26    type RequestStream = ExitControllerRequestStream;
27    #[cfg(target_os = "fuchsia")]
28    type SynchronousProxy = ExitControllerSynchronousProxy;
29
30    const DEBUG_NAME: &'static str = "test.policy.ExitController";
31}
32impl fidl::endpoints::DiscoverableProtocolMarker for ExitControllerMarker {}
33
34pub trait ExitControllerProxyInterface: Send + Sync {
35    fn r#exit(&self, code: i32) -> Result<(), fidl::Error>;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct ExitControllerSynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for ExitControllerSynchronousProxy {
45    type Proxy = ExitControllerProxy;
46    type Protocol = ExitControllerMarker;
47
48    fn from_channel(inner: fidl::Channel) -> Self {
49        Self::new(inner)
50    }
51
52    fn into_channel(self) -> fidl::Channel {
53        self.client.into_channel()
54    }
55
56    fn as_channel(&self) -> &fidl::Channel {
57        self.client.as_channel()
58    }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl ExitControllerSynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <ExitControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66    }
67
68    pub fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    /// Waits until an event arrives and returns it. It is safe for other
73    /// threads to make concurrent requests while waiting for an event.
74    pub fn wait_for_event(
75        &self,
76        deadline: zx::MonotonicInstant,
77    ) -> Result<ExitControllerEvent, fidl::Error> {
78        ExitControllerEvent::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    pub fn r#exit(&self, mut code: i32) -> Result<(), fidl::Error> {
82        self.client.send::<ExitControllerExitRequest>(
83            (code,),
84            0x38305e3f46968321,
85            fidl::encoding::DynamicFlags::empty(),
86        )
87    }
88}
89
90#[derive(Debug, Clone)]
91pub struct ExitControllerProxy {
92    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
93}
94
95impl fidl::endpoints::Proxy for ExitControllerProxy {
96    type Protocol = ExitControllerMarker;
97
98    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
99        Self::new(inner)
100    }
101
102    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
103        self.client.into_channel().map_err(|client| Self { client })
104    }
105
106    fn as_channel(&self) -> &::fidl::AsyncChannel {
107        self.client.as_channel()
108    }
109}
110
111impl ExitControllerProxy {
112    /// Create a new Proxy for test.policy/ExitController.
113    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
114        let protocol_name = <ExitControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
115        Self { client: fidl::client::Client::new(channel, protocol_name) }
116    }
117
118    /// Get a Stream of events from the remote end of the protocol.
119    ///
120    /// # Panics
121    ///
122    /// Panics if the event stream was already taken.
123    pub fn take_event_stream(&self) -> ExitControllerEventStream {
124        ExitControllerEventStream { event_receiver: self.client.take_event_receiver() }
125    }
126
127    pub fn r#exit(&self, mut code: i32) -> Result<(), fidl::Error> {
128        ExitControllerProxyInterface::r#exit(self, code)
129    }
130}
131
132impl ExitControllerProxyInterface for ExitControllerProxy {
133    fn r#exit(&self, mut code: i32) -> Result<(), fidl::Error> {
134        self.client.send::<ExitControllerExitRequest>(
135            (code,),
136            0x38305e3f46968321,
137            fidl::encoding::DynamicFlags::empty(),
138        )
139    }
140}
141
142pub struct ExitControllerEventStream {
143    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
144}
145
146impl std::marker::Unpin for ExitControllerEventStream {}
147
148impl futures::stream::FusedStream for ExitControllerEventStream {
149    fn is_terminated(&self) -> bool {
150        self.event_receiver.is_terminated()
151    }
152}
153
154impl futures::Stream for ExitControllerEventStream {
155    type Item = Result<ExitControllerEvent, fidl::Error>;
156
157    fn poll_next(
158        mut self: std::pin::Pin<&mut Self>,
159        cx: &mut std::task::Context<'_>,
160    ) -> std::task::Poll<Option<Self::Item>> {
161        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
162            &mut self.event_receiver,
163            cx
164        )?) {
165            Some(buf) => std::task::Poll::Ready(Some(ExitControllerEvent::decode(buf))),
166            None => std::task::Poll::Ready(None),
167        }
168    }
169}
170
171#[derive(Debug)]
172pub enum ExitControllerEvent {}
173
174impl ExitControllerEvent {
175    /// Decodes a message buffer as a [`ExitControllerEvent`].
176    fn decode(
177        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
178    ) -> Result<ExitControllerEvent, fidl::Error> {
179        let (bytes, _handles) = buf.split_mut();
180        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
181        debug_assert_eq!(tx_header.tx_id, 0);
182        match tx_header.ordinal {
183            _ => Err(fidl::Error::UnknownOrdinal {
184                ordinal: tx_header.ordinal,
185                protocol_name:
186                    <ExitControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
187            }),
188        }
189    }
190}
191
192/// A Stream of incoming requests for test.policy/ExitController.
193pub struct ExitControllerRequestStream {
194    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
195    is_terminated: bool,
196}
197
198impl std::marker::Unpin for ExitControllerRequestStream {}
199
200impl futures::stream::FusedStream for ExitControllerRequestStream {
201    fn is_terminated(&self) -> bool {
202        self.is_terminated
203    }
204}
205
206impl fidl::endpoints::RequestStream for ExitControllerRequestStream {
207    type Protocol = ExitControllerMarker;
208    type ControlHandle = ExitControllerControlHandle;
209
210    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
211        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
212    }
213
214    fn control_handle(&self) -> Self::ControlHandle {
215        ExitControllerControlHandle { inner: self.inner.clone() }
216    }
217
218    fn into_inner(
219        self,
220    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
221    {
222        (self.inner, self.is_terminated)
223    }
224
225    fn from_inner(
226        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
227        is_terminated: bool,
228    ) -> Self {
229        Self { inner, is_terminated }
230    }
231}
232
233impl futures::Stream for ExitControllerRequestStream {
234    type Item = Result<ExitControllerRequest, fidl::Error>;
235
236    fn poll_next(
237        mut self: std::pin::Pin<&mut Self>,
238        cx: &mut std::task::Context<'_>,
239    ) -> std::task::Poll<Option<Self::Item>> {
240        let this = &mut *self;
241        if this.inner.check_shutdown(cx) {
242            this.is_terminated = true;
243            return std::task::Poll::Ready(None);
244        }
245        if this.is_terminated {
246            panic!("polled ExitControllerRequestStream after completion");
247        }
248        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
249            |bytes, handles| {
250                match this.inner.channel().read_etc(cx, bytes, handles) {
251                    std::task::Poll::Ready(Ok(())) => {}
252                    std::task::Poll::Pending => return std::task::Poll::Pending,
253                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
254                        this.is_terminated = true;
255                        return std::task::Poll::Ready(None);
256                    }
257                    std::task::Poll::Ready(Err(e)) => {
258                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
259                            e.into(),
260                        ))))
261                    }
262                }
263
264                // A message has been received from the channel
265                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
266
267                std::task::Poll::Ready(Some(match header.ordinal {
268                    0x38305e3f46968321 => {
269                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
270                        let mut req = fidl::new_empty!(
271                            ExitControllerExitRequest,
272                            fidl::encoding::DefaultFuchsiaResourceDialect
273                        );
274                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ExitControllerExitRequest>(&header, _body_bytes, handles, &mut req)?;
275                        let control_handle =
276                            ExitControllerControlHandle { inner: this.inner.clone() };
277                        Ok(ExitControllerRequest::Exit { code: req.code, control_handle })
278                    }
279                    _ => Err(fidl::Error::UnknownOrdinal {
280                        ordinal: header.ordinal,
281                        protocol_name:
282                            <ExitControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
283                    }),
284                }))
285            },
286        )
287    }
288}
289
290#[derive(Debug)]
291pub enum ExitControllerRequest {
292    Exit { code: i32, control_handle: ExitControllerControlHandle },
293}
294
295impl ExitControllerRequest {
296    #[allow(irrefutable_let_patterns)]
297    pub fn into_exit(self) -> Option<(i32, ExitControllerControlHandle)> {
298        if let ExitControllerRequest::Exit { code, control_handle } = self {
299            Some((code, control_handle))
300        } else {
301            None
302        }
303    }
304
305    /// Name of the method defined in FIDL
306    pub fn method_name(&self) -> &'static str {
307        match *self {
308            ExitControllerRequest::Exit { .. } => "exit",
309        }
310    }
311}
312
313#[derive(Debug, Clone)]
314pub struct ExitControllerControlHandle {
315    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
316}
317
318impl fidl::endpoints::ControlHandle for ExitControllerControlHandle {
319    fn shutdown(&self) {
320        self.inner.shutdown()
321    }
322    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
323        self.inner.shutdown_with_epitaph(status)
324    }
325
326    fn is_closed(&self) -> bool {
327        self.inner.channel().is_closed()
328    }
329    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
330        self.inner.channel().on_closed()
331    }
332
333    #[cfg(target_os = "fuchsia")]
334    fn signal_peer(
335        &self,
336        clear_mask: zx::Signals,
337        set_mask: zx::Signals,
338    ) -> Result<(), zx_status::Status> {
339        use fidl::Peered;
340        self.inner.channel().signal_peer(clear_mask, set_mask)
341    }
342}
343
344impl ExitControllerControlHandle {}
345
346mod internal {
347    use super::*;
348
349    impl fidl::encoding::ValueTypeMarker for ExitControllerExitRequest {
350        type Borrowed<'a> = &'a Self;
351        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
352            value
353        }
354    }
355
356    unsafe impl fidl::encoding::TypeMarker for ExitControllerExitRequest {
357        type Owned = Self;
358
359        #[inline(always)]
360        fn inline_align(_context: fidl::encoding::Context) -> usize {
361            4
362        }
363
364        #[inline(always)]
365        fn inline_size(_context: fidl::encoding::Context) -> usize {
366            4
367        }
368        #[inline(always)]
369        fn encode_is_copy() -> bool {
370            true
371        }
372
373        #[inline(always)]
374        fn decode_is_copy() -> bool {
375            true
376        }
377    }
378
379    unsafe impl<D: fidl::encoding::ResourceDialect>
380        fidl::encoding::Encode<ExitControllerExitRequest, D> for &ExitControllerExitRequest
381    {
382        #[inline]
383        unsafe fn encode(
384            self,
385            encoder: &mut fidl::encoding::Encoder<'_, D>,
386            offset: usize,
387            _depth: fidl::encoding::Depth,
388        ) -> fidl::Result<()> {
389            encoder.debug_check_bounds::<ExitControllerExitRequest>(offset);
390            unsafe {
391                // Copy the object into the buffer.
392                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
393                (buf_ptr as *mut ExitControllerExitRequest)
394                    .write_unaligned((self as *const ExitControllerExitRequest).read());
395                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
396                // done second because the memcpy will write garbage to these bytes.
397            }
398            Ok(())
399        }
400    }
401    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<i32, D>>
402        fidl::encoding::Encode<ExitControllerExitRequest, D> for (T0,)
403    {
404        #[inline]
405        unsafe fn encode(
406            self,
407            encoder: &mut fidl::encoding::Encoder<'_, D>,
408            offset: usize,
409            depth: fidl::encoding::Depth,
410        ) -> fidl::Result<()> {
411            encoder.debug_check_bounds::<ExitControllerExitRequest>(offset);
412            // Zero out padding regions. There's no need to apply masks
413            // because the unmasked parts will be overwritten by fields.
414            // Write the fields.
415            self.0.encode(encoder, offset + 0, depth)?;
416            Ok(())
417        }
418    }
419
420    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
421        for ExitControllerExitRequest
422    {
423        #[inline(always)]
424        fn new_empty() -> Self {
425            Self { code: fidl::new_empty!(i32, D) }
426        }
427
428        #[inline]
429        unsafe fn decode(
430            &mut self,
431            decoder: &mut fidl::encoding::Decoder<'_, D>,
432            offset: usize,
433            _depth: fidl::encoding::Depth,
434        ) -> fidl::Result<()> {
435            decoder.debug_check_bounds::<Self>(offset);
436            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
437            // Verify that padding bytes are zero.
438            // Copy from the buffer into the object.
439            unsafe {
440                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4);
441            }
442            Ok(())
443        }
444    }
445}