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